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 119534 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]
Prototype
org.eclipse.pde.ds.ui.183.patch (text/plain), 16.90 KB, created by
Rafael Oliveira Nóbrega
on 2008-12-04 13:08:33 EST
(
hide
)
Description:
Prototype
Filename:
MIME Type:
Creator:
Rafael Oliveira Nóbrega
Created:
2008-12-04 13:08:33 EST
Size:
16.90 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.ds.ui2 >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 17:59:08 -0000 >@@ -34,8 +34,13 @@ > 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) > > DSImplementationDetails_title=Definition > DSImplementationDetails_description=Specify the service's implementation class: >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 17:59:08 -0000 >@@ -40,8 +40,13 @@ > 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 DSImplementationDetails_title; > public static String DSImplementationDetails_description; >@@ -165,6 +170,7 @@ > > public static String DSService_title; > >+ > > > >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 17:59:10 -0000 >@@ -14,15 +14,33 @@ > > 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.dialogs.MessageDialog; > 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.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"; >+ private static final String F_OSGI_FOLDER_NAME = "OSGI-INF"; > protected DSFileWizardPage fMainPage; > > public DSNewWizard() { >@@ -32,28 +50,102 @@ > /* > * (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 = MessageDialog.openQuestion(this.getShell(), >+ Messages.DSNewWizard_defaultOSGIFolder_title, >+ Messages.DSNewWizard_defaultOSGIFolder_message); >+ this.getDialogSettings().put(F_DefaultOSGIFolder_key, value); >+ } else { >+ value = this.getDialogSettings().getBoolean(F_DefaultOSGIFolder_key); >+ } >+ >+ currentSelection = setCurrentSelection(currentSelection); >+ > fMainPage = new DSFileWizardPage(currentSelection); > } > >+ private IStructuredSelection setCurrentSelection( >+ 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 { >+ if (MessageDialog >+ .openQuestion(this.getShell(), >+ Messages.DSNewWizard_createOSGIFolder_title, >+ Messages.DSNewWizard_createOSGIFolder_message)) { >+ 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 +153,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 17:59:09 -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(); >+ } > }
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