diff options
author | Marco Descher | 2013-02-15 11:09:52 +0000 |
---|---|---|
committer | Lars Vogel | 2013-03-13 12:08:56 +0000 |
commit | 99eb399fc0ea72e866c7d306b97848d59fac9011 (patch) | |
tree | 68d08873ce2490ac6611ff66c24625eff35360df | |
parent | e772b62b3322121abc0c9d9c7a2a630164da015a (diff) | |
download | org.eclipse.e4.tools-99eb399fc0ea72e866c7d306b97848d59fac9011.tar.gz org.eclipse.e4.tools-99eb399fc0ea72e866c7d306b97848d59fac9011.tar.xz org.eclipse.e4.tools-99eb399fc0ea72e866c7d306b97848d59fac9011.zip |
[395982] Dynamic menu contribution; Application model editor tooling
part
15 files changed, 623 insertions, 7 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml index d141b313..05d1907e 100644 --- a/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/plugin.xml @@ -23,6 +23,9 @@ <contributionClassCreator class="org.eclipse.e4.tools.emf.editor3x.extension.AddonContributionEditor"> </contributionClassCreator> + <contributionClassCreator + class="org.eclipse.e4.tools.emf.editor3x.extension.DynamicMenuContributionContributionEditor"> + </contributionClassCreator> </extension> <extension point="org.eclipse.ui.preferencePages"> diff --git a/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/DynamicMenuContributionContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/DynamicMenuContributionContributionEditor.java new file mode 100644 index 00000000..a9f1c3ce --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/extension/DynamicMenuContributionContributionEditor.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2013 MEDEVIT, FHV 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: + * Marco Descher <marco@descher.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.tools.emf.editor3x.extension; + +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.NewDynamicMenuContributionClassWizard; +import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator; +import org.eclipse.e4.ui.model.application.MContribution; +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; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +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.ui.JavaUI; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PartInitException; + +public class DynamicMenuContributionContributionEditor implements + IContributionClassCreator { + + public void createOpen(MContribution contribution, EditingDomain domain, IProject project, Shell shell) { + createOpen(contribution, domain, project, shell, false); + } + + public 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:") ) { + NewDynamicMenuContributionClassWizard wizard = new NewDynamicMenuContributionClassWizard(contribution.getContributionURI()); + wizard.init( null, new StructuredSelection(project)); + WizardDialog dialog = new WizardDialog(shell, wizard); + if( dialog.open() == WizardDialog.OK ) { + IFile f = wizard.getFile(); + 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; + } else { + fullyQualified = className; + } + } else { + fullyQualified = wizard.getDomainClass().getName(); + } + + Command cmd = SetCommand.create(domain, contribution, ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, "bundleclass://" + Util.getBundleSymbolicName(f.getProject()) + "/" + fullyQualified); + if( cmd.canExecute() ) { + domain.getCommandStack().execute(cmd); + } + } catch (JavaModelException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } else { + URI uri = URI.createURI(contribution.getContributionURI()); + if (uri.hasAuthority() && uri.segmentCount() == 1) { + String symbolicName = uri.authority(); + 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) ) { + p = check; + break; + } + } + } + + // TODO If this is not a WS-Resource we need to open differently + if (p != null) { + 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) { + createOpen(contribution, domain, project, shell, true); + } catch (PartInitException e) { + MessageDialog.openError(shell, "Failed to open editor", e.getMessage()); + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } else { + MessageDialog.openError(shell, "Invalid URL", + "The current url is invalid"); + } + } + } + + public boolean isSupported(EClass element) { + return Util.isTypeOrSuper(MenuPackageImpl.Literals.DYNAMIC_MENU_CONTRIBUTION, element); + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties b/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties index 31acf1b1..7e109d4c 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties +++ b/bundles/org.eclipse.e4.tools.emf.ui/OSGI-INF/resources.properties @@ -17,6 +17,7 @@ IMG_org.eclipse.e4.tools.emf.ui.modelelements.KeyBinding=/icons/full/modelelemen IMG_org.eclipse.e4.tools.emf.ui.modelelements.Menu=/icons/full/modelelements/Menu.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuContribution=/icons/full/modelelements/MenuContribution.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuItem=/icons/full/modelelements/MenuItem.gif +IMG_org.eclipse.e4.tools.emf.ui.modelelements.DynamicMenuContribution=/icons/full/modelelements/DynamicMenuContribution.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuSeparator=/icons/full/modelelements/MenuSeparator.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.ModelFragments=/icons/full/modelelements/ModelFragments.png IMG_org.eclipse.e4.tools.emf.ui.modelelements.Parameter=/icons/full/modelelements/Parameter.png @@ -51,6 +52,7 @@ IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.HandledToolItem=/icons/full/mo IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.Menu=/icons/full/modelelements/tbr/Menu.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuContribution=/icons/full/modelelements/tbr/MenuContribution.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuItem=/icons/full/modelelements/tbr/MenuItem.gif +IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.DynamicMenuContribution=/icons/full/modelelements/tbr/DynamicMenuContribution.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuSeparator=/icons/full/modelelements/tbr/MenuSeparator.gif IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.ModelFragments=/icons/full/modelelements/tbr/ModelFragments.png IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.Parameter=/icons/full/modelelements/tbr/Parameter.gif diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/DynamicMenuContribution.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/DynamicMenuContribution.gif Binary files differnew file mode 100644 index 00000000..29f08863 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/DynamicMenuContribution.gif diff --git a/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/tbr/DynamicMenuContribution.gif b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/tbr/DynamicMenuContribution.gif Binary files differnew file mode 100644 index 00000000..b2caa8a1 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/icons/full/modelelements/tbr/DynamicMenuContribution.gif diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java index e8355836..22189a5f 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 BestSolution.at and others. + * Copyright (c) 2010-2013 BestSolution.at 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 @@ -7,6 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Marco Descher <marco@descher.at> - Bug 395982 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal; @@ -97,6 +98,12 @@ public class Messages { public String HandledMenuItemEditor_Tag; public String HandledMenuItemEditor_Value; + public String DynamicMenuContributionEditor_Label; + public String DynamicMenuContributionEditor_Description; + + public String DynamicMenuContributionEditor_ClassURI; + public String DynamicMenuContributionEditor_LabelLabel; + public String HandledToolItemEditor_Command; public String HandledToolItemEditor_Parameters; public String HandledToolItemEditor_ParametersName; @@ -140,6 +147,7 @@ public class Messages { public String MenuEditor_AddMenu; public String MenuEditor_AddDirectMenuItem; public String MenuEditor_AddSeparator; + public String MenuEditor_AddDynamicMenuContribution; public String MenuEditor_AddCoreExpression; public String MenuItemEditor_Type; diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties index 34ecbf8b..01e57514 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties @@ -1,5 +1,5 @@ # ****************************************************************************** -# * Copyright (c) 2010 BestSolution.at and others. +# * Copyright (c) 2010-2013 BestSolution.at 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 @@ -8,6 +8,7 @@ # * Contributors: # * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation # * Sopot Cela <sopotcela@gmail.com> - enhancements +# * Marco Descher <marco@descher.at> - Bug 395982 # ****************************************************************************** ModelTooling_Common_Up=Up ModelTooling_Common_Down=Down @@ -96,6 +97,12 @@ HandledMenuItemEditor_Parameters=Parameters HandledMenuItemEditor_Tag=Name HandledMenuItemEditor_Value=Value +DynamicMenuContributionEditor_Label=DynamicMenuContribution +DynamicMenuContributionEditor_Description=DynamicMenuContribution blablabla + +DynamicMenuContributionEditor_ClassURI=Class URI +DynamicMenuContributionEditor_LabelLabel=Label + HandledToolItemEditor_Command=Command HandledToolItemEditor_Parameters=Parameters HandledToolItemEditor_ParametersName=Name @@ -140,6 +147,7 @@ MenuEditor_AddHandledMenuItem=HandledMenuItem MenuEditor_AddMenu=Menu MenuEditor_AddDirectMenuItem=DirectMenuItem MenuEditor_AddSeparator=Separator +MenuEditor_AddDynamicMenuContribution=DynamicMenuContribution MenuEditor_AddCoreExpression=VisibleWhen Core Expression diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java index 41e62681..60c8ecf0 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/ResourceProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 BestSolution.at + * Copyright (c) 2011-2013 BestSolution.at * 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 @@ -7,6 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Marco Descher <marco@descher.at> - Bug 395982 *******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal; @@ -32,6 +33,7 @@ public class ResourceProvider extends BasicResourceProvider { public static final String IMG_Menu = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.Menu"; //$NON-NLS-1$ public static final String IMG_MenuContribution = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuContribution"; //$NON-NLS-1$ public static final String IMG_MenuItem = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuItem"; //$NON-NLS-1$ + public static final String IMG_DynamicMenuContribution = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.DynamicMenuContribution"; //$NON-NLS-1$ public static final String IMG_MenuSeparator = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.MenuSeparator"; //$NON-NLS-1$ public static final String IMG_ModelFragments = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.ModelFragments"; //$NON-NLS-1$ public static final String IMG_Parameter = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.Parameter"; //$NON-NLS-1$ @@ -66,6 +68,7 @@ public class ResourceProvider extends BasicResourceProvider { public static final String IMG_Tbr_Menu = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.Menu"; //$NON-NLS-1$ public static final String IMG_Tbr_MenuContribution = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuContribution"; //$NON-NLS-1$ public static final String IMG_Tbr_MenuItem = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuItem"; //$NON-NLS-1$ + public static final String IMG_Tbr_DynamicMenuContribution = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.DynamicMenuContribution"; //$NON-NLS-1$ public static final String IMG_Tbr_MenuSeparator = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.MenuSeparator"; //$NON-NLS-1$ public static final String IMG_Tbr_ModelFragments = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.ModelFragments"; //$NON-NLS-1$ public static final String IMG_Tbr_Parameter = "IMG_org.eclipse.e4.tools.emf.ui.modelelements.tbr.Parameter"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java index 4210e267..9640c9ca 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 BestSolution.at and others. + * Copyright (c) 2010-2013 BestSolution.at 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 @@ -8,6 +8,7 @@ * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Wim Jongman <wim.jongman@remainsoftware.com> - Maintenance + * Marco Descher <marco@descher.at> - Bug395982 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common; @@ -71,6 +72,7 @@ import org.eclipse.e4.tools.emf.ui.internal.common.component.CoreExpressionEdito import org.eclipse.e4.tools.emf.ui.internal.common.component.DefaultEditor; import org.eclipse.e4.tools.emf.ui.internal.common.component.DirectMenuItemEditor; import org.eclipse.e4.tools.emf.ui.internal.common.component.DirectToolItemEditor; +import org.eclipse.e4.tools.emf.ui.internal.common.component.DynamicMenuContributionEditor; import org.eclipse.e4.tools.emf.ui.internal.common.component.HandledMenuItemEditor; import org.eclipse.e4.tools.emf.ui.internal.common.component.HandledToolItemEditor; import org.eclipse.e4.tools.emf.ui.internal.common.component.HandlerEditor; @@ -1119,6 +1121,7 @@ public class ModelEditor { registerEditor(MenuPackageImpl.Literals.MENU_CONTRIBUTION, ContextInjectionFactory.make(MenuContributionEditor.class, context)); registerEditor(MenuPackageImpl.Literals.TOOL_BAR_CONTRIBUTION, ContextInjectionFactory.make(ToolBarContributionEditor.class, context)); registerEditor(MenuPackageImpl.Literals.TRIM_CONTRIBUTION, ContextInjectionFactory.make(TrimContributionEditor.class, context)); + registerEditor(MenuPackageImpl.Literals.DYNAMIC_MENU_CONTRIBUTION, ContextInjectionFactory.make(DynamicMenuContributionEditor.class, context)); registerEditor(UiPackageImpl.Literals.CORE_EXPRESSION, ContextInjectionFactory.make(CoreExpressionEditor.class, context)); diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java new file mode 100644 index 00000000..d8757498 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/DynamicMenuContributionEditor.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2013 MEDEVIT, FHV 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: + * Marco Descher <marco@descher.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.tools.emf.ui.internal.common.component; + +import javax.inject.Inject; +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.observable.list.IObservableList; +import org.eclipse.core.databinding.observable.value.WritableValue; +import org.eclipse.core.resources.IProject; +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.tools.emf.ui.common.ContributionURIValidator; +import org.eclipse.e4.tools.emf.ui.common.EStackLayout; +import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator; +import org.eclipse.e4.tools.emf.ui.common.Util; +import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor; +import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider; +import org.eclipse.e4.tools.emf.ui.internal.common.component.ControlFactory.TextPasteHandler; +import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.ContributionClassDialog; +import org.eclipse.e4.ui.model.application.MContribution; +import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; +import org.eclipse.e4.ui.model.application.ui.MUIElement; +import org.eclipse.e4.ui.model.application.ui.MUILabel; +import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl; +import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl; +import org.eclipse.emf.databinding.EMFDataBindingContext; +import org.eclipse.emf.databinding.edit.EMFEditProperties; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.databinding.swt.IWidgetValueProperty; +import org.eclipse.jface.databinding.swt.WidgetProperties; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +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.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.Text; + +public class DynamicMenuContributionEditor extends AbstractComponentEditor { + + private Composite composite; + private EMFDataBindingContext context; + + private EStackLayout stackLayout; + + @Inject + @Optional + private IProject project; + + public DynamicMenuContributionEditor() { + super(); + } + + @Override + public String getLabel(Object element) { + return Messages.DynamicMenuContributionEditor_Label; + } + + @Override + public String getDescription(Object element) { + return Messages.DynamicMenuContributionEditor_Description; + } + + @Override + public Image getImage(Object element, Display display) { + if (element instanceof MUIElement) { + if (((MUIElement) element).isToBeRendered()) { + return createImage(ResourceProvider.IMG_DynamicMenuContribution); + } else { + return createImage(ResourceProvider.IMG_Tbr_DynamicMenuContribution); + } + } + + return null; + } + + @Override + public String getDetailLabel(Object element) { + return getLocalizedLabel((MUILabel) element); + } + + @Override + protected Composite doGetEditor(Composite parent, Object object) { + if (composite == null) { + context = new EMFDataBindingContext(); + if (getEditor().isModelFragment()) { + composite = new Composite(parent, SWT.NONE); + stackLayout = new EStackLayout(); + composite.setLayout(stackLayout); + createForm(composite, context, getMaster(), false); + createForm(composite, context, getMaster(), true); + } else { + composite = createForm(parent, context, getMaster(), false); + } + } + + if (getEditor().isModelFragment()) { + Control topControl; + if (Util.isImport((EObject) object)) { + topControl = composite.getChildren()[1]; + } else { + topControl = composite.getChildren()[0]; + } + + if (stackLayout.topControl != topControl) { + stackLayout.topControl = topControl; + composite.layout(true, true); + } + } + + getMaster().setValue(object); + return composite; + } + + private Composite createForm(Composite parent, final EMFDataBindingContext context, WritableValue master, boolean isImport) { + CTabFolder folder = new CTabFolder(parent, SWT.BOTTOM); + + CTabItem item = new CTabItem(folder, SWT.NONE); + item.setText(Messages.ModelTooling_Common_TabDefault); + + parent = createScrollableContainer(folder); + item.setControl(parent.getParent()); + + if (getEditor().isShowXMIId() || getEditor().isLiveModel()) { + ControlFactory.createXMIId(parent, this); + } + + IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify); + + if (isImport) { + ControlFactory.createFindImport(parent, Messages, this, context); + folder.setSelection(0); + return folder; + } + + ControlFactory.createTextField(parent, Messages.ModelTooling_Common_Id, master, context, textProp, EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__ELEMENT_ID)); + ControlFactory.createTranslatedTextField(parent, Messages.DynamicMenuContributionEditor_LabelLabel, getMaster(), context, textProp, EMFEditProperties.value(getEditingDomain(), UiPackageImpl.Literals.UI_LABEL__LABEL), resourcePool, project); + + // ------------------------------------------------------------ + final Link lnk = new Link(parent, SWT.NONE); + { + final IContributionClassCreator c = getEditor().getContributionCreator(MenuPackageImpl.Literals.DYNAMIC_MENU_CONTRIBUTION); + if (project != null && c != null) { + + lnk.setText("<A>" + Messages.DynamicMenuContributionEditor_ClassURI + "</A>"); //$NON-NLS-1$//$NON-NLS-2$ + lnk.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + lnk.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + c.createOpen((MContribution) getMaster().getValue(), getEditingDomain(), project, lnk.getShell()); + } + }); + } else { + Label l = new Label(parent, SWT.NONE); + l.setText(Messages.DynamicMenuContributionEditor_ClassURI); + l.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); + } + + Text t = new Text(parent, SWT.BORDER); + TextPasteHandler.createFor(t); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + t.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent e) { + lnk.setToolTipText(((Text) (e.getSource())).getText()); + } + }); + Binding binding = context.bindValue(textProp.observeDelayed(200, t), EMFEditProperties.value(getEditingDomain(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI).observeDetail(getMaster()), new UpdateValueStrategy().setAfterConvertValidator(new ContributionURIValidator()), new UpdateValueStrategy()); + Util.addDecoration(t, binding); + + final Button b = new Button(parent, SWT.PUSH | SWT.FLAT); + b.setImage(createImage(ResourceProvider.IMG_Obj16_zoom)); + b.setText(Messages.ModelTooling_Common_FindEllipsis); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + ContributionClassDialog dialog = new ContributionClassDialog(b.getShell(), project, getEditingDomain(), (MContribution) getMaster().getValue(), ApplicationPackageImpl.Literals.CONTRIBUTION__CONTRIBUTION_URI, Messages); + dialog.open(); + } + }); + } + + folder.setSelection(0); + + return folder; + } + + @Override + public IObservableList getChildList(Object element) { + return null; + } + +} diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuContributionEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuContributionEditor.java index d14fca00..f8b610fd 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuContributionEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuContributionEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 BestSolution.at and others. + * Copyright (c) 2010-2013 BestSolution.at 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 @@ -7,7 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Marco Descher <marco@descher.at> - https://bugs.eclipse.org/397650 + * Marco Descher <marco@descher.at> - Bug 397650, Bug 395982 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component; @@ -115,6 +115,12 @@ public class MenuContributionEditor extends AbstractComponentEditor { handleAdd(MenuPackageImpl.Literals.MENU_SEPARATOR, true); } }); + actions.add(new Action(Messages.MenuEditor_AddDynamicMenuContribution, createImageDescriptor(ResourceProvider.IMG_DynamicMenuContribution)) { + @Override + public void run() { + handleAdd(MenuPackageImpl.Literals.DYNAMIC_MENU_CONTRIBUTION, false); + } + }); } @Override diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java index a41adfe1..98545578 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/MenuEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 BestSolution.at and others. + * Copyright (c) 2010-2013 BestSolution.at 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 @@ -7,6 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Marco Descher <marco@descher.at> - Bug 395982 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component; @@ -150,6 +151,12 @@ public class MenuEditor extends AbstractComponentEditor { handleAdd(MenuPackageImpl.Literals.MENU_SEPARATOR, true); } }); + actions.add(new Action(Messages.MenuEditor_AddDynamicMenuContribution, createImageDescriptor(ResourceProvider.IMG_DynamicMenuContribution)) { + @Override + public void run() { + handleAdd(MenuPackageImpl.Literals.DYNAMIC_MENU_CONTRIBUTION, false); + } + }); addExpression = new Action(Messages.MenuEditor_AddCoreExpression, createImageDescriptor(ResourceProvider.IMG_CoreExpression)) { @Override public void run() { diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewDynamicMenuContributionClassWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewDynamicMenuContributionClassWizard.java new file mode 100644 index 00000000..59c8b2bc --- /dev/null +++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/NewDynamicMenuContributionClassWizard.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2013 MEDEVIT, FHV 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: + * Marco Descher <marco@descher.at> - initial API and implementation + *******************************************************************************/ +package org.eclipse.e4.internal.tools.wizards.classes; + +import java.util.Set; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.BeanProperties; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassPage; +import org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassWizard; +import org.eclipse.e4.internal.tools.wizards.classes.AbstractNewClassPage.JavaClass; +import org.eclipse.e4.internal.tools.wizards.classes.templates.DynamicMenuContributionTemplate; + +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jface.databinding.swt.IWidgetValueProperty; +import org.eclipse.jface.databinding.swt.WidgetProperties; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class NewDynamicMenuContributionClassWizard extends + AbstractNewClassWizard { + + private String initialString; + + public NewDynamicMenuContributionClassWizard(String contributionURI) { + this.initialString = contributionURI; + } + + @Override + protected String getContent() { + DynamicMenuContributionTemplate template = new DynamicMenuContributionTemplate(); + return template.generate(getDomainClass()); + } + + @Override + public void addPages() { + addPage(new AbstractNewClassPage("Classinformation", + "New Dynamic Menu Contribution", + "Create a new dynamic menu contribution class", root, ResourcesPlugin.getWorkspace().getRoot(),initialString) { + + @Override + protected JavaClass createInstance() { + return new DynamicMenuContributionClass(root); + } + + @Override + protected void createFields(Composite parent, DataBindingContext dbc) { + IWidgetValueProperty textProp = WidgetProperties + .text(SWT.Modify); + + { + Label l = new Label(parent, SWT.NONE); + l.setText("AboutToShow Method"); + + Text t = new Text(parent, SWT.BORDER); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + dbc.bindValue( + textProp.observe(t), + BeanProperties.value("aboutToShowMethodName").observe( + getClazz())); + + l = new Label(parent, SWT.NONE); + } + + { + Label l = new Label(parent, SWT.NONE); + l.setText("AboutToShow Method"); + + Text t = new Text(parent, SWT.BORDER); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + dbc.bindValue(textProp.observe(t), + BeanProperties.value("aboutToHideMethodName") + .observe(getClazz())); + dbc.bindValue( + WidgetProperties.enabled().observe(t), + BeanProperties.value("useAboutToHide").observe( + getClazz())); + + Button b = new Button(parent, SWT.CHECK); + dbc.bindValue( + WidgetProperties.selection().observe(b), + BeanProperties.value("useAboutToHide").observe( + getClazz())); + } + } + }); + } + + @Override + protected Set<String> getRequiredBundles() { + Set<String> set = super.getRequiredBundles(); + set.add("org.eclipse.e4.ui.di"); + set.add("org.eclipse.e4.ui.model.workbench"); + return set; + } + + public static class DynamicMenuContributionClass extends JavaClass { + private String aboutToShowMethodName = "aboutToShow"; + private String aboutToHideMethodName = "aboutToHide"; + private boolean useAboutToHide = false; + + public DynamicMenuContributionClass(IPackageFragmentRoot root) { + super(root); + } + + public String getAboutToShowMethodName() { + return aboutToShowMethodName; + } + + public void setAboutToShowMethodName(String executeMethodName) { + support.firePropertyChange("aboutToShowMethodName", + this.aboutToShowMethodName, + this.aboutToShowMethodName = executeMethodName); + } + + public String getAboutToHideMethodName() { + return aboutToHideMethodName; + } + + public void setAboutToHideMethodName(String canExecuteMethodName) { + support.firePropertyChange("aboutToHideMethodName", + this.aboutToHideMethodName, + this.aboutToHideMethodName = canExecuteMethodName); + } + + public boolean isUseAboutToHide() { + return useAboutToHide; + } + + public void setUseAboutToHide(boolean useAboutToHide) { + support.firePropertyChange("useAboutToHide", this.useAboutToHide, + this.useAboutToHide = useAboutToHide); + } + } + +} diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/templates/DynamicMenuContributionTemplate.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/templates/DynamicMenuContributionTemplate.java new file mode 100644 index 00000000..aa531af4 --- /dev/null +++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/classes/templates/DynamicMenuContributionTemplate.java @@ -0,0 +1,56 @@ +package org.eclipse.e4.internal.tools.wizards.classes.templates; + +import org.eclipse.e4.internal.tools.wizards.classes.NewDynamicMenuContributionClassWizard.DynamicMenuContributionClass; + +public class DynamicMenuContributionTemplate +{ + protected static String nl; + public static synchronized DynamicMenuContributionTemplate create(String lineSeparator) + { + nl = lineSeparator; + DynamicMenuContributionTemplate result = new DynamicMenuContributionTemplate(); + nl = null; + return result; + } + + public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; + protected final String TEXT_1 = " "; + protected final String TEXT_2 = NL + "package "; + protected final String TEXT_3 = ";"; + protected final String TEXT_4 = NL + NL + "import java.util.List;" + NL + "" + NL + "import org.eclipse.e4.ui.di.AboutToShow;"; + protected final String TEXT_5 = NL + "import org.eclipse.e4.ui.di.AboutToHide;"; + protected final String TEXT_6 = NL + NL + "import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;" + NL + "" + NL + "public class "; + protected final String TEXT_7 = " {" + NL + "\t@AboutToShow" + NL + "\tpublic void "; + protected final String TEXT_8 = "(List<MMenuElement> items) {" + NL + "\t\t//TODO Your code goes here" + NL + "\t}" + NL + "\t"; + protected final String TEXT_9 = NL + "\t" + NL + "\t@AboutToHide" + NL + "\tpublic void "; + protected final String TEXT_10 = "(List<MMenuElement> items) {" + NL + "\t\t//TODO Your code goes here" + NL + "\t}" + NL + "\t"; + protected final String TEXT_11 = "\t" + NL + "}"; + + public String generate(Object argument) + { + final StringBuffer stringBuffer = new StringBuffer(); + DynamicMenuContributionClass domainClass = (DynamicMenuContributionClass)argument; + stringBuffer.append(TEXT_1); + if( domainClass.getPackageFragment() != null && domainClass.getPackageFragment().getElementName().trim().length() > 0 ) { + stringBuffer.append(TEXT_2); + stringBuffer.append( domainClass.getPackageFragment().getElementName() ); + stringBuffer.append(TEXT_3); + } + stringBuffer.append(TEXT_4); + if( domainClass.isUseAboutToHide() ) { + stringBuffer.append(TEXT_5); + } + stringBuffer.append(TEXT_6); + stringBuffer.append( domainClass.getName() ); + stringBuffer.append(TEXT_7); + stringBuffer.append( domainClass.getAboutToShowMethodName() ); + stringBuffer.append(TEXT_8); + if( domainClass.isUseAboutToHide() ) { + stringBuffer.append(TEXT_9); + stringBuffer.append( domainClass.getAboutToHideMethodName() ); + stringBuffer.append(TEXT_10); + } + stringBuffer.append(TEXT_11); + return stringBuffer.toString(); + } +} diff --git a/bundles/org.eclipse.e4.tools/templates/dynamicMenuContribution.txtjet b/bundles/org.eclipse.e4.tools/templates/dynamicMenuContribution.txtjet new file mode 100644 index 00000000..832f703f --- /dev/null +++ b/bundles/org.eclipse.e4.tools/templates/dynamicMenuContribution.txtjet @@ -0,0 +1,28 @@ +<%@ jet package="org.eclipse.e4.internal.tools.wizards.classes.templates" class="DynamicMenuContributionTemplate" imports="org.eclipse.e4.internal.tools.wizards.classes.NewDynamicMenuContributionClassWizard.DynamicMenuContributionClass" %> +<% DynamicMenuContributionClass domainClass = (DynamicMenuContributionClass)argument; %> +<% if( domainClass.getPackageFragment() != null && domainClass.getPackageFragment().getElementName().trim().length() > 0 ) { %> +package <%= domainClass.getPackageFragment().getElementName() %>; +<% } %> + +import java.util.List; + +import org.eclipse.e4.ui.di.AboutToShow; +<% if( domainClass.isUseAboutToHide() ) { %> +import org.eclipse.e4.ui.di.AboutToHide; +<% } %> + +import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement; + +public class <%= domainClass.getName() %> { + @AboutToShow + public void <%= domainClass.getAboutToShowMethodName() %>(List<MMenuElement> items) { + //TODO Your code goes here + } + <% if( domainClass.isUseAboutToHide() ) { %> + + @AboutToHide + public void <%= domainClass.getAboutToHideMethodName() %>(List<MMenuElement> items) { + //TODO Your code goes here + } + <% } %> +}
\ No newline at end of file |