diff options
Diffstat (limited to 'plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org')
7 files changed, 324 insertions, 1 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java index b64bbfb2986..d053284e784 100644 --- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/DynamicNewChild.java @@ -10,6 +10,7 @@ * * CEA LIST - Initial API and implementation * Christian W. Damus (CEA) - bug 413703 + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Bug 436954 * *****************************************************************************/ package org.eclipse.papyrus.views.modelexplorer.newchild; @@ -81,7 +82,7 @@ public class DynamicNewChild extends ContributionItem { public void fill(Menu menu, int index) { EObject eObject = getSelection(); if (eObject != null) { - CreationMenuFactory creationMenuFactory = new CreationMenuFactory(editingDomain); + CreationMenuFactory creationMenuFactory = new ModelExplorerMenuFactory(editingDomain); ArrayList<Folder> folders = creationMenuRegistry.getRootFolder(); Iterator<Folder> iterFolder = folders.iterator(); while (iterFolder.hasNext()) { diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/ModelExplorerMenuFactory.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/ModelExplorerMenuFactory.java new file mode 100644 index 00000000000..d4ba25ed35d --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/ModelExplorerMenuFactory.java @@ -0,0 +1,87 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.infra.newchild.CreationMenuFactory; +import org.eclipse.papyrus.infra.widgets.util.RevealResultCommand; +import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView; +import org.eclipse.papyrus.views.modelexplorer.core.ui.pagebookview.MultiViewPageBookView; +import org.eclipse.papyrus.views.modelexplorer.newchild.preferences.NewChildPreferences; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; + +/** + * Override of creation menu factory to select created element in Model Explorer view. + * + * @author Gabriel Pascual + * + */ +public class ModelExplorerMenuFactory extends CreationMenuFactory { + + /** + * Default constructor. + * + * @param editingDomain + */ + public ModelExplorerMenuFactory(TransactionalEditingDomain editingDomain) { + super(editingDomain); + } + + /** + * @see org.eclipse.papyrus.infra.newchild.CreationMenuFactory#buildCommand(org.eclipse.emf.ecore.EReference, org.eclipse.emf.ecore.EObject, java.lang.String) + * + * @param reference + * @param container + * @param extendedType + * @return + */ + @Override + protected Command buildCommand(EReference reference, EObject container, String extendedType) { + Command buildCommand = super.buildCommand(reference, container, extendedType); + + boolean defaultSelectionPreference = Activator.getDefault().getPreferenceStore().getBoolean(NewChildPreferences.DEFAULT_SELECTION); + + if (defaultSelectionPreference) { + + IViewPart viewPart = getActiveViewPart(); + // Wrap command to select created element + buildCommand = RevealResultCommand.wrap(buildCommand, viewPart, container); + } + + return buildCommand; + } + + + /** + * Gets the active view part. + * + * @return the active view part + */ + private IViewPart getActiveViewPart() { + IViewPart activeView = null; + // Get Model Explorer view part + IViewPart modelExplorerView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ModelExplorerPageBookView.VIEW_ID); + + if (modelExplorerView instanceof MultiViewPageBookView) { + MultiViewPageBookView pageBook = (MultiViewPageBookView) modelExplorerView; + activeView = pageBook.getActiveView(); + } + + return activeView; + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/handlers/DefaultSelectionHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/handlers/DefaultSelectionHandler.java new file mode 100644 index 00000000000..1b06119ad2c --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/handlers/DefaultSelectionHandler.java @@ -0,0 +1,51 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.dialogs.PreferencesUtil; + +/** + * Handler to open default selection preference page through a menu in Model Explorer. + * + * @author Gabriel Pascual + * + */ +public class DefaultSelectionHandler extends AbstractHandler { + + /** The Constant PREFERENCES_SELECTION_PAGE_ID. */ + private static final String PREFERENCES_SELECTION_PAGE_ID = "org.eclipse.papyrus.views.modelexplorer.preferences.selection"; //$NON-NLS-1$ + + /** + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + * + * @param event + * @return + * @throws ExecutionException + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(Display.getDefault().getActiveShell(), PREFERENCES_SELECTION_PAGE_ID, null, null); + if (dialog != null) { + dialog.open(); + } + + return null; + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/messages/Messages.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/messages/Messages.java new file mode 100644 index 00000000000..5a17e9abca9 --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/messages/Messages.java @@ -0,0 +1,40 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net- Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild.messages; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Externalisation of string. + * + * @author Gabriel Pascual + * + */ +public class Messages { + private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferenceInitializer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferenceInitializer.java new file mode 100644 index 00000000000..8d6220631d0 --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferenceInitializer.java @@ -0,0 +1,47 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.papyrus.views.modelexplorer.newchild.Activator; + +/** + * Initialiser for new child preferences in Model Explorer. + * + * @author Gabriel Pascual + * + */ +public class NewChildPreferenceInitializer extends AbstractPreferenceInitializer { + + /** + * Constructor. + * + */ + public NewChildPreferenceInitializer() { + super(); + } + + /** + * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() + * + */ + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + store.setDefault(NewChildPreferences.DEFAULT_SELECTION, true); + + } + +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferencePage.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferencePage.java new file mode 100644 index 00000000000..7ca0d19571a --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferencePage.java @@ -0,0 +1,71 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.papyrus.views.modelexplorer.newchild.Activator; +import org.eclipse.papyrus.views.modelexplorer.newchild.messages.Messages; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * Preference page to define enable/disable default selection in Model Explorer. + * + * @author Gabriel Pascual + * + */ +public class NewChildPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + /** The Constant DEFAULT_SELECTION_LABEL. */ + private static final String DEFAULT_SELECTION_LABEL = Messages.getString("NewChildPreferencePage.selection.label"); //$NON-NLS-1$ + + /** The Constant PAGE_DESCRIPTION. */ + private static final String PAGE_DESCRIPTION = Messages.getString("NewChildPreferencePage.desciption"); //$NON-NLS-1$ + + /** + * Constructor. + * + */ + public NewChildPreferencePage() { + super(); + } + + /** + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + * + * @param workbench + */ + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription(PAGE_DESCRIPTION); + + } + + /** + * Creates the field editors. + * + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() + */ + @Override + protected void createFieldEditors() { + addField(new BooleanFieldEditor(NewChildPreferences.DEFAULT_SELECTION, DEFAULT_SELECTION_LABEL, getFieldEditorParent())); + + } + + + + +} diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferences.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferences.java new file mode 100644 index 00000000000..f6012323b70 --- /dev/null +++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.newchild/src/org/eclipse/papyrus/views/modelexplorer/newchild/preferences/NewChildPreferences.java @@ -0,0 +1,26 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST 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: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.views.modelexplorer.newchild.preferences; + +/** + * Preference's keys for new child behaviour of Model Explorer view. + * + * @author Gabriel Pascual + * + */ +public interface NewChildPreferences { + + /** The Constant DEFAULT_SELECTION. */ + public static final String DEFAULT_SELECTION = "defaultSelection"; //$NON-NLS-1$ +} |