Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSopot Cela2012-09-09 17:11:16 -0400
committerSopot Cela2012-09-09 17:11:16 -0400
commitf314b2edd4649cab2fad1c1c14dc5322cea5c7c2 (patch)
treeb34db422707bd41319ca217212567704b2aa0e92
parente82a462a8ecb7572a5c4845f56ce23400908c6e9 (diff)
downloadorg.eclipse.e4.tools-f314b2edd4649cab2fad1c1c14dc5322cea5c7c2.tar.gz
org.eclipse.e4.tools-f314b2edd4649cab2fad1c1c14dc5322cea5c7c2.tar.xz
org.eclipse.e4.tools-f314b2edd4649cab2fad1c1c14dc5322cea5c7c2.zip
bug 389039: Handler, Addon and Part class URI wizard autofill package
and name https://bugs.eclipse.org/bugs/show_bug.cgi?id=389039
-rw-r--r--bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/AddonContributionEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/HandlerContributionEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/PartContributionEditor.java7
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassPage.java89
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassWizard.java25
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewAddonClassWizard.java9
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewHandlerClassWizard.java10
-rw-r--r--bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewPartClassWizard.java9
8 files changed, 137 insertions, 26 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/AddonContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/AddonContributionEditor.java
index 023ecb2b..87fa59a3 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/AddonContributionEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/AddonContributionEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.tools.emf.editor3x.extension;
@@ -54,7 +55,7 @@ public class AddonContributionEditor implements IContributionClassCreator {
private void createOpen(MContribution contribution, EditingDomain domain,
IProject project, Shell shell, boolean forceNew) {
if( forceNew || contribution.getContributionURI() == null || contribution.getContributionURI().trim().length() == 0 || !contribution.getContributionURI().startsWith("bundleclass:") ) {
- NewAddonClassWizard wizard = new NewAddonClassWizard();
+ NewAddonClassWizard wizard = new NewAddonClassWizard(contribution.getContributionURI());
wizard.init( null, new StructuredSelection(project));
WizardDialog dialog = new WizardDialog(shell, wizard);
if( dialog.open() == WizardDialog.OK ) {
@@ -109,14 +110,10 @@ public class AddonContributionEditor implements IContributionClassCreator {
if( t != null ) {
JavaUI.openInEditor(t);
} else {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
}
} catch (JavaModelException e) {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
} catch (PartInitException e) {
MessageDialog.openError(shell, "Failed to open editor", e.getMessage());
// TODO Auto-generated catch block
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/HandlerContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/HandlerContributionEditor.java
index 4b14881e..e6aed7c9 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/HandlerContributionEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/HandlerContributionEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.tools.emf.editor3x.extension;
@@ -44,7 +45,7 @@ public class HandlerContributionEditor implements IContributionClassCreator {
private void createOpen(MContribution contribution, EditingDomain domain, IProject project, Shell shell, boolean forceNew) {
if( forceNew || contribution.getContributionURI() == null || contribution.getContributionURI().trim().length() == 0 || !contribution.getContributionURI().startsWith("bundleclass:") ) {
- NewHandlerClassWizard wizard = new NewHandlerClassWizard();
+ NewHandlerClassWizard wizard = new NewHandlerClassWizard(contribution.getContributionURI());
wizard.init( null, new StructuredSelection(project));
WizardDialog dialog = new WizardDialog(shell, wizard);
if( dialog.open() == WizardDialog.OK ) {
@@ -99,14 +100,10 @@ public class HandlerContributionEditor implements IContributionClassCreator {
if( t != null ) {
JavaUI.openInEditor(t);
} else {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
}
} catch (JavaModelException e) {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
} catch (PartInitException e) {
MessageDialog.openError(shell, "Failed to open editor", e.getMessage());
// TODO Auto-generated catch block
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/PartContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/PartContributionEditor.java
index 83eadf22..cd15cfa9 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/PartContributionEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/PartContributionEditor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.tools.emf.editor3x.extension;
@@ -46,7 +47,7 @@ public class PartContributionEditor implements IContributionClassCreator {
if ( forceNew || contribution.getContributionURI() == null
|| contribution.getContributionURI().trim().length() == 0
|| !contribution.getContributionURI().startsWith("bundleclass:")) {
- NewPartClassWizard wizard = new NewPartClassWizard();
+ NewPartClassWizard wizard = new NewPartClassWizard(contribution.getContributionURI());
wizard.init(null, new StructuredSelection(project));
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() == WizardDialog.OK) {
@@ -101,14 +102,10 @@ public class PartContributionEditor implements IContributionClassCreator {
if( t != null ) {
JavaUI.openInEditor(t);
} else {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
}
} catch (JavaModelException e) {
- if( MessageDialog.openQuestion(shell, "Class not found", "The class '"+fullyQualified+"' was not found. Would you like to start the class creation wizard?") ) {
createOpen(contribution, domain, project, shell, true);
- }
} catch (PartInitException e) {
MessageDialog.openError(shell, "Failed to open editor", e.getMessage());
// TODO Auto-generated catch block
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassPage.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassPage.java
index c137f6c6..af61db6b 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassPage.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassPage.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
@@ -111,6 +112,7 @@ public abstract class AbstractNewClassPage extends WizardPage {
private JavaClass clazz;
private IPackageFragmentRoot froot;
private IWorkspaceRoot fWorkspaceRoot;
+ private String initialString;
protected AbstractNewClassPage(String pageName, String title, String description, IPackageFragmentRoot froot, IWorkspaceRoot fWorkspaceRoot) {
super(pageName);
@@ -121,6 +123,11 @@ public abstract class AbstractNewClassPage extends WizardPage {
setDescription(description);
}
+ protected AbstractNewClassPage(String pageName, String title, String description, IPackageFragmentRoot froot, IWorkspaceRoot fWorkspaceRoot, String initialString){
+ this(pageName,title,description,froot,fWorkspaceRoot);
+ this.initialString=initialString;
+ }
+
public void createControl(Composite parent) {
final Image img = new Image(parent.getDisplay(), getClass().getClassLoader().getResourceAsStream("/icons/full/wizban/newclass_wiz.png"));
setImageDescriptor(ImageDescriptor.createFromImage(img));
@@ -138,7 +145,9 @@ public abstract class AbstractNewClassPage extends WizardPage {
parent.setLayout(new GridLayout(3, false));
clazz = createInstance();
-
+
+ clazz.setPackageFragment(froot.getPackageFragment(parseInitialStringForPackage(initialString)==null?"":parseInitialStringForPackage(initialString)));
+ clazz.setName(parseInitialStringForClassName(initialString));
DataBindingContext dbc = new DataBindingContext();
WizardPageSupport.create(this, dbc);
@@ -149,6 +158,7 @@ public abstract class AbstractNewClassPage extends WizardPage {
Text t = new Text(parent, SWT.BORDER);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
t.setEditable(false);
+
final Binding bd = dbc.bindValue(
WidgetProperties.text().observe(t),
BeanProperties.value("fragmentRoot").observe(clazz),
@@ -166,7 +176,7 @@ public abstract class AbstractNewClassPage extends WizardPage {
froot = root;
clazz.setFragmentRoot(root);
}
- bd.updateModelToTarget(); //TODO Find out why this is needed
+ bd.updateModelToTarget();
}
});
}
@@ -174,14 +184,13 @@ public abstract class AbstractNewClassPage extends WizardPage {
{
Label l = new Label(parent, SWT.NONE);
l.setText("Package");
-
Text t = new Text(parent, SWT.BORDER);
- t.setEditable(false);
+ t.setEditable(true);
t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
final Binding bd = dbc.bindValue(
- WidgetProperties.text().observe(t),
+ WidgetProperties.text(SWT.Modify).observe(t),
BeanProperties.value("packageFragment").observe(clazz),
- new UpdateValueStrategy(),
+ new UpdateValueStrategy().setConverter(new StringToPackageFragmentConverter(froot)),
new UpdateValueStrategy().setConverter(new PackageFragmentToStringConverter())
);
@@ -222,6 +231,49 @@ public abstract class AbstractNewClassPage extends WizardPage {
setControl(parent);
}
+ private String parseInitialStringForPackage(String initialString2) {
+ if (initialString2==null) return null;
+ int ioBC = initialString2.indexOf("bundleclass://");
+ int iSecondSlash = initialString2.lastIndexOf('/');
+ if (
+
+ (initialString2.length()==0)||//empty
+ (ioBC==-1)||//no bundle class
+ (iSecondSlash==-1)||//no package &| class name
+ (initialString2.indexOf('.')==-1)//no package
+ ){
+ System.err.println("unparsable");
+ return null;
+ }
+ System.err.println("First: "+initialString2);;
+ int bi = ioBC+"bundleclass://".length()-1;
+ int ei = iSecondSlash;
+
+ int lastDot = initialString2.lastIndexOf('.');
+ String packageString = initialString2.substring(iSecondSlash+1, lastDot);
+ return packageString;
+ }
+
+ private String parseInitialStringForClassName(String initialString){
+ if (initialString==null) return null;
+ int ioBC = initialString.indexOf("bundleclass://");
+ int iSecondSlash = initialString.lastIndexOf('/');
+ if (
+
+ (initialString.length()==0)||//empty
+ (ioBC==-1)||//no bundle class
+ (iSecondSlash==-1)||//no package &| class name
+ (initialString.indexOf('.')==-1)//no package
+ ){
+ System.err.println("unparsable");
+ return null;
+ }
+ int lastDot = initialString.lastIndexOf('.');
+ if (lastDot!=-1)
+ return initialString.substring(lastDot+1);
+ return null;
+ }
+
private IPackageFragmentRoot choosePackageRoot() {
IJavaElement initElement= clazz.getFragmentRoot();
Class[] acceptedClasses= new Class[] { IPackageFragmentRoot.class, IJavaProject.class };
@@ -303,7 +355,6 @@ public abstract class AbstractNewClassPage extends WizardPage {
dialog.setEmptyListMessage("You need to select a package");
dialog.setElements(packages);
dialog.setHelpAvailable(false);
-
IPackageFragment pack= clazz.getPackageFragment();
if (pack != null) {
dialog.setInitialSelections(new Object[] { pack });
@@ -365,4 +416,28 @@ public abstract class AbstractNewClassPage extends WizardPage {
return f.getElementName();
}
}
+
+ static class StringToPackageFragmentConverter extends Converter {
+
+ private IPackageFragmentRoot proot;
+
+ public StringToPackageFragmentConverter(IPackageFragmentRoot froot) {
+ super(String.class, IPackageFragment.class);
+ this.proot = froot;
+ }
+
+ public Object convert(Object fromObject) {
+ try {
+ if( fromObject == null ) {
+ return proot.createPackageFragment("", true, null);
+ }
+
+ return proot.getPackageFragment((String) fromObject);
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+ }
}
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassWizard.java
index 523e003b..5abe6b38 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/AbstractNewClassWizard.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
@@ -49,7 +50,9 @@ import org.osgi.framework.ServiceReference;
public abstract class AbstractNewClassWizard extends Wizard implements INewWizard {
protected IPackageFragmentRoot root;
protected IFile file;
-
+ public AbstractNewClassWizard() {
+ this.setWindowTitle("New contribution class");
+ }
public void init(IWorkbench workbench, IStructuredSelection selection) {
root = getFragmentRoot(getInitialJavaElement(selection));
}
@@ -174,7 +177,27 @@ public abstract class AbstractNewClassWizard extends Wizard implements INewWizar
checkRequiredBundles();
IPackageFragment fragment = clazz.getPackageFragment();
+ boolean exists = false;
if (fragment != null) {
+ IJavaElement[] children;
+ try {
+ children = clazz.getFragmentRoot().getChildren();
+
+ for (IJavaElement iJavaElement : children) {
+ IPackageFragment pf = (IPackageFragment) iJavaElement;
+ if (pf.getElementName().equals(fragment.getElementName())){
+ exists = true;
+ break;
+ }
+ }
+ ;
+
+ if (!exists)
+ fragment = clazz.getFragmentRoot().createPackageFragment(fragment.getElementName(), true, null);
+ } catch (JavaModelException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
String cuName = clazz.getName() + ".java";
ICompilationUnit unit = fragment.getCompilationUnit(cuName);
IResource resource = unit.getResource();
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewAddonClassWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewAddonClassWizard.java
index 58432912..94325ef7 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewAddonClassWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewAddonClassWizard.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
@@ -18,11 +19,17 @@ import org.eclipse.e4.internal.tools.wizards.classes.templates.AddonTemplate;
import org.eclipse.swt.widgets.Composite;
public class NewAddonClassWizard extends AbstractNewClassWizard {
+ private String initialString;
+
+ public NewAddonClassWizard(String contributionURI) {
+ this.initialString = contributionURI;
+ }
+
@Override
public void addPages() {
addPage(new AbstractNewClassPage("Classinformation",
"New Addon",
- "Create a new addon class", root, ResourcesPlugin.getWorkspace().getRoot()) {
+ "Create a new addon class", root, ResourcesPlugin.getWorkspace().getRoot(), initialString) {
@Override
protected void createFields(Composite parent,
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewHandlerClassWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewHandlerClassWizard.java
index f970424a..b5b29f3e 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewHandlerClassWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewHandlerClassWizard.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
@@ -28,6 +29,13 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class NewHandlerClassWizard extends AbstractNewClassWizard {
+ private String initialString;
+
+ public NewHandlerClassWizard(String contributionURI) {
+ this.initialString = contributionURI;
+
+ }
+
@Override
protected String getContent() {
HandlerTemplate template = new HandlerTemplate();
@@ -38,7 +46,7 @@ public class NewHandlerClassWizard extends AbstractNewClassWizard {
public void addPages() {
addPage(new AbstractNewClassPage("Classinformation",
"New Handler",
- "Create a new handler class", root, ResourcesPlugin.getWorkspace().getRoot()) {
+ "Create a new handler class", root, ResourcesPlugin.getWorkspace().getRoot(),initialString) {
@Override
protected JavaClass createInstance() {
diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewPartClassWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewPartClassWizard.java
index db3d3bf6..1f6526f4 100644
--- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewPartClassWizard.java
+++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewPartClassWizard.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
+ * Sopot Cela <sopotcela@gmail.com>
******************************************************************************/
package org.eclipse.e4.internal.tools.wizards.classes;
@@ -31,11 +32,17 @@ import org.eclipse.swt.widgets.Text;
public class NewPartClassWizard extends AbstractNewClassWizard {
+ private String initialString;
+
+ public NewPartClassWizard(String contributionURI) {
+ this.initialString = contributionURI;
+ }
+
@Override
public void addPages() {
addPage(new AbstractNewClassPage("Classinformation", "New Part",
"Create a new part class", root, ResourcesPlugin.getWorkspace()
- .getRoot()) {
+ .getRoot(), initialString) {
@Override
protected void createFields(Composite parent, DataBindingContext dbc) {

Back to the top