summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-05-19 10:33:37 (EDT)
committerGabriel Pascual2014-05-19 10:33:37 (EDT)
commitdfdc647f45e793a2ce22db3e653483cbafc53645 (patch)
treee0c3ab448f6cb62c079257027c6fe4082b83e69c
parent8dc03ad834c57002c69ad005f0aa565f04ac67a3 (diff)
downloadorg.eclipse.papyrus-dfdc647f45e793a2ce22db3e653483cbafc53645.zip
org.eclipse.papyrus-dfdc647f45e793a2ce22db3e653483cbafc53645.tar.gz
org.eclipse.papyrus-dfdc647f45e793a2ce22db3e653483cbafc53645.tar.bz2
350134: [Palette] Can't delete local palette definitionrefs/changes/67/26867/1
https://bugs.eclipse.org/bugs/show_bug.cgi?id=350134 - Change called method for delete button - Add a button to restore default configuration for extended palette Change-Id: I1072f93e086f6e6c0eadfa3a0fbda92cd60d4273 Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java1537
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java13
3 files changed, 798 insertions, 755 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java
index 37e0ecf..6ce9f5a 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.palette/src/org/eclipse/papyrus/customization/palette/dialog/PapyrusPaletteCustomizerDialog.java
@@ -1,754 +1,783 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.customization.palette.dialog;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.gef.palette.PaletteContainer;
-import org.eclipse.gef.palette.PaletteEntry;
-import org.eclipse.gef.palette.PaletteRoot;
-import org.eclipse.gef.ui.palette.PaletteCustomizer;
-import org.eclipse.gmf.runtime.gef.ui.palette.customize.PaletteCustomizerDialogEx;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.ICheckStateProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.Messages;
-import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPaletteCustomizer;
-import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ExtendedProviderDescriptor;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.LocalProviderDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
-
-/**
- * specific dialog window for the customisation of the palette
- */
-public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx implements IPreferenceChangeListener {
-
- /** new local palette icon */
- private static final String NEW_LOCAL_DESC_IMAGE = "/icons/local_desc_new.gif";
-
- /** delete palette icon */
- private static final String DELETE_LOCAL_DESC_IMAGE = "/icons/local_desc_destroy.gif";
-
- /** edit palette icon */
- private static final String EDIT_LOCAL_DESC_IMAGE = "/icons/local_desc_edit.gif";
-
- /** path to the local descriptor icon */
- protected final String LOCAL_DESCRIPTOR = "/icons/local_desc.gif";
-
- /** path to the plugin descriptor icon */
- protected final String PLUGIN_DESCRIPTOR = "/icons/plugin_desc.gif";
-
- /** path to the plugin descriptor icon */
- protected final String EXTENDED_PLUGIN_DESCRIPTOR = "/icons/extended_plugin_desc.gif";
-
- /** viewer for the available tools */
- protected TreeViewer availableToolsTreeViewer;
-
- /** table viewed by the availablePalettesTreeViewer */
- protected Table availablePalettesTable;
-
- /** viewer for the available palettes */
- protected CheckboxTableViewer availablePalettesTableViewer;
-
- /** label provider for palette provider */
- protected PaletteLabelProvider providersLabelProvider;
-
- /** add local palette button */
- protected Button newPaletteButton;
-
- /** delete local palette button */
- protected Button deletePaletteButton;
-
- /** edit local palette button */
- protected Button editPaletteButton;
-
- /**
- * Creates a new PapyrusPaletteCustomizerDialog
- *
- * @param shell
- * the shell that hosts the dialog window
- * @param customizer
- * the customizer used to customize the palette
- * @param root
- * the root of the palette
- */
- public PapyrusPaletteCustomizerDialog(Shell shell, PaletteCustomizer customizer, PaletteRoot root) {
- super(shell, customizer, root);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int open() {
- IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.ID);
- prefs.addPreferenceChangeListener(this);
- return super.open();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean close() {
- IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.ID);
- prefs.removePreferenceChangeListener(this);
- return super.close();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- // RS: does not call super, as the composite should not be drawn like they are in parent
- Composite mainComposite = createMainComposite(parent);
-
- final Control availableToolsComposite = createAvailablePalettesViewer(mainComposite);
- FormData data = new FormData();
- data.left = new FormAttachment(0, 0);
- data.top = new FormAttachment(0, 0);
- data.bottom = new FormAttachment(100, 0);
- // data.right = new FormAttachment(40, 0);
- availableToolsComposite.setLayoutData(data);
-
- // final Control displayButtons = createDisplayButtons(mainComposite);
- // data = new FormData();
- // data.left = new FormAttachment(availableToolsComposite, 0);
- // // data.width = 30;
- // data.top = new FormAttachment(40, 0);
- // data.bottom = new FormAttachment(100, 0);
- // displayButtons.setLayoutData(data);
-
- final Label nameLabel = new Label(mainComposite, SWT.NONE);
- nameLabel.setText(Messages.Palette_Viewer);
- data = new FormData();
- data.left = new FormAttachment(availableToolsComposite, ITabbedPropertyConstants.HSPACE);
- data.top = new FormAttachment(0, 0);
- nameLabel.setLayoutData(data);
-
- // Create the tree
- Control outline = createOutline(mainComposite);
- data = new FormData();
- data.left = new FormAttachment(availableToolsComposite, ITabbedPropertyConstants.HSPACE);
- data.top = new FormAttachment(nameLabel, 0);
- data.bottom = new FormAttachment(100, 0);
- // data.right = new FormAttachment(90, 0);
- outline.setLayoutData(data);
-
- // Create the panel where the properties of the selected palette entry will
- // be shown
- Control properties = createPropertiesPanel(mainComposite);
- data = new FormData();
- data.left = new FormAttachment(outline, ITabbedPropertyConstants.HSPACE);
- data.right = new FormAttachment(100, 0);
- data.top = new FormAttachment(0, 0);
- data.bottom = new FormAttachment(100, 0);
- properties.setLayoutData(data);
-
- // add listeners
- ISelectionChangedListener listener = createSelectionChangedListener();
- if(listener != null) {
- availablePalettesTableViewer.addSelectionChangedListener(listener);
- }
- return mainComposite;
- }
-
- protected ISelectionChangedListener createSelectionChangedListener() {
- return new ISelectionChangedListener() {
-
- /**
- * {@inheritDoc}
- */
- public void selectionChanged(SelectionChangedEvent event) {
- // retrieve element selected
- Object selectedElement = ((IStructuredSelection)event.getSelection()).getFirstElement();
- if(selectedElement instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
- PapyrusPaletteService.ProviderDescriptor descriptor = (PapyrusPaletteService.ProviderDescriptor)selectedElement;
- deletePaletteButton.setEnabled(true);
- editPaletteButton.setEnabled(true);
- } else if(selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) {
- PapyrusPaletteService.LocalProviderDescriptor descriptor = (PapyrusPaletteService.LocalProviderDescriptor)selectedElement;
- deletePaletteButton.setEnabled(true);
- editPaletteButton.setEnabled(true);
- } else {
- deletePaletteButton.setEnabled(false);
- editPaletteButton.setEnabled(false);
- }
-
- // if(selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) {
- // deletePaletteButton.setEnabled(true);
- // // check if the palette is in good configuration to be edited...
- // if(PaletteUtil.areRequiredProfileApplied(getActiveSashPage(), (PapyrusPaletteService.LocalProviderDescriptor)selectedElement)) {
- // editPaletteButton.setEnabled(true);
- // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteSelected);
- // } else {
- // editPaletteButton.setEnabled(false);
- // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_MissingProfile);
- // }
- // } else {
- // deletePaletteButton.setEnabled(false);
- // editPaletteButton.setEnabled(false);
- // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteNotSelected);
- // }
- }
- };
- }
-
- protected void addEntry(MouseEvent e) {
- ISelection selection = availableToolsTreeViewer.getSelection();
- PaletteEntry entry = null;
- if(selection instanceof IStructuredSelection) {
- Object firstElement = ((IStructuredSelection)selection).getFirstElement();
- if(!(firstElement instanceof PaletteEntry)) {
- return;
- } else {
- entry = ((PaletteEntry)firstElement);
- }
- }
- // sets the active entry, to have the page useful for saving modification
- setActiveEntry(entry);
- // add entry to the selected container
- // retrieve the selection in the palette viewer
- PaletteEntry destContainer = getSelectedPaletteEntry();
- ((PapyrusPaletteCustomizer)getCustomizer()).storePaletteState(entry);
- if(destContainer instanceof PaletteContainer) {
- PaletteContainer oldParent = entry.getParent();
-
- // checks if the parent is already changed. If not, must store the standard parent (the
- // one given by the factory)
- PaletteContainer stdParent = ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().get(entry);
- if(stdParent == null) {
- ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().put(entry, entry.getParent());
- }
- oldParent.remove(entry);
- entry.setParent((PaletteContainer)destContainer);
- ((PaletteContainer)destContainer).add(entry);
- } else {
- // add it to the palette root
- PaletteRoot root = (PaletteRoot)PaletteUtil.getRoot(entry);
- if(root != null) {
- PaletteContainer oldParent = entry.getParent();
- PaletteContainer stdParent = ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().get(entry);
- if(stdParent == null) {
- ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().put(entry, stdParent);
- }
- oldParent.remove(entry);
- entry.setParent(root);
- root.add(entry);
- }
- }
- }
-
- /**
- * Creates the available palettes viewer part of the dialog.
- *
- * @param container
- * The Composite within which the viewer has to be created
- * @return The newly created Control that has the viewer
- */
- protected Control createAvailablePalettesViewer(Composite container) {
- // Create the Composite that will contain the available tools
- Composite composite = new Composite(container, SWT.NONE);
- composite.setFont(container.getFont());
- GridLayout layout = new GridLayout(4, false);
- layout.horizontalSpacing = 0;
- layout.verticalSpacing = 0;
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- composite.setLayout(layout);
-
- final Label nameLabel = new Label(composite, SWT.NONE);
- nameLabel.setText(Messages.Available_Palettes);
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
- nameLabel.setLayoutData(data);
-
- newPaletteButton = new Button(composite, SWT.NONE);
- newPaletteButton.setImage(Activator.getImage(NEW_LOCAL_DESC_IMAGE));
- newPaletteButton.setToolTipText(Messages.Dialog_Create_Palette_Tooltip);
- newPaletteButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- createNewLocalPalette();
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
- data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
- newPaletteButton.setLayoutData(data);
-
- editPaletteButton = new Button(composite, SWT.NONE);
- editPaletteButton.setImage(Activator.getImage(EDIT_LOCAL_DESC_IMAGE));
- editPaletteButton.setToolTipText(Messages.Dialog_Edit_Palette_Tooltip);
- editPaletteButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- if(availablePalettesTableViewer == null) {
- return;
- }
-
- IStructuredSelection selection = (IStructuredSelection)availablePalettesTableViewer.getSelection();
- if(selection != null) {
- if((selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) {
- editLocalPalette((PapyrusPaletteService.LocalProviderDescriptor)selection.getFirstElement());
- } else if(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
- editExtendedPalette((PapyrusPaletteService.ExtendedProviderDescriptor)selection.getFirstElement());
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
- data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
- editPaletteButton.setLayoutData(data);
- editPaletteButton.setEnabled(false);
-
- deletePaletteButton = new Button(composite, SWT.NONE);
- deletePaletteButton.setImage(Activator.getImage(DELETE_LOCAL_DESC_IMAGE));
- deletePaletteButton.setToolTipText(Messages.Dialog_Delete_Palette_Tooltip);
- deletePaletteButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- restoreExtendedPaletteToDefault();
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
- data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
- deletePaletteButton.setLayoutData(data);
- deletePaletteButton.setEnabled(false);
-
- availablePalettesTable = new Table(composite, SWT.BORDER | SWT.CHECK);
- availablePalettesTable.setFont(composite.getFont());
- availablePalettesTable.addSelectionListener(new SelectionListener() {
-
- /**
- * {@inheritDoc}
- */
- public void widgetSelected(SelectionEvent e) {
- if(e.detail == SWT.CHECK) {
- TableItem item = (TableItem)e.item;
- // one item was checked => display/hide the given provider
- changeProviderVisibility((PapyrusPaletteService.ProviderDescriptor)item.getData(), item.getChecked());
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- // does nothing
- }
- });
- data = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL);
- data.horizontalSpan = 4;
- data.widthHint = 185;
- // Make the tree this tall even when there is nothing in it. This will keep the
- // dialog from shrinking to an unusually small size.
- data.heightHint = 200;
- availablePalettesTable.setLayoutData(data);
- availablePalettesTableViewer = new CheckboxTableViewer(availablePalettesTable);
- AvailablePalettesCheckStateProvider availablePalettesCheckStateProvider = new AvailablePalettesCheckStateProvider();
- availablePalettesTableViewer.setCheckStateProvider(availablePalettesCheckStateProvider);
- availablePalettesTableViewer.setContentProvider(new PalettesTableContentProvider(availablePalettesTableViewer));
- providersLabelProvider = new PaletteLabelProvider(availablePalettesTableViewer);
- availablePalettesTableViewer.setLabelProvider(providersLabelProvider);
- availablePalettesTableViewer.setInput(PapyrusPaletteService.getInstance());
- availablePalettesTableViewer.addDoubleClickListener(new IDoubleClickListener() {
-
- public void doubleClick(DoubleClickEvent event) {
- // get selection. if local palette: open the wizard to edit this local palette
- IStructuredSelection selection = (IStructuredSelection)event.getSelection();
- if(selection.getFirstElement() instanceof LocalProviderDescriptor) {
- editLocalPalette((PapyrusPaletteService.LocalProviderDescriptor)selection.getFirstElement());
- } else if(selection.getFirstElement() instanceof ExtendedProviderDescriptor) {
- editExtendedPalette((PapyrusPaletteService.ExtendedProviderDescriptor)selection.getFirstElement());
- }
- }
- });
-
- return composite;
- }
-
- /**
- * Launch the wizard for the palette creation
- *
- * @param shell
- * the shell where to display the wizard
- */
- protected void createNewLocalPalette() {
- NewLocalPaletteWizard wizard = new NewLocalPaletteWizard(getActiveSashPage(), getCustomizer());
- WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
- wizardDialog.open();
- }
-
- /**
- * Deletes the current selected local palette
- */
- protected void deleteLocalPalette() {
- IStructuredSelection selection = (IStructuredSelection)availablePalettesTableViewer.getSelection();
- if(selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) {
- MessageDialog.openError(getShell(), Messages.Dialog_Not_Local_Palette_Title, Messages.Dialog_Not_Local_Palette_Message);
- } else {
- PapyrusPaletteService.LocalProviderDescriptor descriptor = ((PapyrusPaletteService.LocalProviderDescriptor)selection.getFirstElement());
- String id = descriptor.getContributionID();
- PapyrusPalettePreferences.deleteLocalPalette(id);
- }
- }
-
- /**
- * Reset the current selected extended palette to the initial configurtion in the plugin
- */
- protected void restoreExtendedPaletteToDefault() {
- IStructuredSelection selection = (IStructuredSelection)availablePalettesTableViewer.getSelection();
- if(selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor)) {
- MessageDialog.openError(getShell(), Messages.Dialog_Not_Local_Palette_Title, Messages.Dialog_Not_Local_Palette_Message);
- } else {
- PapyrusPaletteService.ExtendedProviderDescriptor descriptor = ((PapyrusPaletteService.ExtendedProviderDescriptor)selection.getFirstElement());
- String id = descriptor.getContributionID();
- PapyrusPalettePreferences.unregisterLocalRedefinition(id);
- }
- }
-
- /**
- * Edits the current selected local palette
- */
- protected void editLocalPalette(PapyrusPaletteService.LocalProviderDescriptor descriptor) {
- UpdateLocalPaletteWizard wizard = new UpdateLocalPaletteWizard(getActiveSashPage(), descriptor, getCustomizer());
- WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
- wizardDialog.open();
- }
-
- /**
- * @param firstElement
- */
- protected void editExtendedPalette(ExtendedProviderDescriptor descriptor) {
- // check the file in plugin state area.
- String contributionID = descriptor.getContributionID();
- String paletteRedefinition = PapyrusPalettePreferences.getPaletteRedefinition(contributionID);
-
- if(paletteRedefinition == null) {
- // create a local redefinition of this palette contribution
- PapyrusPalettePreferences.createPaletteRedefinition(descriptor);
- }
-
-
- UpdateExtendedPaletteWizard wizard = new UpdateExtendedPaletteWizard(getActiveSashPage(), descriptor, getCustomizer());
- WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
- wizardDialog.open();
- }
-
-
- /**
- * Changes the visibility of the given provider
- *
- * @param descriptor
- * the provider to hide/show
- * @param isChecked
- * <code>true</code> if the descriptor should be visible
- */
- protected void changeProviderVisibility(PapyrusPaletteService.ProviderDescriptor descriptor, boolean isChecked) {
- PapyrusPalettePreferences.changePaletteVisibility(descriptor.getContributionID(), getActiveSashPage().getClass().getName(), isChecked);
- }
-
- /**
- * Creates the main composite for the dialog area
- *
- * @param parent
- * the parent of the createrd composite
- * @return the newly created Composite
- */
- protected Composite createMainComposite(Composite parent) {
- // dialog window
- // create a composite with standard margins and spacing
- Composite composite = new Composite(parent, SWT.NONE);
- FormLayout layout = new FormLayout();
- layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
- applyDialogFont(composite);
- return composite;
- }
-
- /**
- * Content provider for available tools viewer
- */
- public class PalettesTableContentProvider implements IStructuredContentProvider {
-
- /** the palette root */
- private PapyrusPaletteService paletteService;
-
- /** tree viewer to fill */
- private final TableViewer viewer;
-
- /**
- * Constructor
- *
- * @param tableViewer
- * The TableViewer whose ContentProvider this PaletteTreeProvider is
- */
- public PalettesTableContentProvider(TableViewer tableViewer) {
- this.viewer = tableViewer;
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- paletteService = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if(newInput != null) {
- paletteService = (PapyrusPaletteService)newInput;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof PapyrusPaletteService) {
- List<PapyrusPaletteService.ProviderDescriptor> providers = ((PapyrusPaletteService)inputElement).getContributingProviders(getActiveSashPage(), getPaletteRoot());
-
- return providers.toArray();
- }
- return null;
- }
- }
-
- /**
- * Returns the current active sash page
- *
- * @return the current active sash page
- */
- protected IEditorPart getActiveSashPage() {
- // Lookup ServiceRegistry
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IEditorPart editorPart = page.getActiveEditor();
- assert editorPart != null;
- ISashWindowsContainer sashWindowsContainer = (ISashWindowsContainer)editorPart.getAdapter(ISashWindowsContainer.class);
- if(sashWindowsContainer != null) {
- return sashWindowsContainer.getActiveEditor();
- }
- return null;
- }
-
- /**
- * provider in charge of the check boxes in the available palettes table viewer
- */
- protected class AvailablePalettesCheckStateProvider implements ICheckStateProvider {
-
- /**
- * {@inheritDoc}
- */
- public boolean isChecked(Object element) {
- if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
- return !PapyrusPalettePreferences.getHiddenPalettes(getActiveSashPage()).contains(((PapyrusPaletteService.ProviderDescriptor)element).getContributionID());
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isGrayed(Object element) {
- return false;
- }
-
- }
-
- /**
- * Label provider for available tools viewer
- */
- protected class PaletteLabelProvider implements ILabelProvider {
-
- /**
- * Creates a new PaletteLabelProvider.
- *
- * @param viewer
- * the table viewer where the labels are displayed
- */
- public PaletteLabelProvider(TableViewer viewer) {
- }
-
- private Map<ImageDescriptor, Image> imageCache = new HashMap<ImageDescriptor, Image>();
-
- /**
- * {@inheritDoc}
- */
- public Image getImage(Object element) {
- if(element instanceof PapyrusPaletteService.LocalProviderDescriptor) {
- return Activator.getImage(LOCAL_DESCRIPTOR);
- } else if(element instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
- // icon should be decorated if it is already defined in a local way or not.
- return Activator.getImage(EXTENDED_PLUGIN_DESCRIPTOR);
- } else if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
- return Activator.getImage(PLUGIN_DESCRIPTOR);
- }
- return Activator.getImage(Activator.DEFAULT_IMAGE);
- }
-
- /**
- * {@inheritDoc}
- */
- public String getText(Object element) {
- if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
- return ((PapyrusPaletteService.ProviderDescriptor)element).getContributionName();
- }
- return "<undefined>";
- }
-
- /**
- * {@inheritDoc}
- */
- public void addListener(ILabelProviderListener listener) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
- Iterator<Image> images = imageCache.values().iterator();
- while(images.hasNext()) {
- images.next().dispose();
- }
- imageCache = null;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeListener(ILabelProviderListener listener) {
- }
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void preferenceChange(PreferenceChangeEvent event) {
- String id = event.getKey();
- if(PapyrusPalettePreferences.PALETTE_CUSTOMIZATIONS_ID.equals(id) || PapyrusPalettePreferences.PALETTE_LOCAL_DEFINITIONS.equals(id)) {
- // refresh available palette table viewer
- availablePalettesTableViewer.setInput(PapyrusPaletteService.getInstance());
- }
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@gmail.com - Bug 350134
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.customization.palette.dialog;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.gef.palette.PaletteContainer;
+import org.eclipse.gef.palette.PaletteEntry;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.ui.palette.PaletteCustomizer;
+import org.eclipse.gmf.runtime.gef.ui.palette.customize.PaletteCustomizerDialogEx;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.Messages;
+import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPaletteCustomizer;
+import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
+import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
+import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ExtendedProviderDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
+
+/**
+ * Specific dialog window for the customisation of the palette.
+ */
+public class PapyrusPaletteCustomizerDialog extends PaletteCustomizerDialogEx implements IPreferenceChangeListener {
+
+ /** Id for restore button of extended customization palette. */
+ private static final int RESTORE_DEFAULT_PALETTE_BUTTON_ID = 23;
+
+ /** Id for delete button of local palette. */
+ private static final int DELETE_PALETTE_BUTTON_ID = 22;
+
+ /** Id for edit button of extended and local palette. */
+ private static final int EDIT_PALETTE_BUTTON_ID = 21;
+
+ /** Id for new button to create local palette. */
+ private static final int NEW_LOCAL_PALETTE_BUTTON_ID = 20;
+
+ /** new local palette icon */
+ private static final String NEW_LOCAL_DESC_IMAGE = "/icons/local_desc_new.gif";
+
+ /** delete palette icon */
+ private static final String DELETE_LOCAL_DESC_IMAGE = "/icons/local_desc_destroy.gif";
+
+ /** edit palette icon */
+ private static final String EDIT_LOCAL_DESC_IMAGE = "/icons/local_desc_edit.gif";
+
+ private static final String RESTORE_DEFAULT_DESC_IMAGE = "/icons/obj16/eraser.gif";
+
+ /** path to the local descriptor icon */
+ protected final String LOCAL_DESCRIPTOR = "/icons/local_desc.gif";
+
+ /** path to the plugin descriptor icon */
+ protected final String PLUGIN_DESCRIPTOR = "/icons/plugin_desc.gif";
+
+ /** path to the plugin descriptor icon */
+ protected final String EXTENDED_PLUGIN_DESCRIPTOR = "/icons/extended_plugin_desc.gif";
+
+ /** viewer for the available tools */
+ protected TreeViewer availableToolsTreeViewer;
+
+ /** table viewed by the availablePalettesTreeViewer */
+ protected Table availablePalettesTable;
+
+ /** viewer for the available palettes */
+ protected CheckboxTableViewer availablePalettesTableViewer;
+
+ /** label provider for palette provider */
+ protected PaletteLabelProvider providersLabelProvider;
+
+ private Map<Integer, Button> paletteButtonsMap = new HashMap<Integer, Button>();
+
+ /**
+ * Creates a new PapyrusPaletteCustomizerDialog
+ *
+ * @param shell
+ * the shell that hosts the dialog window
+ * @param customizer
+ * the customizer used to customize the palette
+ * @param root
+ * the root of the palette
+ */
+ public PapyrusPaletteCustomizerDialog(Shell shell, PaletteCustomizer customizer, PaletteRoot root) {
+ super(shell, customizer, root);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int open() {
+ IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.ID);
+ prefs.addPreferenceChangeListener(this);
+ return super.open();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean close() {
+ IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.ID);
+ prefs.removePreferenceChangeListener(this);
+ return super.close();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // RS: does not call super, as the composite should not be drawn like they are in parent
+ Composite mainComposite = createMainComposite(parent);
+
+ final Control availableToolsComposite = createAvailablePalettesViewer(mainComposite);
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 0);
+ data.bottom = new FormAttachment(100, 0);
+ // data.right = new FormAttachment(40, 0);
+ availableToolsComposite.setLayoutData(data);
+
+ // final Control displayButtons = createDisplayButtons(mainComposite);
+ // data = new FormData();
+ // data.left = new FormAttachment(availableToolsComposite, 0);
+ // // data.width = 30;
+ // data.top = new FormAttachment(40, 0);
+ // data.bottom = new FormAttachment(100, 0);
+ // displayButtons.setLayoutData(data);
+
+ final Label nameLabel = new Label(mainComposite, SWT.NONE);
+ nameLabel.setText(Messages.Palette_Viewer);
+ data = new FormData();
+ data.left = new FormAttachment(availableToolsComposite, ITabbedPropertyConstants.HSPACE);
+ data.top = new FormAttachment(0, 0);
+ nameLabel.setLayoutData(data);
+
+ // Create the tree
+ Control outline = createOutline(mainComposite);
+ data = new FormData();
+ data.left = new FormAttachment(availableToolsComposite, ITabbedPropertyConstants.HSPACE);
+ data.top = new FormAttachment(nameLabel, 0);
+ data.bottom = new FormAttachment(100, 0);
+ // data.right = new FormAttachment(90, 0);
+ outline.setLayoutData(data);
+
+ // Create the panel where the properties of the selected palette entry will
+ // be shown
+ Control properties = createPropertiesPanel(mainComposite);
+ data = new FormData();
+ data.left = new FormAttachment(outline, ITabbedPropertyConstants.HSPACE);
+ data.right = new FormAttachment(100, 0);
+ data.top = new FormAttachment(0, 0);
+ data.bottom = new FormAttachment(100, 0);
+ properties.setLayoutData(data);
+
+ // add listeners
+ ISelectionChangedListener listener = createSelectionChangedListener();
+ if(listener != null) {
+ availablePalettesTableViewer.addSelectionChangedListener(listener);
+ }
+ return mainComposite;
+ }
+
+ protected ISelectionChangedListener createSelectionChangedListener() {
+ return new ISelectionChangedListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ // retrieve element selected
+ Object selectedElement = ((IStructuredSelection)event.getSelection()).getFirstElement();
+
+ if(selectedElement instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
+ paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false);
+ paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(true);
+ paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(true);
+ } else if(selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) {
+ paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(true);
+ paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(true);
+ paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false);
+ } else {
+ paletteButtonsMap.get(DELETE_PALETTE_BUTTON_ID).setEnabled(false);
+ paletteButtonsMap.get(EDIT_PALETTE_BUTTON_ID).setEnabled(false);
+ paletteButtonsMap.get(RESTORE_DEFAULT_PALETTE_BUTTON_ID).setEnabled(false);
+ }
+
+ // if(selectedElement instanceof PapyrusPaletteService.LocalProviderDescriptor) {
+ // deletePaletteButton.setEnabled(true);
+ // // check if the palette is in good configuration to be edited...
+ // if(PaletteUtil.areRequiredProfileApplied(getActiveSashPage(), (PapyrusPaletteService.LocalProviderDescriptor)selectedElement)) {
+ // editPaletteButton.setEnabled(true);
+ // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteSelected);
+ // } else {
+ // editPaletteButton.setEnabled(false);
+ // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_MissingProfile);
+ // }
+ // } else {
+ // deletePaletteButton.setEnabled(false);
+ // editPaletteButton.setEnabled(false);
+ // editPaletteButton.setToolTipText(Messages.PapyrusPaletteCustomizerDialog_EditButtonTooltip_LocalPaletteNotSelected);
+ // }
+ }
+ };
+ }
+
+ protected void addEntry(MouseEvent e) {
+ ISelection selection = availableToolsTreeViewer.getSelection();
+ PaletteEntry entry = null;
+ if(selection instanceof IStructuredSelection) {
+ Object firstElement = ((IStructuredSelection)selection).getFirstElement();
+ if(!(firstElement instanceof PaletteEntry)) {
+ return;
+ } else {
+ entry = ((PaletteEntry)firstElement);
+ }
+ }
+ // sets the active entry, to have the page useful for saving modification
+ setActiveEntry(entry);
+ // add entry to the selected container
+ // retrieve the selection in the palette viewer
+ PaletteEntry destContainer = getSelectedPaletteEntry();
+ ((PapyrusPaletteCustomizer)getCustomizer()).storePaletteState(entry);
+ if(destContainer instanceof PaletteContainer) {
+ PaletteContainer oldParent = entry.getParent();
+
+ // checks if the parent is already changed. If not, must store the standard parent (the
+ // one given by the factory)
+ PaletteContainer stdParent = ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().get(entry);
+ if(stdParent == null) {
+ ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().put(entry, entry.getParent());
+ }
+ oldParent.remove(entry);
+ entry.setParent((PaletteContainer)destContainer);
+ ((PaletteContainer)destContainer).add(entry);
+ } else {
+ // add it to the palette root
+ PaletteRoot root = (PaletteRoot)PaletteUtil.getRoot(entry);
+ if(root != null) {
+ PaletteContainer oldParent = entry.getParent();
+ PaletteContainer stdParent = ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().get(entry);
+ if(stdParent == null) {
+ ((PapyrusPaletteCustomizer)getCustomizer()).getChangedParents().put(entry, stdParent);
+ }
+ oldParent.remove(entry);
+ entry.setParent(root);
+ root.add(entry);
+ }
+ }
+ }
+
+ /**
+ * Creates the available palettes viewer part of the dialog.
+ *
+ * @param container
+ * The Composite within which the viewer has to be created
+ * @return The newly created Control that has the viewer
+ */
+ protected Control createAvailablePalettesViewer(Composite container) {
+ // Create the Composite that will contain the available tools
+ Composite composite = new Composite(container, SWT.NONE);
+ composite.setFont(container.getFont());
+ GridLayout layout = new GridLayout(5, false);
+ layout.horizontalSpacing = 0;
+ layout.verticalSpacing = 0;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ composite.setLayout(layout);
+
+ final Label nameLabel = new Label(composite, SWT.NONE);
+ nameLabel.setText(Messages.Available_Palettes);
+ GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ nameLabel.setLayoutData(data);
+
+ // Create action buttons
+ createEditionPaletteButton(composite, NEW_LOCAL_PALETTE_BUTTON_ID, Activator.getImage(NEW_LOCAL_DESC_IMAGE), Messages.Dialog_Create_Palette_Tooltip);
+ createEditionPaletteButton(composite, EDIT_PALETTE_BUTTON_ID, Activator.getImage(EDIT_LOCAL_DESC_IMAGE), Messages.Dialog_Edit_Palette_Tooltip);
+ createEditionPaletteButton(composite, DELETE_PALETTE_BUTTON_ID, Activator.getImage(DELETE_LOCAL_DESC_IMAGE), Messages.Dialog_Delete_Palette_Tooltip);
+ createEditionPaletteButton(composite, RESTORE_DEFAULT_PALETTE_BUTTON_ID, Activator.getImage(RESTORE_DEFAULT_DESC_IMAGE), Messages.Dialog_Restore_Palette_Tooltip);
+
+ availablePalettesTable = new Table(composite, SWT.BORDER | SWT.CHECK);
+ availablePalettesTable.setFont(composite.getFont());
+ availablePalettesTable.addSelectionListener(new SelectionListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void widgetSelected(SelectionEvent e) {
+ if(e.detail == SWT.CHECK) {
+ TableItem item = (TableItem)e.item;
+ // one item was checked => display/hide the given provider
+ changeProviderVisibility((PapyrusPaletteService.ProviderDescriptor)item.getData(), item.getChecked());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // does nothing
+ }
+ });
+ data = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL);
+ data.horizontalSpan = 5;
+ data.widthHint = 185;
+ // Make the tree this tall even when there is nothing in it. This will keep the
+ // dialog from shrinking to an unusually small size.
+ data.heightHint = 200;
+ availablePalettesTable.setLayoutData(data);
+ availablePalettesTableViewer = new CheckboxTableViewer(availablePalettesTable);
+ AvailablePalettesCheckStateProvider availablePalettesCheckStateProvider = new AvailablePalettesCheckStateProvider();
+ availablePalettesTableViewer.setCheckStateProvider(availablePalettesCheckStateProvider);
+ availablePalettesTableViewer.setContentProvider(new PalettesTableContentProvider(availablePalettesTableViewer));
+ providersLabelProvider = new PaletteLabelProvider(availablePalettesTableViewer);
+ availablePalettesTableViewer.setLabelProvider(providersLabelProvider);
+ availablePalettesTableViewer.setInput(PapyrusPaletteService.getInstance());
+ availablePalettesTableViewer.addDoubleClickListener(new IDoubleClickListener() {
+
+ public void doubleClick(DoubleClickEvent event) {
+ // get selection. if local palette: open the wizard to edit this local palette
+ IStructuredSelection selection = (IStructuredSelection)event.getSelection();
+ editSelectedPalette(selection);
+ }
+ });
+
+ return composite;
+ }
+
+ /**
+ * Create button to edit palette in table.
+ *
+ * @param parentConposite
+ * @return
+ */
+ protected Button createEditionPaletteButton(Composite parentConposite, int id, Image icon, String toolTip) {
+ Button button = new Button(parentConposite, SWT.NONE);
+ button.setData(new Integer(id));
+ button.setImage(icon);
+ button.setToolTipText(toolTip);
+ button.addMouseListener(new MouseListener() {
+
+ public void mouseDoubleClick(MouseEvent e) {
+ // Nothing to do
+
+ }
+
+ public void mouseDown(MouseEvent e) {
+ // Nothing to do
+
+ }
+
+ public void mouseUp(MouseEvent e) {
+ buttonPressed(((Integer)e.widget.getData()).intValue());
+
+ }
+
+ });
+
+ // Register created button
+ paletteButtonsMap.put(new Integer(id), button);
+
+ return button;
+ }
+
+ /**
+ * @see org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog#buttonPressed(int)
+ *
+ * @param buttonId
+ */
+ @Override
+ protected void buttonPressed(int buttonId) {
+ if(paletteButtonsMap.containsKey(buttonId)) {
+
+ switch(buttonId) {
+ case NEW_LOCAL_PALETTE_BUTTON_ID:
+ createNewLocalPalette();
+ break;
+ case EDIT_PALETTE_BUTTON_ID:
+ IStructuredSelection selection = getPalettesTableSelection();
+ editSelectedPalette(selection);
+ break;
+ case DELETE_PALETTE_BUTTON_ID:
+ deleteLocalPalette();
+ break;
+ case RESTORE_DEFAULT_PALETTE_BUTTON_ID:
+ restoreExtendedPaletteToDefault();
+ break;
+ default:
+ break;
+ }
+ } else {
+ super.buttonPressed(buttonId);
+ }
+ }
+
+ /**
+ * Get selection in palettes table viewer.
+ *
+ * @return The {@link IStructuredSelection} if there is one, otherwise <code>null</code>
+ */
+ private IStructuredSelection getPalettesTableSelection() {
+ IStructuredSelection structuredSelection = null;
+ if(availablePalettesTableViewer != null) {
+ ISelection selection = availablePalettesTableViewer.getSelection();
+ if(selection instanceof IStructuredSelection) {
+ structuredSelection = (IStructuredSelection)selection;
+ }
+ }
+
+
+ return structuredSelection;
+ }
+
+ /**
+ * @see org.eclipse.jface.dialogs.Dialog#setButtonLayoutData(org.eclipse.swt.widgets.Button)
+ *
+ * @param button
+ */
+ @Override
+ protected void setButtonLayoutData(Button button) {
+ if(paletteButtonsMap.containsValue(button)) {
+ GridData data = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+ button.setLayoutData(data);
+ button.setEnabled(false);
+ } else {
+ super.setButtonLayoutData(button);
+ }
+ }
+
+ /**
+ * Launch the wizard for the palette creation
+ *
+ * @param shell
+ * the shell where to display the wizard
+ */
+ protected void createNewLocalPalette() {
+ NewLocalPaletteWizard wizard = new NewLocalPaletteWizard(getActiveSashPage(), getCustomizer());
+ WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
+ wizardDialog.open();
+ }
+
+ /**
+ * Deletes the current selected local palette
+ */
+ protected void deleteLocalPalette() {
+ IStructuredSelection selection = (IStructuredSelection)availablePalettesTableViewer.getSelection();
+ if(selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) {
+ MessageDialog.openError(getShell(), Messages.Dialog_Not_Local_Palette_Title, Messages.Dialog_Not_Local_Palette_Message);
+ } else {
+ PapyrusPaletteService.LocalProviderDescriptor descriptor = ((PapyrusPaletteService.LocalProviderDescriptor)selection.getFirstElement());
+ String id = descriptor.getContributionID();
+ PapyrusPalettePreferences.deleteLocalPalette(id);
+ }
+ }
+
+ /**
+ * Reset the current selected extended palette to the initial configurtion in the plugin
+ */
+ protected void restoreExtendedPaletteToDefault() {
+ IStructuredSelection selection = (IStructuredSelection)availablePalettesTableViewer.getSelection();
+ if(selection == null || !(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor)) {
+ MessageDialog.openError(getShell(), Messages.Dialog_Not_Extended_Palette_Title, Messages.Dialog_Not_Extended_Palette_Message);
+ } else {
+ PapyrusPaletteService.ExtendedProviderDescriptor descriptor = ((PapyrusPaletteService.ExtendedProviderDescriptor)selection.getFirstElement());
+ String id = descriptor.getContributionID();
+ PapyrusPalettePreferences.unregisterLocalRedefinition(id);
+ }
+ }
+
+ /**
+ * Method to launch edition dialog according to selection.
+ *
+ * @param selection
+ * Selection which determine kind of edition
+ */
+ protected void editSelectedPalette(IStructuredSelection selection) {
+ if(selection != null) {
+ if((selection.getFirstElement() instanceof PapyrusPaletteService.LocalProviderDescriptor)) {
+ editLocalPalette((PapyrusPaletteService.LocalProviderDescriptor)selection.getFirstElement());
+ } else if(selection.getFirstElement() instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
+ editExtendedPalette((PapyrusPaletteService.ExtendedProviderDescriptor)selection.getFirstElement());
+ }
+ }
+
+ }
+
+ /**
+ * Edits the current selected local palette
+ */
+ protected void editLocalPalette(PapyrusPaletteService.LocalProviderDescriptor descriptor) {
+ UpdateLocalPaletteWizard wizard = new UpdateLocalPaletteWizard(getActiveSashPage(), descriptor, getCustomizer());
+ WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
+ wizardDialog.open();
+ }
+
+ /**
+ * @param firstElement
+ */
+ protected void editExtendedPalette(ExtendedProviderDescriptor descriptor) {
+ // check the file in plugin state area.
+ String contributionID = descriptor.getContributionID();
+ String paletteRedefinition = PapyrusPalettePreferences.getPaletteRedefinition(contributionID);
+
+ if(paletteRedefinition == null) {
+ // create a local redefinition of this palette contribution
+ PapyrusPalettePreferences.createPaletteRedefinition(descriptor);
+ }
+
+
+ UpdateExtendedPaletteWizard wizard = new UpdateExtendedPaletteWizard(getActiveSashPage(), descriptor, getCustomizer());
+ WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
+ wizardDialog.open();
+ }
+
+
+ /**
+ * Changes the visibility of the given provider
+ *
+ * @param descriptor
+ * the provider to hide/show
+ * @param isChecked
+ * <code>true</code> if the descriptor should be visible
+ */
+ protected void changeProviderVisibility(PapyrusPaletteService.ProviderDescriptor descriptor, boolean isChecked) {
+ PapyrusPalettePreferences.changePaletteVisibility(descriptor.getContributionID(), getActiveSashPage().getClass().getName(), isChecked);
+ }
+
+ /**
+ * Creates the main composite for the dialog area
+ *
+ * @param parent
+ * the parent of the createrd composite
+ * @return the newly created Composite
+ */
+ protected Composite createMainComposite(Composite parent) {
+ // dialog window
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parent, SWT.NONE);
+ FormLayout layout = new FormLayout();
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ /**
+ * Content provider for available tools viewer
+ */
+ public class PalettesTableContentProvider implements IStructuredContentProvider {
+
+ /** the palette root */
+ private PapyrusPaletteService paletteService;
+
+ /** tree viewer to fill */
+ private final TableViewer viewer;
+
+ /**
+ * Constructor
+ *
+ * @param tableViewer
+ * The TableViewer whose ContentProvider this PaletteTreeProvider is
+ */
+ public PalettesTableContentProvider(TableViewer tableViewer) {
+ this.viewer = tableViewer;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose() {
+ paletteService = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if(newInput != null) {
+ paletteService = (PapyrusPaletteService)newInput;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof PapyrusPaletteService) {
+ List<PapyrusPaletteService.ProviderDescriptor> providers = ((PapyrusPaletteService)inputElement).getContributingProviders(getActiveSashPage(), getPaletteRoot());
+
+ return providers.toArray();
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Returns the current active sash page
+ *
+ * @return the current active sash page
+ */
+ protected IEditorPart getActiveSashPage() {
+ // Lookup ServiceRegistry
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorPart editorPart = page.getActiveEditor();
+ assert editorPart != null;
+ ISashWindowsContainer sashWindowsContainer = (ISashWindowsContainer)editorPart.getAdapter(ISashWindowsContainer.class);
+ if(sashWindowsContainer != null) {
+ return sashWindowsContainer.getActiveEditor();
+ }
+ return null;
+ }
+
+ /**
+ * provider in charge of the check boxes in the available palettes table viewer
+ */
+ protected class AvailablePalettesCheckStateProvider implements ICheckStateProvider {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isChecked(Object element) {
+ if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
+ return !PapyrusPalettePreferences.getHiddenPalettes(getActiveSashPage()).contains(((PapyrusPaletteService.ProviderDescriptor)element).getContributionID());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isGrayed(Object element) {
+ return false;
+ }
+
+ }
+
+ /**
+ * Label provider for available tools viewer
+ */
+ protected class PaletteLabelProvider implements ILabelProvider {
+
+ /**
+ * Creates a new PaletteLabelProvider.
+ *
+ * @param viewer
+ * the table viewer where the labels are displayed
+ */
+ public PaletteLabelProvider(TableViewer viewer) {
+ }
+
+ private Map<ImageDescriptor, Image> imageCache = new HashMap<ImageDescriptor, Image>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public Image getImage(Object element) {
+ if(element instanceof PapyrusPaletteService.LocalProviderDescriptor) {
+ return Activator.getImage(LOCAL_DESCRIPTOR);
+ } else if(element instanceof PapyrusPaletteService.ExtendedProviderDescriptor) {
+ // icon should be decorated if it is already defined in a local way or not.
+ return Activator.getImage(EXTENDED_PLUGIN_DESCRIPTOR);
+ } else if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
+ return Activator.getImage(PLUGIN_DESCRIPTOR);
+ }
+ return Activator.getImage(Activator.DEFAULT_IMAGE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText(Object element) {
+ if(element instanceof PapyrusPaletteService.ProviderDescriptor) {
+ return ((PapyrusPaletteService.ProviderDescriptor)element).getContributionName();
+ }
+ return "<undefined>";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose() {
+ Iterator<Image> images = imageCache.values().iterator();
+ while(images.hasNext()) {
+ images.next().dispose();
+ }
+ imageCache = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+ String id = event.getKey();
+ if(PapyrusPalettePreferences.PALETTE_CUSTOMIZATIONS_ID.equals(id) || PapyrusPalettePreferences.PALETTE_LOCAL_DEFINITIONS.equals(id)) {
+ // refresh available palette table viewer
+ availablePalettesTableViewer.setInput(PapyrusPaletteService.getInstance());
+ }
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties
index 0c99979..39a8a5f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/messages.properties
@@ -90,9 +90,12 @@ Aspect_Action_Information_List_Label=Aspect Actions:
Dialog_Not_Local_Palette_Title=Bad selection (no item or bad item)
Dialog_Not_Local_Palette_Message=Please select a local palette to be deleted.
+Dialog_Not_Extended_Palette_Title=Bad selection (no item or bad item)
+Dialog_Not_Extended_Palette_Message=Please select an extended palette to be restored.
Dialog_Delete_Palette_Tooltip=Delete selected local palette definition
Dialog_Create_Palette_Tooltip=Create a new local palette
Dialog_Edit_Palette_Tooltip=Edit selected palette
+Dialog_Restore_Palette_Tooltip=Restore default values of selected palette
Local_Palette_Create_Drawer_Tooltip=Create a new drawer in the palette
Local_Palette_Create_Separator_Tooltip=Create a new separator in the palette
Local_Palette_Create_Stack_Tooltip=Create a new stack in the palette
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java
index dc4f44a..3df0996 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/Messages.java
@@ -190,6 +190,15 @@ public class Messages extends NLS {
/** Message for dialog box when palette to delete is not a local palette */
public static String Dialog_Not_Local_Palette_Message;
+ /** Title for dialog box when palette to restore is not an extended palette */
+ public static String Dialog_Not_Extended_Palette_Title;
+
+ /** Message for dialog box when palette to restore is not an extended palette */
+ public static String Dialog_Not_Extended_Palette_Message;
+
+ /** Tooltip for the restore palette button. */
+ public static String Dialog_Restore_Palette_Tooltip;
+
/** tooltip for the delete palette button */
public static String Dialog_Delete_Palette_Tooltip;
@@ -354,7 +363,7 @@ public class Messages extends NLS {
/** IntegerEditor Title */
public static String PropertyEditors_IntegerTitle;
-
+
/** RealEditor Title */
public static String PropertyEditors_RealTitle;
@@ -429,4 +438,6 @@ public class Messages extends NLS {
public static String ShowHideContentsAction_Title;
public static String CommonDeferredCreateConnectionViewCommand_NullConnectionCommand;
+
+
}