diff options
author | Mickael ADAM | 2016-11-17 13:03:43 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-11-30 13:47:52 +0000 |
commit | a3ea7ef9891a5d83d0de788df4bafcfcfb50b453 (patch) | |
tree | ba6c0877b799748a0f3120e096273571462b4370 /plugins/infra/ui | |
parent | e96ff0214a5cdea079ffb209880589c35e9077cf (diff) | |
download | org.eclipse.papyrus-a3ea7ef9891a5d83d0de788df4bafcfcfb50b453.tar.gz org.eclipse.papyrus-a3ea7ef9891a5d83d0de788df4bafcfcfb50b453.tar.xz org.eclipse.papyrus-a3ea7ef9891a5d83d0de788df4bafcfcfb50b453.zip |
Bug 507654 - [Palette Customization] Exported Element type model are
wrong
- Fix issue
Plus:
- correct selection dialog of palette configuration layers
- for some use of tree selector dialog
- Add constraint to flat tabulation:
- Don't display tab in selector dialog when the contentProvider
is flat
https://bugs.eclipse.org/bugs/show_bug.cgi?id=507654
Change-Id: If547f0f8101d56dacc1b2dc488f71a2d8550e792
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/infra/ui')
4 files changed, 37 insertions, 460 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ElementsExplorerDialog.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ElementsExplorerDialog.java deleted file mode 100644 index 92d56d82e9d..00000000000 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ElementsExplorerDialog.java +++ /dev/null @@ -1,436 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2016 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: - * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation - *****************************************************************************/ -package org.eclipse.papyrus.infra.widgets.editors; - -import java.util.Arrays; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IBaseLabelProvider; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.papyrus.infra.widgets.Activator; -import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider; -import org.eclipse.papyrus.infra.widgets.providers.PatternViewerFilter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -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.Tree; -import org.eclipse.ui.dialogs.SelectionStatusDialog; - -/** - * Selection dialog for icons in bundles. - */ -// TODO implement multiselection with multi return -public class ElementsExplorerDialog extends SelectionStatusDialog { - - - /** indicates if several icons can be selected at the same time */ - protected final boolean allowMultiple; - - /** initial value */ - protected String initialValue; - - /** The resource set. */ - protected ResourceSet resourceSet = new ResourceSetImpl(); - - /** The tree viewer. */ - protected TreeViewer elementsTreeViewer; - - /** The tree viewer filter. */ - protected PatternViewerFilterEx viewerFilter = new PatternViewerFilterEx(); - - /** The information text. */ - private StyledText informationText; - - /** The default profile icon path. */ - private static final String ICONS_EXPAND_ALL = "/icons/expandAll.png";//$NON-NLS-1$ - - /** The default profile icon path. */ - private static final String ICONS_COLLAPSE_ALL = "/icons/collapseAll.png";//$NON-NLS-1$ - - /** the content provider. */ - private IStructuredContentProvider contentProvider; - - /** The label provider. */ - private IBaseLabelProvider labelProvider; - - /** The input. */ - private Object input; - - /** the return class type. */ - private Class<?> returnClass; - - public ElementsExplorerDialog(final Shell parentShell, final boolean allowMultiple, final String initialQualifyName) { - super(parentShell); - this.allowMultiple = allowMultiple; - this.initialValue = initialQualifyName; - } - - public ElementsExplorerDialog(final Shell parentShell, final String initialValue) { - this(parentShell, false, initialValue); - } - - public ElementsExplorerDialog(final Shell parentShell) { - this(parentShell, false, "");//$NON-NLS-1$ - } - - /** - * {@inheritDoc} - * Unloads resources. - * - * @see org.eclipse.jface.dialogs.Dialog#close() - */ - @Override - public boolean close() { - for (Resource resource : resourceSet.getResources()) { - if (resource.isLoaded()) { - resource.unload(); - } - } - return super.close(); - } - - /** - * Return the selected {@link Stereotype}. - * {@inheritDoc} - */ - @Override - protected void computeResult() { - Object selectedElements = getSelectedElements(); - if (null != selectedElements) { - setResult(Arrays.asList(selectedElements)); - } - } - - /** - * {@inheritDoc} - */ - @Override - protected Control createDialogArea(final Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); - initializeDialogUnits(composite); - - // creates the message area, as defined in the super class - createMessageArea(composite); - createFilterText(composite); - createExpandCollapseButtons(composite); - createFilteredList(composite); - createInformationText(composite); - - selectInitialValue(); - refreshOkButton(); - return composite; - } - - /** - * Create buttons to collapse and expand treeViewer. - */ - protected void createExpandCollapseButtons(final Composite composite) { - if (contentProvider instanceof ITreeContentProvider) { - Composite container = new Composite(composite, SWT.NONE); - GridLayout layout = new GridLayout(2, true); - layout.horizontalSpacing = 2; - layout.marginBottom = -5; - layout.marginBottom = -5; - container.setLayout(layout); - - Label buttonExpand = new Label(container, SWT.NONE); - Image imageExpand = Activator.getDefault().getImage(ICONS_EXPAND_ALL); - buttonExpand.setImage(imageExpand); - buttonExpand.addMouseListener(new MouseAdapter() { - /** - * {@iniriteDoc] - * - * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent) - */ - @Override - public void mouseUp(MouseEvent event) { - elementsTreeViewer.expandAll(); - } - }); - - Label buttonCollapse = new Label(container, SWT.NONE); - Image imageCollapse = Activator.getDefault().getImage(ICONS_COLLAPSE_ALL); - buttonCollapse.setImage(imageCollapse); - buttonCollapse.addMouseListener(new MouseAdapter() { - /** - * {@iniriteDoc] - * - * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent) - */ - @Override - public void mouseUp(MouseEvent event) { - elementsTreeViewer.collapseAll(); - } - }); - } - } - - /** - * Selected the initial value in treeViewer. - */ - protected void selectInitialValue() { - // //Select initialValue Stereotype - if (!initialValue.isEmpty()) { - ITreeContentProvider contentProvider = (ITreeContentProvider) elementsTreeViewer.getContentProvider(); - Object[] roots = contentProvider.getElements(null); - // TODO select initial value - // for (Object root : roots) { - // Object[] profiles = contentProvider.getChildren(root); - // for (Object profile : profiles) { - // Object[] stereotypes = contentProvider.getChildren(profile); - // for (Object stereotype : stereotypes) { - // // if (stereotype instanceof Stereotype && initialValue.equals(((Stereotype) stereotype).getQualifiedName())) { - // // elementsTreeViewer.expandToLevel(profile, 1); - // // elementsTreeViewer.setSelection(new StructuredSelection(stereotype), true); - // // break; - // // } - // - // } - // } - // } - } - } - - /** - * Create information text field. - */ - protected void createInformationText(final Composite composite) { - informationText = new StyledText(composite, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL); - informationText.setLayoutData(new GridData(SWT.FILL, SWT.WRAP, true, false)); - informationText.setAlwaysShowScrollBars(false); - } - - /** - * Creates a filtered list. - * - * @param parent - * the parent composite. - * @return returns the filtered list widget. - */ - protected TreeViewer createFilteredList(final Composite parent) { - - Tree tree = new Tree(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - final GridLayout filterLayout = new GridLayout(); - filterLayout.marginHeight = 0; - filterLayout.marginWidth = 0; - tree.setLayout(filterLayout); - { - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - tree.setLayoutData(gridData); - } - - TreeViewer treeViewer = new TreeViewer(tree); - treeViewer.setContentProvider(new EncapsulatedContentProvider(contentProvider)); - treeViewer.setLabelProvider(labelProvider); - - treeViewer.setFilters(viewerFilter); - - treeViewer.setInput(null != input ? input : new Object()); - - // Selection change listener to refresh button and information - treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(final SelectionChangedEvent event) { - refreshOkButton(); - refreshInformationText(); - } - }); - - // Double click listener to validate with double click - treeViewer.addDoubleClickListener(new IDoubleClickListener() { - - @Override - public void doubleClick(final DoubleClickEvent event) { - if (getOkButton().isEnabled()) { - okPressed(); - } - } - - }); - - treeViewer.refresh(); - elementsTreeViewer = treeViewer; - - return treeViewer; - } - - /** - * Pattern viewer filter extension used to filter elements from stereotype tree viewer with the text field. - * Extended to filter only applicable {@link Stereotype} from source {@link Element}. - */ - private class PatternViewerFilterEx extends PatternViewerFilter { - /** - * Only set it visible if we can load the profile. - * - * @see org.eclipse.papyrus.infra.widgets.providers.PatternViewerFilter#isVisible(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - @Override - public boolean isVisible(final Viewer viewer, final Object parentElement, final Object element) { - - boolean visible = super.isVisible(viewer, parentElement, element); - visible &= ElementsExplorerDialog.this.isVisible(element); - return visible; - } - - /** - * Override to pass method from protected to public. - * - * @see org.eclipse.papyrus.infra.widgets.providers.AbstractTreeFilter#clearCache() - */ - public void clearCache() { - super.clearCache(); - } - } - - /** - * Creates an area where a filter can be entered. - * - * @param parent - * the parent composite where to create the filter text - * @return the created text area - */ - protected void createFilterText(final Composite parent) { - // Create the filter composite - final StringWithClearEditor filterText = new StringWithClearEditor(parent, SWT.BORDER); - - filterText.setValue("");//$NON-NLS-1$ - - filterText.getText().addModifyListener(new ModifyListener() { - - @Override - public void modifyText(final ModifyEvent e) { - String value = filterText.getValue(); - viewerFilter.setPattern(value); - elementsTreeViewer.refresh(); - elementsTreeViewer.collapseAll(); - // If some text in filter expands to the stereotype level else to the profile level - elementsTreeViewer.expandToLevel(value.isEmpty() ? 2 : 3); - } - }); - - // Key listener to focus in the treviewer when presser arrow down key - filterText.getText().addKeyListener(new KeyAdapter() { - - /** - * {@inheritDoc} - */ - @Override - public void keyPressed(final KeyEvent e) { - if (e.keyCode == SWT.ARROW_DOWN) { - elementsTreeViewer.getControl().setFocus(); - } - } - }); - } - - /** - * Returns the currently selected element. - * To be called within or after open(). - * - * @return returns the currently selected element. - */ - protected Object getSelectedElements() { - Assert.isNotNull(elementsTreeViewer); - return elementsTreeViewer.getStructuredSelection().getFirstElement(); - } - - /** - * Refresh the Ok button according to the selection. - */ - protected void refreshOkButton() { - Object selectedElements = getSelectedElements(); - - if (null != selectedElements && (null == returnClass || returnClass.isInstance(selectedElements))) { - updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, ""));//$NON-NLS-1$ - } else { - updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ""));//$NON-NLS-1$ - } - } - - /** - * Refresh the Information text according to the selection. To be implemented by client. - */ - protected void refreshInformationText() { - // To be implemented by client. - } - - - /** - * Return true if element have to be visible. It can be used to force element to be visible even if the filter dosen't not match with them. - */ - protected boolean isVisible(final Object element) { - return true; - } - - /** - * Set the content provider of the treeviewer. - */ - public void setContentProvider(final IStructuredContentProvider contentProvider) { - this.contentProvider = contentProvider; - if (null != elementsTreeViewer) { - elementsTreeViewer.setContentProvider(new EncapsulatedContentProvider(contentProvider)); - } - } - - /** - * Set the label provider of the treeviewer. - */ - public void setLabelProvider(final IBaseLabelProvider labelProvider) { - this.labelProvider = labelProvider; - if (null != elementsTreeViewer) { - elementsTreeViewer.setLabelProvider(labelProvider); - } - } - - /** - * Set the input. - */ - public void setInput(final Object input) { - this.input = input; - if (null != elementsTreeViewer) { - elementsTreeViewer.setInput(input); - } - } - - /** - * Sets the return type Class that will be return. - */ - public void setReturnTypeClass(final Class<?> returnClass) { - this.returnClass = returnClass; - } - -} diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java index e6bdf573aa8..2fc31bfe4d7 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java @@ -219,10 +219,6 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector */ public TreeSelectorDialog(final Shell parentShell) { super(parentShell); - tabIds.add(defaultTabId); - tabNames.put(defaultTabId, Messages.TreeSelectorDialog_defaultTabLabel); - Image treeIcon = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.PLUGIN_ID, ICONS_TREE_VIEW); - tabIcons.put(defaultTabId, treeIcon); } /** @@ -231,26 +227,33 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector protected void initializeTabulationInfo() { SelectorDialogTabReader instance = SelectorDialogTabReader.getInstance(); + // Add default tab + tabIds.add(defaultTabId); + tabNames.put(defaultTabId, Messages.TreeSelectorDialog_defaultTabLabel); + Image treeIcon = org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.PLUGIN_ID, ICONS_TREE_VIEW); + tabIcons.put(defaultTabId, treeIcon); + List<String> ids = instance.getIds(); for (String id : ids) { + + ILabelProvider tabLabelProvider = instance.getLabelProviders().get(id); + labelProviders.put(id, tabLabelProvider); + if (tabLabelProvider instanceof IDependableLabelProvider) { + ((IDependableLabelProvider) tabLabelProvider).setLabelProvider(labelProviders.get(defaultTabId)); + } + + ITreeContentProvider tabContentProvider = instance.getContentProviders().get(id); + contentProviders.put(id, tabContentProvider); + if (tabContentProvider instanceof IDependableContentProvider) { + ((IDependableContentProvider) tabContentProvider).setContentProvider(contentProviders.get(defaultTabId)); + } + Constraint constraint = instance.getConstraints().get(id); if (!tabIds.contains(id) && (null == constraint || constraint.match(Collections.singleton(id)))) { tabIds.addAll(ids); tabNames.put(id, instance.getTabNames().get(id)); tabIcons.put(id, instance.getTabIcons().get(id)); descriptions.put(id, instance.getDescriptions().get(id)); - - ILabelProvider tabLabelProvider = instance.getLabelProviders().get(id); - labelProviders.put(id, tabLabelProvider); - if (tabLabelProvider instanceof IDependableLabelProvider) { - ((IDependableLabelProvider) tabLabelProvider).setLabelProvider(labelProviders.get(defaultTabId)); - } - - ITreeContentProvider tabContentProvider = instance.getContentProviders().get(id); - contentProviders.put(id, tabContentProvider); - if (tabContentProvider instanceof IDependableContentProvider) { - ((IDependableContentProvider) tabContentProvider).setContentProvider(contentProviders.get(defaultTabId)); - } } } @@ -457,13 +460,20 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector GridLayoutFactory.swtDefaults().applyTo(tabComposite); } + // Message label(common for all tabs) + if (null != getMessage() && !getMessage().isEmpty()) { + Label messageLabel = new Label(tabComposite, SWT.WRAP); + messageLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + messageLabel.setText(getMessage()); + } // Description Label - if (null != descriptions.get(tabId)) { + if (null != descriptions.get(tabId) && !descriptions.get(tabId).isEmpty()) { Label descriptionLabel = new Label(tabComposite, SWT.WRAP); descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); descriptionLabel.setText(tabDescription); } + // create tree viewer ExtendedTreeViewer tabTreeViewer = new ExtendedTreeViewer(tabComposite, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, true).hint(300, 300).applyTo(tabTreeViewer.getTree()); @@ -656,10 +666,12 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector * The input. */ private void doSetInput(final String TabId) { - if (null == input) { - treeViewers.get(TabId).setInput("");//$NON-NLS-1$ - } else { - treeViewers.get(TabId).setInput(input); + if (null != treeViewers.get(TabId)) { + if (null == input) { + treeViewers.get(TabId).setInput("");//$NON-NLS-1$ + } else { + treeViewers.get(TabId).setInput(input); + } } } diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FilteredContentProvider.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FilteredContentProvider.java index d86d51e8254..b67a5bb31f0 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FilteredContentProvider.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FilteredContentProvider.java @@ -130,7 +130,9 @@ public class FilteredContentProvider extends EncapsulatedContentProvider { @Override public void createViewerToolbar(final Composite parent) { // Create case sensitive checkbox - createExpandCollapseButtons(parent); + if (!isFlat()) { + createExpandCollapseButtons(parent); + } } /** @@ -138,7 +140,6 @@ public class FilteredContentProvider extends EncapsulatedContentProvider { */ protected void createExpandCollapseButtons(final Composite parent) { - ToolBar Toolbar = new ToolBar(parent, SWT.NONE); buttonExpand = new ToolItem(Toolbar, SWT.NONE); buttonExpand.setImage(Activator.getDefault().getImage(ICONS_EXPAND_ALL)); diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FlatFilteredContentProvider.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FlatFilteredContentProvider.java index 0b943186ac6..c41dbda329e 100644 --- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FlatFilteredContentProvider.java +++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/FlatFilteredContentProvider.java @@ -182,7 +182,7 @@ public class FlatFilteredContentProvider protected Object[] getAllChildren(final Object parentElement, final Set<Object> visitedElements) { Set<Object> list = new HashSet<Object>(); Object[] children = provider.getChildren(parentElement); - if (0 < children.length) { + if (null != children && 0 < children.length) { for (int i = 0; i < children.length; i++) { boolean visited = false; |