Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 119573 Details for
Bug 256731
[ds tooling] New Component wizard should create OSGI-INF folder and always place component definitions in that folder
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Prototype2
org.eclipse.pde.ds.ui.185.patch (text/plain), 59.70 KB, created by
Rafael Oliveira Nóbrega
on 2008-12-04 18:27:36 EST
(
hide
)
Description:
Prototype2
Filename:
MIME Type:
Creator:
Rafael Oliveira Nóbrega
Created:
2008-12-04 18:27:36 EST
Size:
59.70 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.ds.ui >Index: src/org/eclipse/pde/internal/ds/ui/wizards/DSNewWizard.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/wizards/DSNewWizard.java,v >retrieving revision 1.7 >diff -u -r1.7 DSNewWizard.java >--- src/org/eclipse/pde/internal/ds/ui/wizards/DSNewWizard.java 11 Nov 2008 21:14:42 -0000 1.7 >+++ src/org/eclipse/pde/internal/ds/ui/wizards/DSNewWizard.java 4 Dec 2008 23:26:14 -0000 >@@ -14,15 +14,34 @@ > > import java.lang.reflect.InvocationTargetException; > >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.jdt.core.ICompilationUnit; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaCore; >+import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.internal.core.JavaElement; >+import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; >+import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.operation.IRunnableWithProgress; > import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; > import org.eclipse.pde.internal.ds.ui.Activator; > import org.eclipse.pde.internal.ds.ui.Messages; >+import org.eclipse.pde.internal.ds.ui.parts.HandyPromptDialog; >+import org.eclipse.pde.internal.ui.PDEPlugin; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > > public class DSNewWizard extends Wizard implements INewWizard { >+ private static final String F_DefaultOSGIFolder_key = "default_folder"; //$NON-NLS-1$ >+ private static final String F_createOSGIFolder_key = "create_folder"; //$NON-NLS-1$ >+ private static final String F_OSGI_FOLDER_NAME = "OSGI-INF"; //$NON-NLS-1$ > protected DSFileWizardPage fMainPage; > > public DSNewWizard() { >@@ -32,28 +51,140 @@ > /* > * (non-Javadoc) > * >- * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages() >+ * @see >+ * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages() > */ > public void addPages() { >- addPage(fMainPage); >+ addPage(fMainPage); > } >- >+ > public void init(IWorkbench workbench, IStructuredSelection currentSelection) { > setWindowTitle(Messages.DSNewWizard_title); >+ setDialogSettings(PDEPlugin.getDefault().getDialogSettings()); >+ boolean value = false; >+ if (this.getDialogSettings().get(F_DefaultOSGIFolder_key) == null) { >+ value = showDefaultFolderPromptyDialog(); >+ if (value) { >+ currentSelection = getOSGIFolderSelection(currentSelection); >+ } >+ } else { >+ if (this.getDialogSettings().getBoolean(F_DefaultOSGIFolder_key)) { >+ currentSelection = getOSGIFolderSelection(currentSelection); >+ } >+ } >+ > fMainPage = new DSFileWizardPage(currentSelection); > } > >+ private boolean showDefaultFolderPromptyDialog() { >+ boolean value; >+ HandyPromptDialog d = new HandyPromptDialog(this.getShell(), >+ Messages.DSNewWizard_defaultOSGIFolder_message); >+ d.setTitle(Messages.DSNewWizard_defaultOSGIFolder_title); >+ int checkboxId = d.addCheckbox(Messages.DSNewWizard_RememberMyDecision, >+ false); >+ d.open(); >+ value = d.getReturnCode() == HandyPromptDialog.OK; >+ if (d.isCheckboxSelected(checkboxId)) { >+ this.getDialogSettings().put(F_DefaultOSGIFolder_key, value); >+ } >+ return value; >+ } >+ >+ private IStructuredSelection getOSGIFolderSelection( >+ IStructuredSelection currentSelection) { >+ if (currentSelection != null) { >+ Object element = currentSelection.getFirstElement(); >+ if (element != null) { >+ IProject project = getProject(element); >+ if (project != null) { >+ IResource findMember = project.findMember(F_OSGI_FOLDER_NAME); >+ if (findMember != null) { >+ if (findMember instanceof IFolder) { >+ currentSelection = new StructuredSelection( >+ findMember); >+ } >+ } else { >+ currentSelection = getNewFolderPath(currentSelection, >+ project); >+ } >+ } >+ } >+ >+ } >+ return currentSelection; >+ } >+ >+ private IStructuredSelection getNewFolderPath( >+ IStructuredSelection currentSelection, IProject project) { >+ if (this.getDialogSettings().get(F_createOSGIFolder_key) == null) { >+ HandyPromptDialog d = new HandyPromptDialog(this.getShell(), >+ Messages.DSNewWizard_createOSGIFolder_message); >+ d.setTitle(Messages.DSNewWizard_createOSGIFolder_title); >+ int checkboxId = d.addCheckbox( >+ Messages.DSNewWizard_RememberMyDecision, false); >+ d.open(); >+ boolean value = d.getReturnCode() == HandyPromptDialog.OK; >+ if (value) { >+ IFolder folder = project.getFolder(F_OSGI_FOLDER_NAME); >+ try { >+ folder.create(false, true, new NullProgressMonitor()); >+ currentSelection = new StructuredSelection(folder); >+ } catch (CoreException e) { >+ } >+ } >+ if (d.isCheckboxSelected(checkboxId)) { >+ this.getDialogSettings().put(F_createOSGIFolder_key, value); >+ } >+ } else { >+ if (this.getDialogSettings().getBoolean(F_createOSGIFolder_key)) { >+ IFolder folder = project.getFolder(F_OSGI_FOLDER_NAME); >+ try { >+ folder.create(false, true, new NullProgressMonitor()); >+ currentSelection = new StructuredSelection(folder); >+ } catch (CoreException e) { >+ } >+ } >+ } >+ return currentSelection; >+ } >+ >+ private IProject getProject(Object element) { >+ IProject project = null; >+ if (element instanceof IResource) { >+ project = ((IResource) element).getProject(); >+ } else if (element instanceof JavaElement) { >+ project = ((JavaElement) element).getJavaProject().getProject(); >+ } else if (element instanceof ClassPathContainer) { >+ project = ((ClassPathContainer) element).getJavaProject() >+ .getProject(); >+ } >+ return project; >+ } >+ > /* > * (non-Javadoc) > * >- * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish() >+ * @see >+ * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish >+ * () > */ > public boolean performFinish() { > try { > >+ String implementationClassValue = fMainPage >+ .getDSImplementationClassValue(); >+ if (fMainPage.isGenerateMethodsButtonSelected()) { >+ createMethods(implementationClassValue); >+ } >+ >+ IDialogSettings settings = getDialogSettings(); >+ if (settings != null) { >+ fMainPage.saveSettings(settings); >+ } > IRunnableWithProgress op = new DSCreationOperation(fMainPage > .createNewFile(), fMainPage.getDSComponentNameValue(), >- fMainPage.getDSImplementationClassValue()); >+ implementationClassValue); > > getContainer().run(false, true, op); > } catch (InvocationTargetException e) { >@@ -61,7 +192,37 @@ > return false; > } catch (InterruptedException e) { > return false; >+ >+ } catch (JavaModelException e) { >+ return false; > } > return true; > } >+ >+ private void createMethods(String implementationClassValue) >+ throws JavaModelException { >+ >+ IJavaProject proj = JavaCore.create(fMainPage.getProject()); >+ IType saved_type = proj.findType(implementationClassValue); >+ ICompilationUnit workingCU = saved_type.getCompilationUnit() >+ .getWorkingCopy(new NullProgressMonitor()); >+ >+ // create import >+ String importString = "org.osgi.service.component.ComponentContext";//$NON-NLS-1$ >+ workingCU.createImport(importString, null, new NullProgressMonitor()); >+ >+ // create methods >+ IType workingType = workingCU.getType(saved_type.getElementName()); >+ String activateMethodString = "protected void activate(ComponentContext context) {\n" //$NON-NLS-1$ >+ + " // TODO Auto-generated method stub \n}";//$NON-NLS-1$ >+ String deactivateMethodString = "protected void deactivate(ComponentContext context) {\n" //$NON-NLS-1$ >+ + " // TODO Auto-generated method stub \n}";//$NON-NLS-1$ >+ workingType.createMethod(activateMethodString, null, false, >+ new NullProgressMonitor()); >+ workingType.createMethod(deactivateMethodString, null, false, >+ new NullProgressMonitor()); >+ >+ workingCU.commitWorkingCopy(false, new NullProgressMonitor()); >+ } >+ > } >Index: src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java,v >retrieving revision 1.10 >diff -u -r1.10 DSFileWizardPage.java >--- src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java 11 Nov 2008 21:14:42 -0000 1.10 >+++ src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java 4 Dec 2008 23:26:13 -0000 >@@ -20,6 +20,7 @@ > import org.eclipse.core.runtime.Status; > import org.eclipse.jdt.core.IJavaElement; > import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.IMethod; > import org.eclipse.jdt.core.IType; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.search.SearchEngine; >@@ -27,6 +28,7 @@ > import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer; > import org.eclipse.jdt.ui.IJavaElementSearchConstants; > import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jface.dialogs.IDialogSettings; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.window.Window; > import org.eclipse.jface.wizard.WizardDialog; >@@ -35,6 +37,7 @@ > import org.eclipse.pde.internal.ds.ui.Activator; > import org.eclipse.pde.internal.ds.ui.Messages; > import org.eclipse.pde.internal.ds.ui.SWTUtil; >+import org.eclipse.pde.internal.ui.PDEPlugin; > import org.eclipse.pde.internal.ui.util.PDEModelUtility; > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.ModifyEvent; >@@ -64,7 +67,11 @@ > > private static final String F_FILE_EXTENSION = "xml"; //$NON-NLS-1$ > >- private static final String F_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$ >+ private static final String F_DEFAULT_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$ >+ >+ private static final String F_COMPONENT_NAME = "component"; //$NON-NLS-1$ >+ >+ private static final String F_GENERATE_METHODS = "generate_methods"; //$NON-NLS-1$ > > private Group fGroup; > >@@ -75,8 +82,12 @@ > private Hyperlink fDSImplementationClassHyperlink; > private Button fDSImplementationClassButton; > >+ private Button fGenerateMethodsButton; >+ > private IStructuredSelection fSelection; > >+ private IProject project; >+ > public DSFileWizardPage(IStructuredSelection selection) { > super(F_PAGE_NAME, selection); > this.fSelection = selection; >@@ -86,22 +97,25 @@ > /* > * (non-Javadoc) > * >- * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#initialize() >+ * @see >+ * org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage >+ * #initialize() > */ > protected void initialize() { > setTitle(Messages.DSFileWizardPage_title); > setDescription(Messages.DSFileWizardPage_description); > // Force the file extension to be 'xml' > setFileExtension(F_FILE_EXTENSION); >- setFileName(F_COMPONENT_NAME); > } > > private void setComponentName() { >- Object element = fSelection.getFirstElement(); >- if (element != null) { >- IProject project = getProject(element); >- if (project != null) >- setComponentNameText(project); >+ if (fSelection != null) { >+ Object element = fSelection.getFirstElement(); >+ if (element != null) { >+ IProject project = getProject(element); >+ if (project != null) >+ setComponentNameText(project); >+ } > } > } > >@@ -115,6 +129,11 @@ > project = ((ClassPathContainer) element).getJavaProject() > .getProject(); > } >+ this.project = project; >+ return project; >+ } >+ >+ public IProject getProject() { > return project; > } > >@@ -134,6 +153,17 @@ > } > > protected void createAdvancedControls(Composite parent) { >+ IDialogSettings settings = getDialogSettings(); >+ if (settings != null) { >+ String component = settings.get(F_COMPONENT_NAME); >+ if (component != null && !component.equals("")) { >+ setFileName(component); >+ } else { >+ setFileName(F_DEFAULT_COMPONENT_NAME); >+ } >+ } else { >+ setFileName(F_DEFAULT_COMPONENT_NAME); >+ } > > // Controls Group > fGroup = new Group(parent, SWT.NONE); >@@ -153,10 +183,9 @@ > fDSComponentNameText.setText(""); //$NON-NLS-1$ > fDSComponentNameText.addModifyListener(new ModifyListener() { > public void modifyText(ModifyEvent e) { >- setPageComplete(checkPageComplete()); >+ setPageComplete(isPageComplete()); > } > }); >- setComponentName(); > > fDSImplementationClassHyperlink = new Hyperlink(fGroup, SWT.NONE); > fDSImplementationClassHyperlink >@@ -236,7 +265,7 @@ > fDSImplementationClassText.setText(""); //$NON-NLS-1$ > fDSImplementationClassText.addModifyListener(new ModifyListener() { > public void modifyText(ModifyEvent e) { >- setPageComplete(checkPageComplete()); >+ setPageComplete(isPageComplete()); > } > }); > >@@ -277,6 +306,13 @@ > } > }); > >+ fGenerateMethodsButton = new Button(fGroup, SWT.CHECK); >+ fGenerateMethodsButton.setText(Messages.DSFileWizardPage_createMethods); >+ fGenerateMethodsButton.setEnabled(false); >+ fGenerateMethodsButton.setSelection(false); >+ >+ setComponentName(); >+ validatePage(); > } > > public String getDSComponentNameValue() { >@@ -298,7 +334,8 @@ > /* > * (non-Javadoc) > * >- * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validateLinkedResource() >+ * @see >+ * org.eclipse.ui.dialogs.WizardNewFileCreationPage#validateLinkedResource() > */ > protected IStatus validateLinkedResource() { > return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$ >@@ -309,7 +346,73 @@ > } > > public boolean isPageComplete() { >- return checkPageComplete(); >+ updateCreateMethodsButton(); >+ return checkPageComplete() & validatePage(); > } > >+ public void saveSettings(IDialogSettings settings) { >+ settings.put(F_COMPONENT_NAME, getFileName()); >+ if (fGenerateMethodsButton.isEnabled()) { >+ settings.put(F_GENERATE_METHODS, fGenerateMethodsButton >+ .getSelection()); >+ } >+ >+ } >+ >+ protected boolean validatePage() { >+ if (fDSImplementationClassText != null) { >+ IStatus status = PDEPlugin.getWorkspace().validateName( >+ fDSImplementationClassText.getText(), IResource.FILE); >+ if (!status.isOK()) { >+ setErrorMessage(status.getMessage()); >+ return false; >+ } >+ } >+ return super.validatePage(); >+ } >+ >+ private void updateCreateMethodsButton() { >+ boolean wasDisabled = !fGenerateMethodsButton.isEnabled(); >+ try { >+ IType type = JavaCore.create(this.getProject()).findType( >+ this.getDSImplementationClassValue()); >+ if (type != null) { >+ IMethod methodActivate = type.getMethod("activate", //$NON-NLS-1$ >+ new String[] { "QComponentContext;" }); //$NON-NLS-1$ >+ IMethod methodDeactivate = type.getMethod("deactivate", //$NON-NLS-1$ >+ new String[] { "QComponentContext;" }); //$NON-NLS-1$ >+ if (type.findMethods(methodActivate) == null >+ && type.findMethods(methodDeactivate) == null) { >+ if (wasDisabled) { >+ enableAndToggleGenerateButton(); >+ } >+ return; >+ } >+ } >+ } catch (Exception e) { >+ } >+ fGenerateMethodsButton.setEnabled(false); >+ fGenerateMethodsButton.setSelection(false); >+ >+ } >+ >+ private void enableAndToggleGenerateButton() { >+ fGenerateMethodsButton.setEnabled(true); >+ IDialogSettings settings = getDialogSettings(); >+ if (settings != null) { >+ if (settings.get(F_GENERATE_METHODS) != null) { >+ fGenerateMethodsButton.setSelection(settings >+ .getBoolean(F_GENERATE_METHODS)); >+ >+ } else { >+ fGenerateMethodsButton.setSelection(true); >+ } >+ } else { >+ fGenerateMethodsButton.setSelection(true); >+ } >+ } >+ >+ public boolean isGenerateMethodsButtonSelected() { >+ return fGenerateMethodsButton.getSelection(); >+ } > } >Index: src/org/eclipse/pde/internal/ds/ui/Messages.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/Messages.java,v >retrieving revision 1.25 >diff -u -r1.25 Messages.java >--- src/org/eclipse/pde/internal/ds/ui/Messages.java 11 Nov 2008 21:14:42 -0000 1.25 >+++ src/org/eclipse/pde/internal/ds/ui/Messages.java 4 Dec 2008 23:26:12 -0000 >@@ -40,8 +40,14 @@ > public static String DSFileWizardPage_browse; > public static String DSFileWizardPage_selectType; > public static String DSFileWizardPage_not_OSGI_folder; >+ public static String DSFileWizardPage_createMethods; > > public static String DSNewWizard_title; >+ public static String DSNewWizard_createOSGIFolder_title; >+ public static String DSNewWizard_createOSGIFolder_message; >+ public static String DSNewWizard_defaultOSGIFolder_title; >+ public static String DSNewWizard_defaultOSGIFolder_message; >+ public static String DSNewWizard_RememberMyDecision; > > public static String DSImplementationDetails_title; > public static String DSImplementationDetails_description; >@@ -165,6 +171,7 @@ > > public static String DSService_title; > >+ > > > >Index: src/org/eclipse/pde/internal/ds/ui/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/pde/ds/org.eclipse.pde.ds.ui/src/org/eclipse/pde/internal/ds/ui/messages.properties,v >retrieving revision 1.38 >diff -u -r1.38 messages.properties >--- src/org/eclipse/pde/internal/ds/ui/messages.properties 11 Nov 2008 21:14:42 -0000 1.38 >+++ src/org/eclipse/pde/internal/ds/ui/messages.properties 4 Dec 2008 23:26:12 -0000 >@@ -34,8 +34,14 @@ > DSFileWizardPage_browse=Browse... > DSFileWizardPage_selectType= Select Type > DSFileWizardPage_not_OSGI_folder=By convention, component files should be located in OSGI-INF/ folder >+DSFileWizardPage_createMethods=Generate &lifecycle methods > > DSNewWizard_title=New Component Definition >+DSNewWizard_createOSGIFolder_title=Create OSGI-INF Folder >+DSNewWizard_createOSGIFolder_message=Do you want to create the OSGI-INF folder? (recomended) >+DSNewWizard_defaultOSGIFolder_title=OSGI-INF Folder >+DSNewWizard_defaultOSGIFolder_message=Make OSGI-INF as default folder? (recomended) >+DSNewWizard_RememberMyDecision=Remember my decision > > DSImplementationDetails_title=Definition > DSImplementationDetails_description=Specify the service's implementation class: >Index: src/org/eclipse/pde/internal/ds/ui/parts/Messages.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/Messages.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/Messages.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/Messages.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import java.util.MissingResourceException; >+import java.util.ResourceBundle; >+ >+/** >+ * Messages.java >+ */ >+public class Messages extends Object { >+ // >+ // Static Fields >+ // >+ >+ private static final String BUNDLE_NAME = "org.eclipse.pde.internal.ds.ui.parts.messages"; //$NON-NLS-1$ >+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(Messages.BUNDLE_NAME); >+ >+ // >+ // Static Methods >+ // >+ >+ public static String getString(String key) { >+ if (key == null) throw new IllegalArgumentException(); >+ String value; >+ >+ try { >+ value = Messages.RESOURCE_BUNDLE.getString(key); >+ value = value.trim(); >+ } catch (MissingResourceException exception) { >+ value = '!' + key + '!'; >+ } >+ >+ return value; >+ } >+ >+ // >+ // Constructors >+ // >+ >+ private Messages() { >+ super(); >+ } >+} >Index: src/org/eclipse/pde/internal/ds/ui/parts/IHandyDialog.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/IHandyDialog.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/IHandyDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/IHandyDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,55 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import org.eclipse.jface.dialogs.IDialogConstants; >+ >+public interface IHandyDialog { >+ // Values returned by open() >+ public static final int CANCEL_ID = IDialogConstants.CANCEL_ID; >+ public static final int HELP_ID = IDialogConstants.HELP_ID; >+ public static final int NO_ID = IDialogConstants.NO_ID; >+ public static final int OK_ID = IDialogConstants.OK_ID; >+ public static final int YES_ID = IDialogConstants.YES_ID; >+ >+ /** >+ * @see org.eclipse.jface.window.Window.open() >+ */ >+ public int open(); >+ >+ /** >+ * Set the context ID to be used when the user clicks the Help button. >+ * This ID should be defined somewhere in a <code>contexts.xml</code> file, >+ * which has been registered using the <code>org.eclipse.help.contexts</code> >+ * extension-point. Setting a context ID has the side effect of causing a >+ * Help button to be displayed. >+ * >+ * @param helpContextId The help context ID. >+ */ >+ public void setHelpContextId(String helpContextId); >+ >+ /** >+ * Set the size of the dialog. This is only a hint, since dialogs must >+ * respect the dialog font size. The most you can expect is that the >+ * dialog will be no smaller than the width and height specified. >+ * >+ * @param width The width of the dialog. >+ * @param height The height of the dialog. >+ */ >+ public void setSize(int width, int height); >+ >+ /** >+ * Set the title of the dialog. >+ * >+ * @param title The title of the dialog. >+ */ >+ public void setTitle(String title); >+} >Index: src/org/eclipse/pde/internal/ds/ui/parts/IHandyPromptDialog.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/IHandyPromptDialog.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/IHandyPromptDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/IHandyPromptDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,38 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import org.eclipse.swt.graphics.Image; >+ >+public interface IHandyPromptDialog extends IHandyDialog { >+ public int addCheckbox(String text, boolean selected); >+ public int addRadioButton(String text, boolean selected); >+ public void defaultButtonIsCancel(); >+ public void defaultButtonIsNo(); >+ public void defaultButtonIsYes(); >+ public int getSelectedRadioButtonId(); >+ public boolean isCheckboxSelected(int id); >+ public void removeAllCheckboxes(); >+ public void removeAllRadioButtons(); >+ public void setCancelButtonText(String cancelButtonText); >+ public void setCheckboxGroupText(String checkboxGroupText); >+ public void setCheckboxSelected(int id, boolean selected); >+ public void setHelpContextId(String helpContextId); >+ public void setImage(Image image); >+ public void setNoButtonText(String negativeButtonLabel); >+ public void setRadioButtonGroupText(String radioButtonGroupText); >+ public void setRadioButtonSelected(int id, boolean selected); >+ public void setYesButtonText(String positiveButtonLabel); >+ public void useErrorIcon(); >+ public void useInformationIcon(); >+ public void useQuestionIcon(); >+ public void useWarningIcon(); >+} >\ No newline at end of file >Index: src/org/eclipse/pde/internal/ds/ui/parts/UiUtility.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/UiUtility.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/UiUtility.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/UiUtility.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,291 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import java.net.URL; >+import java.text.MessageFormat; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.SWTError; >+import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.TextTransfer; >+import org.eclipse.swt.dnd.Transfer; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Device; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.MessageBox; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IViewPart; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.browser.IWebBrowser; >+import org.eclipse.ui.browser.IWorkbenchBrowserSupport; >+import org.eclipse.ui.help.IWorkbenchHelpSystem; >+import org.eclipse.ui.part.FileEditorInput; >+ >+/** >+ * UiUtility.java >+ */ >+public class UiUtility extends Object { >+ // >+ // Static Fields >+ // >+ >+ // Externalized Strings >+ private static final String FAILED_TO_OPEN_URL_KEY = "UiUtility.FailedToOpenUrl"; //$NON-NLS-1$ >+ private static final String ERROR_KEY = "UiUtility.Error"; //$NON-NLS-1$ >+ private static final String WEB_BROWSER_CAN_NOT_BE_FOUND = "UiUtility.WebBrowserCanNotBeFound"; //$NON-NLS-1$ >+ >+ // Singleton >+ private static final UiUtility INSTANCE = new UiUtility(); >+ >+ // >+ // Static Methods >+ // >+ >+ public static UiUtility getInstance() { >+ return UiUtility.INSTANCE; >+ } >+ >+ // >+ // Constructors >+ // >+ >+ private UiUtility() { >+ super(); >+ } >+ >+ // >+ // Instance Methods >+ // >+ >+ public void copyToClipboard(String text) { >+ Display display = Display.getCurrent(); >+ Clipboard clipboard = new Clipboard(display); >+ TextTransfer textTransfer = TextTransfer.getInstance(); >+ >+ Object[] data = new Object[] { >+ text >+ }; >+ >+ Transfer[] transfers = new Transfer[] { >+ textTransfer >+ }; >+ >+ try { >+ clipboard.setContents(data, transfers); >+ } catch (SWTError error) { >+ // Only when another application is accessing the system clipboard. >+ // OK to ignore. >+ } finally { >+ clipboard.dispose(); >+ } >+ } >+ >+ public void copyToClipboard(String[] items) { >+ int size = items.length; >+ StringBuffer buffer = new StringBuffer(size * 20); >+ String lineSeparator = System.getProperty("line.separator"); //$NON-NLS-1$ >+ >+ for (int i = 0; i < size; i++) { >+ String item = items [ i ]; >+ buffer.append(item); >+ buffer.append(lineSeparator); >+ } >+ >+ String text = buffer.toString(); >+ copyToClipboard(text); >+ } >+ >+ public IViewPart findView(String id) { >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); >+ IWorkbenchPage workbenchPage = workbenchWindow.getActivePage(); >+ IViewPart view = workbenchPage.findView(id); >+ return view; >+ } >+ >+ private IWorkbenchPage getActiveWorkbenchPage() { >+ IWorkbenchWindow[] windows = getWorkbenchWindows(); >+ IWorkbenchPage page = null; >+ int i = 0; >+ >+ while (page == null && i < windows.length) { >+ IWorkbenchWindow window = windows [ i ]; >+ page = window.getActivePage(); >+ i++; >+ } >+ >+ return page; >+ } >+ >+ public IWorkbenchWindow getActiveWorkbenchWindow() { >+ IWorkbench workbench = getWorkbench(); >+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); >+ return window; >+ } >+ >+ public Color getBackgroundColor() { >+ Color color = getSystemColor(SWT.COLOR_LIST_BACKGROUND); >+ return color; >+ } >+ >+ private Control getControlWithFocus(Composite parent) { >+ Control result = null; >+ Control[] children = parent.getChildren(); >+ int length = children.length; >+ int index = 0; >+ >+ while (result == null && index < length) { >+ result = children [ index ]; >+ result = getControlWithFocus(result); >+ index++; >+ } >+ >+ return result; >+ } >+ >+ public Control getControlWithFocus(Control parent) { >+ boolean focus = parent.isFocusControl(); >+ Control result = focus == true ? parent : null; >+ >+ if (result == null && parent instanceof Composite) { // $codepro.audit.disable disallowInstanceof >+ Composite composite = (Composite) parent; >+ result = getControlWithFocus(composite); >+ } >+ >+ return result; >+ } >+ >+ public IWorkbenchHelpSystem getHelpSystem() { >+ boolean valid = PlatformUI.isWorkbenchRunning(); >+ if (valid == false) >+ return null; // Early return. >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ IWorkbenchHelpSystem helpSystem = workbench.getHelpSystem(); >+ return helpSystem; >+ } >+ >+ public Shell getShell() { >+ Display display = Display.getCurrent(); >+ Shell shell = display.getActiveShell(); >+ return shell; >+ } >+ >+ public Color getSystemColor(int id) { >+ Device device = Display.getDefault(); >+ Color color = device.getSystemColor(id); >+ return color; >+ } >+ >+ public String getTextFromClipboard() { >+ Display display = Display.getCurrent(); >+ Clipboard clipboard = new Clipboard(display); >+ TextTransfer textTransfer = TextTransfer.getInstance(); >+ String value = (String) clipboard.getContents(textTransfer); >+ clipboard.dispose(); >+ return value; >+ } >+ >+ public IWorkbench getWorkbench() { >+ return PlatformUI.getWorkbench(); >+ } >+ >+ public IWorkbenchPage getWorkbenchPage() { >+ IWorkbenchWindow window = getActiveWorkbenchWindow(); >+ IWorkbenchPage page = window.getActivePage(); >+ return page; >+ } >+ >+ public IWorkbenchWindow[] getWorkbenchWindows() { >+ IWorkbench workbench = getWorkbench(); >+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); >+ return windows; >+ } >+ >+ public boolean isOnUserInterfaceThread() { >+ Object display = Display.getCurrent(); >+ boolean result = display != null; >+ return result; >+ } >+ >+ public void openBrowser(String address) { >+ IWorkbench workbench = getWorkbench(); >+ IWorkbenchBrowserSupport support = workbench.getBrowserSupport(); >+ >+ try { >+ IWebBrowser browser = support.getExternalBrowser(); >+ URL url = new URL(address); >+ browser.openURL(url); >+ } catch (Exception exception) { >+ String message = openUnableToOpenBrowserErrorMessageDialog(address); >+ throw new RuntimeException(message, exception); >+ } >+ } >+ >+ public void openEditor(IFile file, String editorId) throws PartInitException { >+ IWorkbenchPage page = getActiveWorkbenchPage(); >+ IEditorInput editorInput = new FileEditorInput(file); >+ page.openEditor(editorInput, editorId); >+ } >+ >+ public void openErrorDialog(String id, String message, String reason, Throwable throwable) { >+ Shell shell = getShell(); >+ String title = Messages.getString(UiUtility.ERROR_KEY); >+ IStatus status = new Status(IStatus.ERROR, id, IStatus.ERROR, reason, throwable); >+ ErrorDialog.openError(shell, title, message, status, IStatus.ERROR); >+ } >+ >+ public void openMessageDialog(String title, String message, int style) { >+ Shell shell = getShell(); >+ MessageBox messageBox = new MessageBox(shell, style); >+ messageBox.setText(title); >+ messageBox.setMessage(message); >+ messageBox.open(); >+ } >+ >+ private String openUnableToOpenBrowserErrorMessageDialog(String url) { >+ String title = Messages.getString(UiUtility.ERROR_KEY); >+ String error = Messages.getString(UiUtility.WEB_BROWSER_CAN_NOT_BE_FOUND); >+ String separator = System.getProperty("line.separator"); //$NON-NLS-1$ >+ String pattern = Messages.getString(UiUtility.FAILED_TO_OPEN_URL_KEY); >+ >+ Object[] values = new Object[] { >+ url >+ }; >+ >+ String consequence = MessageFormat.format(pattern, values); >+ int length = error.length() + separator.length() + consequence.length(); >+ StringBuffer buffer = new StringBuffer(length); >+ buffer.append(error); >+ buffer.append(separator); >+ buffer.append(consequence); >+ String message = buffer.toString(); >+ int style = SWT.OK | SWT.APPLICATION_MODAL | SWT.ICON_ERROR; >+ openMessageDialog(title, message, style); >+ return message; >+ } >+ >+ public void setHelp(Control control, String contextId) { >+ IWorkbenchHelpSystem helpSystem = getHelpSystem(); >+ helpSystem.setHelp(control, contextId); >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/pde/internal/ds/ui/parts/HandyDialog.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/HandyDialog.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/HandyDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/HandyDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import org.eclipse.jface.dialogs.Dialog; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.help.IWorkbenchHelpSystem; >+ >+abstract class HandyDialog extends Dialog implements IHandyDialog { >+ // >+ // Static Fields >+ // >+ >+ // Externalized Strings >+ protected static final String HELP_KEY = "Common.Help"; //$NON-NLS-1$ >+ >+ // >+ // Instance Fields >+ // >+ >+ private String title; >+ private String helpContextId; >+ private Point size; >+ >+ // >+ // Constructors >+ // >+ >+ protected HandyDialog(Shell parentShell) { >+ super(parentShell); >+ } >+ >+ // >+ // Instance Methods >+ // >+ >+ /** >+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) >+ */ >+ protected void configureShell(Shell shell) { >+ super.configureShell(shell); >+ configureShellTitle(shell); >+ } >+ >+ private void configureShellTitle(Shell shell) { >+ String title = getTitle(); >+ if (title == null) >+ return; // Early return. >+ shell.setText(title); >+ } >+ >+ protected abstract void createArea(Composite composite); >+ >+ /** >+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) >+ */ >+ protected final Control createDialogArea(Composite parent) { >+ Composite composite = (Composite) super.createDialogArea(parent); >+ hookHelpToComposite(composite); >+ createArea(composite); >+ postCreateArea(composite); >+ Dialog.applyDialogFont(composite); >+ return composite; >+ } >+ >+ protected final Button createHelpButtonForButtonBar(Composite parent) { >+ boolean required = isHelpButtonRequired(); >+ if (required == false) return null; >+ String label = Messages.getString(HandyDialog.HELP_KEY); >+ Button button = createButton(parent, IHandyDialog.HELP_ID, label, false); >+ return button; >+ } >+ >+ private Display getDisplay() { >+ Shell shell = getShell(); >+ Display display = shell != null ? shell.getDisplay() : Display.getDefault(); >+ return display; >+ } >+ >+ private String getHelpContextId() { >+ return helpContextId; >+ } >+ >+ private IWorkbenchHelpSystem getHelpSystem() { >+ UiUtility utility = UiUtility.getInstance(); >+ IWorkbenchHelpSystem helpSystem = utility.getHelpSystem(); >+ return helpSystem; >+ } >+ >+ /** >+ * @see org.eclipse.jface.window.Window#getInitialSize() >+ */ >+ protected Point getInitialSize() { >+ Point initialSize = super.getInitialSize(); >+ Point result = initialSize; >+ Point size = getSize(); >+ >+ if (size != null) { >+ if (size.x >= initialSize.x) { >+ result.x = size.x; >+ } >+ >+ if (size.y >= initialSize.y) { >+ result.y = size.y; >+ } >+ } >+ >+ return result; >+ } >+ >+ private Point getSize() { >+ return size; >+ } >+ >+ protected final Image getSystemImage(int id) { >+ Display display = getDisplay(); >+ Image image = display.getSystemImage(id); >+ return image; >+ } >+ >+ private String getTitle() { >+ return title; >+ } >+ >+ protected final void helpPressed() { >+ String id = getHelpContextId(); >+ IWorkbenchHelpSystem helpSystem = getHelpSystem(); >+ if (helpSystem == null) >+ return; // Early return. >+ helpSystem.displayHelp(id); >+ } >+ >+ private void hookHelpToComposite(Composite parent) { >+ String id = getHelpContextId(); >+ if (id == null) >+ return; // Early return. >+ IWorkbenchHelpSystem helpSystem = getHelpSystem(); >+ if (helpSystem == null) >+ return; // Early return. >+ helpSystem.setHelp(parent, id); >+ } >+ >+ protected final boolean isHelpButtonRequired() { >+ IWorkbenchHelpSystem helpSystem = getHelpSystem(); >+ boolean valid = helpSystem != null; >+ if (valid == false) >+ return false; // Early return. >+ String id = getHelpContextId(); >+ if (id == null) >+ return false; // Early return. >+ return true; >+ } >+ >+ protected void postCreateArea(Composite composite) { >+ // No-op >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setHelpContextId(java.lang.String) >+ */ >+ public void setHelpContextId(String helpContextId) { >+ this.helpContextId = helpContextId; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyDialog#setSize(int, int) >+ */ >+ public void setSize(int width, int height) { >+ Point point = new Point(width, height); >+ setSize(point); >+ } >+ >+ private void setSize(Point size) { >+ this.size = size; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setTitle(java.lang.String) >+ */ >+ public void setTitle(String title) { >+ this.title = title; >+ } >+} >Index: src/org/eclipse/pde/internal/ds/ui/parts/messages.properties >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/messages.properties >diff -N src/org/eclipse/pde/internal/ds/ui/parts/messages.properties >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/messages.properties 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,20 @@ >+# Common >+Common.Help=&Help >+ >+# HandyPromptDialog.java >+HandyPromptDialog.Prompt=Prompt >+HandyPromptDialog.UnknownButtonId=Unknown button id {0} >+ >+# UiUtility.java >+UiUtility.Error=Error >+UiUtility.FailedToOpenUrl=Failed to open {0} >+UiUtility.WebBrowserCanNotBeFound=A web browser could not be found! >+ >+# Copyright (c) 2001, 2007 IBM Corporation and others. >+# All rights reserved. This program and the accompanying materials >+# are made available under the terms of the Eclipse Public License v1.0 >+# which accompanies this distribution, and is available at >+# http://www.eclipse.org/legal/epl-v10.html >+# >+# Contributors: >+# IBM Corporation - initial API and implementation >Index: src/org/eclipse/pde/internal/ds/ui/parts/HandyPromptDialog.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/ds/ui/parts/HandyPromptDialog.java >diff -N src/org/eclipse/pde/internal/ds/ui/parts/HandyPromptDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/ds/ui/parts/HandyPromptDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,627 @@ >+/******************************************************************************* >+ * Copyright (c) 2001, 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.pde.internal.ds.ui.parts; >+ >+import java.text.MessageFormat; >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * A handy Yes/No/Cancel dialog. >+ */ >+public class HandyPromptDialog extends HandyDialog implements IHandyPromptDialog { >+ // >+ // Nested Classes >+ // >+ >+ private static class ButtonDetails extends Object { >+ private Button button; >+ private boolean selected; >+ private String text; >+ } >+ >+ // Static Fields >+ // >+ >+ // Externalized Strings >+ private static final String PROMPT_KEY = "HandyPromptDialog.Prompt"; //$NON-NLS-1$ >+ private static final String UNKNOWN_BUTTON_ID_KEY = "HandyPromptDialog.UnknownButtonId"; //$NON-NLS-1$ >+ >+ // Misc >+ private static final int NO_DEFAULT_BUTTON_ID = -1; >+ >+ // >+ // Instance Fields >+ // >+ >+ private String cancelButtonText; >+ private List/*<ButtonDetails>*/ checkboxButtons; >+ private String checkboxGroupText; >+ private int defaultButtonId; >+ private Image image; >+ private String noButtonText; >+ private String prompt; >+ private List/*<ButtonDetails>*/ radioButtons; >+ private String radioButtonGroupText; >+ private String yesButtonText; >+ >+ // >+ // Constructors >+ // >+ >+ public HandyPromptDialog(Shell parentShell, String prompt) { >+ super(parentShell); >+ setTitle(Messages.getString(HandyPromptDialog.PROMPT_KEY)); >+ setPrompt(prompt); >+ initializeCheckboxButtons(); >+ initializeRadioButtons(); >+ initializePushButtons(); >+ setDefaultButtonId(HandyPromptDialog.NO_DEFAULT_BUTTON_ID); >+ } >+ >+ // >+ // Instance Methods >+ // >+ >+ private int addButton(List/*<ButtonDetails>*/ list, String text, boolean selected) { >+ synchronized (list) { >+ int size = list.size(); >+ ButtonDetails details = new ButtonDetails(); >+ details.text = text; >+ details.selected = selected; >+ list.add(details); >+ return size; >+ } >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#addCheckbox(java.lang.String, boolean) >+ */ >+ public int addCheckbox(String text, boolean selected) { >+ List/*<ButtonDetails>*/ list = getCheckboxButtons(); >+ int id = addButton(list, text, selected); >+ return id; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#addRadioButton(java.lang.String, boolean) >+ */ >+ public int addRadioButton(String text, boolean selected) { >+ List/*<ButtonDetails>*/ list = getRadioButtons(); >+ int id = addButton(list, text, selected); >+ return id; >+ } >+ >+ /** >+ * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) >+ */ >+ protected void buttonPressed(int buttonId) { >+ if (IHandyDialog.HELP_ID == buttonId) { >+ helpPressed(); >+ } else { >+ try { >+ updateButtonSelections(); >+ setReturnCode(buttonId); >+ } finally { >+ close(); >+ } >+ } >+ } >+ >+ private void checkButtonId(List/*<ButtonDetails>*/ list, int id) { >+ int size = list.size(); >+ if (id < size) >+ return; // Early return. >+ >+ String pattern = Messages.getString(HandyPromptDialog.UNKNOWN_BUTTON_ID_KEY); >+ Object[] values = new Object[] { >+ new Integer(id) >+ }; >+ String message = MessageFormat.format(pattern, values); >+ throw new IllegalArgumentException(message); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.internal.HandyDialog#createArea(org.eclipse.swt.widgets.Composite) >+ */ >+ protected void createArea(Composite composite) { >+ createPromptControls(composite); >+ } >+ >+ private Button createButton(Composite parent, int id, String label) { >+ int defaultButtonId = getDefaultButtonId(); >+ boolean defaultButton = defaultButtonId == id; >+ Button button = createButton(parent, id, label, defaultButton); >+ return button; >+ } >+ >+ /** >+ * @see org.eclipse.jface.dialogs.Dialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean) >+ */ >+ protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { >+ Button button = super.createButton(parent, id, label, defaultButton); >+ >+ // Force the default button to take focus. This fixes an apparent >+ // bug in SWT where the default button does not always take focus. >+ // Strangely enough, the default button seems to take focus when the >+ // HandyPromptDialog has at least one radio button or checkbox. >+ >+ if (defaultButton == true) { >+ button.setFocus(); >+ } >+ >+ return button; >+ } >+ >+ private void createButtons(List/* <ButtonDetails> */list, >+ Composite parent, boolean grabExcessSpace, String groupText, >+ int style) { >+ synchronized (list) { >+ boolean empty = list.isEmpty(); >+ if (empty == true) >+ return; // Early return. >+ >+ Composite composite; >+ RowLayout layout = new RowLayout(SWT.VERTICAL); >+ >+ if (groupText == null) { >+ composite = new Composite(parent, SWT.NONE); >+ layout.marginLeft = 0; >+ layout.marginRight = 0; >+ layout.marginTop = 0; >+ layout.marginBottom = 0; >+ } else { >+ Group group = new Group(parent, SWT.NONE); >+ group.setText(groupText); >+ composite = group; >+ } >+ >+ composite.setLayout(layout); >+ >+ int alignment = grabExcessSpace == true ? SWT.FILL : SWT.BEGINNING; >+ Object data = new GridData(alignment, alignment, grabExcessSpace, grabExcessSpace); >+ composite.setLayoutData(data); >+ >+ Iterator/*<ButtonDetails>*/ iterator = list.iterator(); >+ while (iterator.hasNext() == true) { >+ ButtonDetails details = (ButtonDetails) iterator.next(); >+ Button button = new Button(composite, style); >+ button.setText(details.text); >+ button.setSelection(details.selected); >+ details.button = button; >+ } >+ } >+ } >+ >+ /** >+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ createYesButtonForButtonBar(parent); >+ createNoButtonForButtonBar(parent); >+ createCancelButtonForButtonBar(parent); >+ createHelpButtonForButtonBar(parent); >+ } >+ >+ private Button createCancelButtonForButtonBar(Composite parent) { >+ String label = getCancelButtonText(); >+ if (label == null) >+ return null; // Early return. >+ int id = IHandyDialog.CANCEL_ID; >+ Button button = createButton(parent, id, label); >+ return button; >+ } >+ >+ private Button createNoButtonForButtonBar(Composite parent) { >+ String label = getNoButtonText(); >+ if (label == null) >+ return null; // Early return. >+ int id = IHandyDialog.NO_ID; >+ Button button = createButton(parent, id, label); >+ return button; >+ } >+ >+ private void createPromptButtonControls(Composite parent) { >+ int columns = 0; >+ >+ List/*<ButtonDetails>*/ checkboxButtons = getCheckboxButtons(); >+ boolean hasCheckboxButtons = checkboxButtons.isEmpty() == false; >+ >+ if (hasCheckboxButtons == true) { >+ columns++; >+ } >+ >+ List/*<ButtonDetails>*/ radioButtons = getRadioButtons(); >+ boolean hasRadioButtons = radioButtons.isEmpty() == false; >+ >+ if (hasRadioButtons == true) { >+ columns++; >+ } >+ >+ if (columns == 0) >+ return; // Early return. >+ >+ Composite composite = createPromptButtonControlsComposite(parent, columns); >+ >+ if (hasCheckboxButtons == true) { >+ String groupText = getCheckboxGroupText(); >+ createButtons(checkboxButtons, composite, hasRadioButtons, groupText, SWT.CHECK); >+ } >+ >+ if (hasRadioButtons == true) { >+ String groupText = getRadioButtonGroupText(); >+ createButtons(radioButtons, composite, hasCheckboxButtons, groupText, SWT.RADIO); >+ } >+ } >+ >+ private Composite createPromptButtonControlsComposite(Composite parent, int columns) { >+ GridLayout layout = new GridLayout(columns, false); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ layout.marginTop = 20; >+ layout.marginHeight = 0; >+ >+ if (columns > 1) { >+ layout.horizontalSpacing = 10; >+ } >+ >+ Composite composite = new Composite(parent, SWT.NONE); >+ composite.setLayout(layout); >+ >+ Object data = new GridData(SWT.FILL, SWT.FILL, true, false); >+ composite.setLayoutData(data); >+ >+ return composite; >+ } >+ >+ private void createPromptControls(Composite parent) { >+ createPromptLabelControls(parent); >+ createPromptButtonControls(parent); >+ } >+ >+ private void createPromptLabelControls(Composite parent) { >+ GridData data; >+ >+ Composite composite = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(2, false); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ composite.setLayout(layout); >+ data = new GridData(SWT.FILL, SWT.FILL, true, true); >+ composite.setLayoutData(data); >+ >+ Label icon = new Label(composite, SWT.LEFT | SWT.NONE); >+ Image image = getImage(); >+ icon.setImage(image); >+ >+ Label label = new Label(composite, SWT.WRAP); >+ String prompt = getPrompt(); >+ label.setText(prompt); >+ data = new GridData(SWT.FILL, SWT.CENTER, true, true); >+ data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); >+ label.setLayoutData(data); >+ } >+ >+ private Button createYesButtonForButtonBar(Composite parent) { >+ String label = getYesButtonText(); >+ if (label == null) >+ return null; // Early return. >+ int id = IHandyDialog.YES_ID; >+ Button button = createButton(parent, id, label); >+ return button; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsCancel() >+ */ >+ public void defaultButtonIsCancel() { >+ setDefaultButtonId(IHandyDialog.CANCEL_ID); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsNo() >+ */ >+ public void defaultButtonIsNo() { >+ setDefaultButtonId(IHandyDialog.NO_ID); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsYes() >+ */ >+ public void defaultButtonIsYes() { >+ setDefaultButtonId(IHandyDialog.YES_ID); >+ } >+ >+ private ButtonDetails getButtonDetails(List/*<ButtonDetails>*/ list, int id) { >+ checkButtonId(list, id); >+ ButtonDetails details = (ButtonDetails) list.get(id); >+ return details; >+ } >+ >+ private String getCancelButtonText() { >+ return cancelButtonText; >+ } >+ >+ private ButtonDetails getCheckboxButtonDetails(int id) { >+ List/*<ButtonDetails>*/ list = getCheckboxButtons(); >+ ButtonDetails details = getButtonDetails(list, id); >+ return details; >+ } >+ >+ private List/*<ButtonDetails>*/ getCheckboxButtons() { >+ return checkboxButtons; >+ } >+ >+ private String getCheckboxGroupText() { >+ return checkboxGroupText; >+ } >+ >+ private int getDefaultButtonId() { >+ synchronized (this) { >+ if (defaultButtonId == -1) { >+ int id = guessDefaultButtonId(); >+ setDefaultButtonId(id); >+ } >+ } >+ >+ return defaultButtonId; >+ } >+ >+ private Image getImage() { >+ synchronized (this) { >+ if (image == null) { >+ useInformationIcon(); >+ } >+ } >+ return image; >+ } >+ >+ private String getNoButtonText() { >+ return noButtonText; >+ } >+ >+ private String getPrompt() { >+ return prompt; >+ } >+ >+ private ButtonDetails getRadioButtonDetails(int id) { >+ List/*<ButtonDetails>*/ list = getRadioButtons(); >+ ButtonDetails details = getButtonDetails(list, id); >+ return details; >+ } >+ >+ private String getRadioButtonGroupText() { >+ return radioButtonGroupText; >+ } >+ >+ private List/*<ButtonDetails>*/ getRadioButtons() { >+ return radioButtons; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#getSelectedRadioButtonId() >+ */ >+ public int getSelectedRadioButtonId() { >+ List/*<ButtonDetails>*/ list = getRadioButtons(); >+ int size = list.size(); >+ >+ for (int id = 0; id < size; id++) { >+ ButtonDetails details = (ButtonDetails) list.get(id); >+ if (details.selected == true) >+ return id; // Early return. >+ } >+ >+ return -1; >+ } >+ >+ private String getYesButtonText() { >+ return yesButtonText; >+ } >+ >+ private int guessDefaultButtonId() { >+ Object text; >+ >+ text = getCancelButtonText(); >+ if (text != null) return IHandyDialog.CANCEL_ID; >+ >+ text = getNoButtonText(); >+ if (text != null) return IHandyDialog.NO_ID; >+ >+ text = getYesButtonText(); >+ if (text != null) return IHandyDialog.YES_ID; >+ >+ boolean helpButtonRequired = isHelpButtonRequired(); >+ if (helpButtonRequired == true) return IHandyDialog.HELP_ID; >+ >+ return HandyPromptDialog.NO_DEFAULT_BUTTON_ID; >+ } >+ >+ private void initializeCheckboxButtons() { >+ setCheckboxButtons(new ArrayList/*<ButtonDetails>*/(3)); >+ } >+ >+ private void initializePushButtons() { >+ setYesButtonText(IDialogConstants.YES_LABEL); >+ setNoButtonText(IDialogConstants.NO_LABEL); >+ setCancelButtonText('&' + IDialogConstants.CANCEL_LABEL); >+ } >+ >+ private void initializeRadioButtons() { >+ setRadioButtons(new ArrayList/*<ButtonDetails>*/(3)); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#isCheckboxSelected(int) >+ */ >+ public boolean isCheckboxSelected(int id) { >+ ButtonDetails details = getCheckboxButtonDetails(id); >+ return details.selected; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#removeAllCheckboxes() >+ */ >+ public void removeAllCheckboxes() { >+ initializeCheckboxButtons(); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#removeAllRadioButtons() >+ */ >+ public void removeAllRadioButtons() { >+ initializeRadioButtons(); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCancelButtonText(java.lang.String) >+ */ >+ public void setCancelButtonText(String cancelButtonText) { >+ this.cancelButtonText = cancelButtonText; >+ } >+ >+ private void setCheckboxButtons(List/*<ButtonDetails>*/ checkboxButtons) { >+ this.checkboxButtons = checkboxButtons; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCheckboxGroupText(java.lang.String) >+ */ >+ public void setCheckboxGroupText(String checkboxGroupText) { >+ this.checkboxGroupText = checkboxGroupText; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCheckboxSelected(int, boolean) >+ */ >+ public void setCheckboxSelected(int id, boolean selected) { >+ ButtonDetails details = getCheckboxButtonDetails(id); >+ details.selected = selected; >+ } >+ >+ private void setDefaultButtonId(int defaultButtonId) { >+ this.defaultButtonId = defaultButtonId; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setImage(org.eclipse.swt.graphics.Image) >+ */ >+ public void setImage(Image image) { >+ this.image = image; >+ } >+ >+ private void setImage(int id) { >+ Image image = getSystemImage(id); >+ setImage(image); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setNoButtonText(java.lang.String) >+ */ >+ public void setNoButtonText(String noButtonText) { >+ this.noButtonText = noButtonText; >+ } >+ >+ private void setPrompt(String prompt) { >+ this.prompt = prompt; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setRadioButtonGroupText(java.lang.String) >+ */ >+ public void setRadioButtonGroupText(String radioButtonGroupText) { >+ this.radioButtonGroupText = radioButtonGroupText; >+ } >+ >+ private void setRadioButtons(List/*<ButtonDetails>*/ radioButtons) { >+ this.radioButtons = radioButtons; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setRadioButtonSelected(int, boolean) >+ */ >+ public void setRadioButtonSelected(int id, boolean selected) { >+ ButtonDetails details = getRadioButtonDetails(id); >+ details.selected = selected; >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setYesButtonText(java.lang.String) >+ */ >+ public void setYesButtonText(String yesButtonText) { >+ this.yesButtonText = yesButtonText; >+ } >+ >+ private void updateButtonSelections() { >+ updateCheckboxButtonSelections(); >+ updateRadioButtonSelections(); >+ } >+ >+ private void updateButtonSelections(List/*<ButtonDetails>*/ list) { >+ synchronized (list) { >+ Iterator/*<ButtonDetails>*/ iterator = list.iterator(); >+ while (iterator.hasNext() == true) { >+ ButtonDetails details = (ButtonDetails) iterator.next(); >+ details.selected = details.button.getSelection(); >+ } >+ } >+ } >+ >+ private void updateCheckboxButtonSelections() { >+ List/*<ButtonDetails>*/ list = getCheckboxButtons(); >+ updateButtonSelections(list); >+ } >+ >+ private void updateRadioButtonSelections() { >+ List/*<ButtonDetails>*/ list = getRadioButtons(); >+ updateButtonSelections(list); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useErrorIcon() >+ */ >+ public void useErrorIcon() { >+ setImage(SWT.ICON_ERROR); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useInformationIcon() >+ */ >+ public void useInformationIcon() { >+ setImage(SWT.ICON_INFORMATION); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useQuestionIcon() >+ */ >+ public void useQuestionIcon() { >+ setImage(SWT.ICON_QUESTION); >+ } >+ >+ /** >+ * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useWarningIcon() >+ */ >+ public void useWarningIcon() { >+ setImage(SWT.ICON_WARNING); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 256731
:
119534
|
119535
| 119573 |
119574
|
120039