Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java')
-rw-r--r--bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java99
1 files changed, 54 insertions, 45 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java
index e5e472e4..4fbc09b8 100644
--- a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java
+++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/ToolControlContributionEditor.java
@@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Dmitry Spiridenok <d.spiridenok@gmail.com> - Bug 412672
+ * Dmitry Spiridenok <d.spiridenok@gmail.com> - Bug 412672
******************************************************************************/
package org.eclipse.e4.tools.emf.editor3x.extension;
@@ -14,9 +14,9 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.e4.internal.tools.wizards.classes.NewToolControlClassWizard;
+import org.eclipse.e4.tools.emf.editor3x.Messages;
import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator;
import org.eclipse.e4.ui.model.application.MContribution;
-import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
import org.eclipse.emf.common.command.Command;
@@ -37,26 +37,31 @@ import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PartInitException;
+@SuppressWarnings("restriction")
public class ToolControlContributionEditor implements IContributionClassCreator {
+ @Override
public void createOpen(MContribution contribution, EditingDomain domain, IProject project, Shell shell) {
createOpen(contribution, domain, project, shell, false);
}
- 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:") ) {
- NewToolControlClassWizard wizard = new NewToolControlClassWizard(contribution.getContributionURI());
- wizard.init( null, new StructuredSelection(project));
- WizardDialog dialog = new WizardDialog(shell, wizard);
- if( dialog.open() == Window.OK ) {
- IFile f = wizard.getFile();
- ICompilationUnit el = JavaCore.createCompilationUnitFrom(f);
+ 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:")) { //$NON-NLS-1$
+ final NewToolControlClassWizard wizard = new NewToolControlClassWizard(contribution.getContributionURI());
+ wizard.init(null, new StructuredSelection(project));
+ final WizardDialog dialog = new WizardDialog(shell, wizard);
+ if (dialog.open() == Window.OK) {
+ final IFile f = wizard.getFile();
+ final ICompilationUnit el = JavaCore.createCompilationUnitFrom(f);
try {
String fullyQualified;
- if( el.getPackageDeclarations() != null && el.getPackageDeclarations().length > 0 ) {
- String packageName = el.getPackageDeclarations()[0].getElementName();
- String className = wizard.getDomainClass().getName();
- if( packageName.trim().length() > 0 ) {
- fullyQualified = packageName + "." + className;
+ if (el.getPackageDeclarations() != null && el.getPackageDeclarations().length > 0) {
+ final String packageName = el.getPackageDeclarations()[0].getElementName();
+ final String className = wizard.getDomainClass().getName();
+ if (packageName.trim().length() > 0) {
+ fullyQualified = packageName + "." + className; //$NON-NLS-1$
} else {
fullyQualified = className;
}
@@ -64,26 +69,28 @@ public class ToolControlContributionEditor implements IContributionClassCreator
fullyQualified = wizard.getDomainClass().getName();
}
- Command cmd = SetCommand.create(domain, contribution, ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, "bundleclass://" + Util.getBundleSymbolicName(f.getProject()) + "/" + fullyQualified);
- if( cmd.canExecute() ) {
+ final Command cmd = SetCommand.create(domain, contribution,
+ ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI,
+ "bundleclass://" + Util.getBundleSymbolicName(f.getProject()) + "/" + fullyQualified); //$NON-NLS-1$ //$NON-NLS-2$
+ if (cmd.canExecute()) {
domain.getCommandStack().execute(cmd);
}
- } catch (JavaModelException e) {
+ } catch (final JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
- URI uri = URI.createURI(contribution.getContributionURI());
+ final URI uri = URI.createURI(contribution.getContributionURI());
if (uri.hasAuthority() && uri.segmentCount() == 1) {
- String symbolicName = uri.authority();
- String fullyQualified = uri.segment(0);
+ final String symbolicName = uri.authority();
+ final String fullyQualified = uri.segment(0);
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(symbolicName);
- if( ! p.exists() ) {
- for( IProject check : ResourcesPlugin.getWorkspace().getRoot().getProjects() ) {
- String name = Util.getBundleSymbolicName(check);
- if( symbolicName.equals(name) ) {
+ if (!p.exists()) {
+ for (final IProject check : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ final String name = Util.getBundleSymbolicName(check);
+ if (symbolicName.equals(name)) {
p = check;
break;
}
@@ -92,37 +99,39 @@ public class ToolControlContributionEditor implements IContributionClassCreator
// TODO If this is not a WS-Resource we need to open differently
if (p != null) {
- IJavaProject jp = JavaCore.create(p);
+ final IJavaProject jp = JavaCore.create(p);
IType t = null;
- try {
- if (p.exists()){
- t = jp.findType(fullyQualified);
- }
- else
- {
- IJavaProject pprim = JavaCore.create(project);
- t = pprim.findType(fullyQualified);
- }
- if( t != null ) {
- JavaUI.openInEditor(t);
- } else {
- createOpen(contribution, domain, project, shell, true);
- }
- } catch (JavaModelException e) {
+ try {
+ if (p.exists()) {
+ t = jp.findType(fullyQualified);
+ }
+ else
+ {
+ final IJavaProject pprim = JavaCore.create(project);
+ t = pprim.findType(fullyQualified);
+ }
+ if (t != null) {
+ JavaUI.openInEditor(t);
+ } else {
createOpen(contribution, domain, project, shell, true);
- } catch (PartInitException e) {
- MessageDialog.openError(shell, "Failed to open editor", e.getMessage());
+ }
+ } catch (final JavaModelException e) {
+ createOpen(contribution, domain, project, shell, true);
+ } catch (final PartInitException e) {
+ MessageDialog.openError(shell, Messages.ContributionEditor_FailedToOpenEditor, e.getMessage());
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
- MessageDialog.openError(shell, "Invalid URL", "The current url is invalid");
+ MessageDialog.openError(shell, Messages.ContributionEditor_InvalidURL,
+ Messages.ContributionEditor_CurrentURLIsInvalid);
}
}
}
+ @Override
public boolean isSupported(EClass element) {
- return Util.isTypeOrSuper(MenuPackageImpl.Literals.TOOL_CONTROL,element);
+ return Util.isTypeOrSuper(MenuPackageImpl.Literals.TOOL_CONTROL, element);
}
}

Back to the top