Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Activator.java53
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Messages.java25
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/PersistableColumn.java217
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/Column.java33
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTable.java47
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTree.java47
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidget.java30
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidgetFactory.java48
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TableColumn.java49
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TreeColumn.java49
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IColumnDescription.java34
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IElementsViewFactory.java68
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/messages.properties11
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/preference/pages/EmfFacetRootPreferencePage.java59
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/AbstractTreeView.java176
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsView.java208
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsViewFactory.java52
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/widgets/AnywhereFilterMatcher.java28
18 files changed, 1234 insertions, 0 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Activator.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Activator.java
new file mode 100644
index 00000000000..c5b166774cc
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Activator.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2011 Mia-Software.
+ *
+ * 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+ */
+package org.eclipse.emf.facet.common.ui.internal;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.emf.facet.common.ui"; //$NON-NLS-1$
+
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ @Override
+ public void start(final BundleContext context) throws Exception {
+ super.start(context);
+ Activator.plugin = this;
+ }
+
+ @Override
+ public void stop(final BundleContext context) throws Exception {
+ Activator.plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return Activator.plugin;
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Messages.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Messages.java
new file mode 100644
index 00000000000..e7cbdcb86fd
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/Messages.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.emf.facet.common.ui.internal.messages"; //$NON-NLS-1$
+ public static String ElementsView_refreshJobTitle;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/PersistableColumn.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/PersistableColumn.java
new file mode 100644
index 00000000000..56a7b5875aa
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/PersistableColumn.java
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.Column;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.SortableTable;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.SortableTree;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.SortableWidget;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.SortableWidgetFactory;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.TableColumn;
+import org.eclipse.emf.facet.common.ui.internal.controls.wrappers.TreeColumn;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerColumn;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * A column in a {@link TreeViewer} or {@link TableViewer} that is sortable (using the given
+ * {@link ColumnLabelProvider}) and can save its width to an {@link IMemento}.
+ */
+public class PersistableColumn {
+
+ /**
+ * Saved column widths, static because we want to be able to save column widths during the
+ * session (if a view is closed and re-opened), instead of only when the workbench is closed
+ * (which is the case with {@link ViewPart#saveState(org.eclipse.ui.IMemento)})
+ */
+ private static final Map<String, Integer> COLUMN_WIDTHS = new HashMap<String, Integer>();
+
+ /** The unique id associated to this column */
+ private String fUniqueID;
+
+ /** The underlying JFace column */
+ private final ViewerColumn fViewerColumn;
+
+ private Column getColumn() {
+ if (this.fViewerColumn instanceof TreeViewerColumn) {
+ TreeViewerColumn treeViewerColumn = (TreeViewerColumn) this.fViewerColumn;
+ return new TreeColumn(treeViewerColumn.getColumn());
+ } else if (this.fViewerColumn instanceof TableViewerColumn) {
+ TableViewerColumn tableViewerColumn = (TableViewerColumn) this.fViewerColumn;
+ return new TableColumn(tableViewerColumn.getColumn());
+ }
+ throw new IllegalStateException("neither a table nor tree column"); //$NON-NLS-1$
+ }
+
+ /**
+ * Initialize a sortable column that can be persisted to an {@link IMemento} .
+ *
+ * @param columnText
+ * the title of the column
+ * @param uniqueID
+ * a unique id used to persist the column width
+ * @param defaultWidth
+ * the width to use if no previous information was saved
+ * @param columnLabelProvider
+ * the label provider for this column
+ */
+ protected void init(final String columnText, final String uniqueID, final int defaultWidth,
+ final ColumnLabelProvider columnLabelProvider) {
+ this.fUniqueID = uniqueID;
+ final Column column = getColumn();
+ column.setText(columnText);
+
+ Integer width = PersistableColumn.getColumnWidths().get(uniqueID);
+ if (width != null) {
+ column.setWidth(width.intValue());
+ } else {
+ column.setWidth(defaultWidth);
+ }
+ column.addControlListener(new ControlAdapter() {
+ @Override
+ public void controlResized(final ControlEvent e) {
+ PersistableColumn.getColumnWidths().put(uniqueID, new Integer(column.getWidth()));
+ }
+ });
+
+ this.fViewerColumn.setLabelProvider(columnLabelProvider);
+ }
+
+ /**
+ * Create a sortable column that can be persisted to an {@link IMemento}.
+ *
+ * @param columnText
+ * the title of the column
+ * @param uniqueID
+ * a unique id used to persist the column width
+ * @param defaultWidth
+ * the width to use if no previous information was saved
+ * @param columnLabelProvider
+ * the label provider for this column
+ * @param treeViewer
+ * the {@link TreeViewer} in which to create the column
+ */
+ public PersistableColumn(final String columnText, final String uniqueID,
+ final int defaultWidth, final ColumnLabelProvider columnLabelProvider,
+ final TreeViewer treeViewer) {
+ TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
+ this.fViewerColumn = treeViewerColumn;
+ init(columnText, uniqueID, defaultWidth, columnLabelProvider);
+
+ addSorter(new TreeColumn(treeViewerColumn.getColumn()),
+ getViewerSorter(columnLabelProvider), new SortableTree(treeViewer));
+ }
+
+ /**
+ * Create a sortable column that can be persisted to an {@link IMemento}.
+ *
+ * @param columnText
+ * the title of the column
+ * @param uniqueID
+ * a unique id used to persist the column width
+ * @param defaultWidth
+ * the width to use if no previous information was saved
+ * @param columnLabelProvider
+ * the label provider for this column
+ * @param tableViewer
+ * the {@link TableViewer} in which to create the column
+ */
+ public PersistableColumn(final String columnText, final String uniqueID,
+ final int defaultWidth, final ColumnLabelProvider columnLabelProvider,
+ final TableViewer tableViewer) {
+ TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
+ this.fViewerColumn = tableViewerColumn;
+ init(columnText, uniqueID, defaultWidth, columnLabelProvider);
+
+ addSorter(new TableColumn(tableViewerColumn.getColumn()),
+ getViewerSorter(columnLabelProvider), new SortableTable(tableViewer));
+ }
+
+ private static ViewerSorter getViewerSorter(final ColumnLabelProvider columnLabelProvider) {
+ return new ViewerSorter() {
+ @Override
+ public int compare(final Viewer viewer, final Object e1, final Object e2) {
+ String text1 = columnLabelProvider.getText(e1);
+ String text2 = columnLabelProvider.getText(e2);
+ if (text1 == null) {
+ return -1;
+ }
+ int compare = text1.compareTo(text2);
+ SortableWidget sortableWidget = SortableWidgetFactory.createSortableWidget(viewer);
+ if (sortableWidget.getSortDirection() == SWT.DOWN) {
+ compare = compare * -1;
+ }
+ return compare;
+ }
+ };
+ }
+
+ private static void addSorter(final Column column, final ViewerSorter viewerSorter,
+ final SortableWidget sortableWidget) {
+ column.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ sortableWidget.setSorter(viewerSorter);
+ sortableWidget.setSortColumn(column);
+ if (sortableWidget.getSortDirection() == SWT.UP) {
+ sortableWidget.setSortDirection(SWT.DOWN);
+ } else if (sortableWidget.getSortDirection() == SWT.DOWN) {
+ sortableWidget.setSortDirection(SWT.UP);
+ } else {
+ sortableWidget.setSortDirection(SWT.UP);
+ }
+ sortableWidget.refresh();
+ }
+ });
+ }
+
+ public void saveState(final IMemento memento) {
+ Integer width = PersistableColumn.getColumnWidths().get(this.fUniqueID);
+ if (width != null) {
+ memento.putInteger(this.fUniqueID, width.intValue());
+ }
+ }
+
+ /**
+ * Loads the saved state from the given {@link IMemento}. Columns created using the given id
+ * after this call will have their width set to the value that was loaded.
+ */
+ public static void loadState(final IMemento memento, final String columnID) {
+ Integer width = memento.getInteger(columnID);
+ if (width != null) {
+ PersistableColumn.getColumnWidths().put(columnID, width);
+ }
+ }
+
+ public void setWidth(final int width) {
+ getColumn().setWidth(width);
+ }
+
+ protected static Map<String, Integer> getColumnWidths() {
+ return PersistableColumn.COLUMN_WIDTHS;
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/Column.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/Column.java
new file mode 100644
index 00000000000..74ceb3887e2
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/Column.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TreeColumn;
+
+/** Provides a unified API over both SWT {@link TreeColumn} and {@link TableColumn} */
+public interface Column {
+ void setText(String columnText);
+
+ void addControlListener(ControlListener controlListener);
+
+ void addSelectionListener(SelectionListener selectionListener);
+
+ void setWidth(int width);
+
+ int getWidth();
+
+ Item getColumn();
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTable.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTable.java
new file mode 100644
index 00000000000..ef0b7552551
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTable.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+/**
+ * Implements {@link SortableWidget}'s unified API for the JFace {@link TableViewer}.
+ */
+public class SortableTable implements SortableWidget {
+ private final TableViewer tableViewer;
+
+ public SortableTable(final TableViewer tableViewer) {
+ this.tableViewer = tableViewer;
+ }
+
+ public void setSorter(final ViewerSorter viewerSorter) {
+ this.tableViewer.setSorter(viewerSorter);
+ }
+
+ public int getSortDirection() {
+ return this.tableViewer.getTable().getSortDirection();
+ }
+
+ public void setSortDirection(final int direction) {
+ this.tableViewer.getTable().setSortDirection(direction);
+ }
+
+ public void setSortColumn(final Column column) {
+ this.tableViewer.getTable().setSortColumn(
+ (org.eclipse.swt.widgets.TableColumn) column.getColumn());
+ }
+
+ public void refresh() {
+ this.tableViewer.refresh();
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTree.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTree.java
new file mode 100644
index 00000000000..3f66f24fb0e
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableTree.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+/**
+ * Implements {@link SortableWidget}'s unified API for the JFace {@link TreeViewer}.
+ */
+public class SortableTree implements SortableWidget {
+ private final TreeViewer treeViewer;
+
+ public SortableTree(final TreeViewer treeViewer) {
+ this.treeViewer = treeViewer;
+ }
+
+ public void setSorter(final ViewerSorter viewerSorter) {
+ this.treeViewer.setSorter(viewerSorter);
+ }
+
+ public int getSortDirection() {
+ return this.treeViewer.getTree().getSortDirection();
+ }
+
+ public void setSortDirection(final int direction) {
+ this.treeViewer.getTree().setSortDirection(direction);
+ }
+
+ public void setSortColumn(final Column column) {
+ this.treeViewer.getTree().setSortColumn(
+ (org.eclipse.swt.widgets.TreeColumn) column.getColumn());
+ }
+
+ public void refresh() {
+ this.treeViewer.refresh();
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidget.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidget.java
new file mode 100644
index 00000000000..ff9dfd9e921
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidget.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+
+/** Provides a unified API over both SWT {@link Tree} and {@link Table} */
+public interface SortableWidget {
+ void setSorter(ViewerSorter viewerSorter);
+
+ int getSortDirection();
+
+ void setSortDirection(int direction);
+
+ void setSortColumn(Column column);
+
+ void refresh();
+
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidgetFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidgetFactory.java
new file mode 100644
index 00000000000..ea310f5ab6b
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/SortableWidgetFactory.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Tree;
+
+/**
+ * A factory to obtain a {@link SortableWidget}, that provides a unified API over both SWT
+ * {@link Tree} and {@link Table}.
+ */
+public final class SortableWidgetFactory {
+
+ private SortableWidgetFactory() {
+ // utility class
+ }
+
+ /**
+ * Get a {@link SortableWidget} for the given {@link Viewer}, that can be either a
+ * {@link TreeViewer} or a {@link TableViewer}.
+ *
+ * @param viewer
+ * a {@link TreeViewer} or a {@link TableViewer}
+ * @return a {@link SortableWidget} that delegates to the given viewer
+ */
+ public static SortableWidget createSortableWidget(final Viewer viewer) {
+ if (viewer instanceof TreeViewer) {
+ TreeViewer treeViewer = (TreeViewer) viewer;
+ return new SortableTree(treeViewer);
+ } else if (viewer instanceof TableViewer) {
+ TableViewer tableViewer = (TableViewer) viewer;
+ return new SortableTable(tableViewer);
+ }
+ throw new IllegalArgumentException();
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TableColumn.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TableColumn.java
new file mode 100644
index 00000000000..141a06fa1f9
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TableColumn.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.SelectionListener;
+
+/** Implements {@link Column}'s unified API for the SWT {@link org.eclipse.swt.widgets.TableColumn} */
+public class TableColumn implements Column {
+ private final org.eclipse.swt.widgets.TableColumn column;
+
+ public TableColumn(final org.eclipse.swt.widgets.TableColumn column) {
+ this.column = column;
+ }
+
+ public void setText(final String columnText) {
+ this.column.setText(columnText);
+ }
+
+ public void setWidth(final int width) {
+ this.column.setWidth(width);
+
+ }
+
+ public void addControlListener(final ControlListener controlListener) {
+ this.column.addControlListener(controlListener);
+ }
+
+ public void addSelectionListener(final SelectionListener selectionListener) {
+ this.column.addSelectionListener(selectionListener);
+ }
+
+ public int getWidth() {
+ return this.column.getWidth();
+ }
+
+ public org.eclipse.swt.widgets.TableColumn getColumn() {
+ return this.column;
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TreeColumn.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TreeColumn.java
new file mode 100644
index 00000000000..c30a1fb87c7
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/controls/wrappers/TreeColumn.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.controls.wrappers;
+
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.SelectionListener;
+
+/** Implements {@link Column}'s unified API for the SWT {@link org.eclipse.swt.widgets.TreeColumn} */
+public class TreeColumn implements Column {
+ private final org.eclipse.swt.widgets.TreeColumn column;
+
+ public TreeColumn(final org.eclipse.swt.widgets.TreeColumn column) {
+ this.column = column;
+ }
+
+ public void setText(final String columnText) {
+ this.column.setText(columnText);
+ }
+
+ public void setWidth(final int width) {
+ this.column.setWidth(width);
+
+ }
+
+ public void addControlListener(final ControlListener controlListener) {
+ this.column.addControlListener(controlListener);
+ }
+
+ public void addSelectionListener(final SelectionListener selectionListener) {
+ this.column.addSelectionListener(selectionListener);
+ }
+
+ public int getWidth() {
+ return this.column.getWidth();
+ }
+
+ public org.eclipse.swt.widgets.TreeColumn getColumn() {
+ return this.column;
+ }
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IColumnDescription.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IColumnDescription.java
new file mode 100644
index 00000000000..6aa019910c6
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IColumnDescription.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.exported.views;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+
+/**
+ * Contains the data necessary to create a column in a view created by
+ * {@link IElementsViewFactory#createElementsView(java.util.Collection, org.eclipse.jface.viewers.ITreeContentProvider, Object, String, org.eclipse.swt.graphics.Image, org.eclipse.jface.viewers.IOpenListener) IElementsViewFactory#createElementsView}
+ */
+public interface IColumnDescription {
+ /** The column's label */
+ String getTitle();
+
+ /** A unique id for the column */
+ String getUniqueID();
+
+ /** The default width that will be used the first time the column is displayed */
+ int getDefaultWidth();
+
+ /**
+ * A label provider that returns the text (and optionally image and other font attributes) for each element in this
+ * column
+ */
+ ColumnLabelProvider getColumnLabelProvider();
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IElementsViewFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IElementsViewFactory.java
new file mode 100644
index 00000000000..271e4c969a0
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/exported/views/IElementsViewFactory.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+ *******************************************************************************/
+
+package org.eclipse.emf.facet.common.ui.internal.exported.views;
+
+import java.util.Collection;
+
+import org.eclipse.emf.facet.common.ui.internal.views.ElementsViewFactory;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * Creates Eclipse views to display lists of elements. To be able to register this view in a non-RCP Eclipse, you will
+ * have to register an IExecutableExtensionFactory that will do the actual instantiation.
+ */
+public interface IElementsViewFactory {
+ IElementsViewFactory DEFAULT = new ElementsViewFactory();
+
+ /**
+ * Creates a view with columns. Each column has a default width, and memorizes its width once resized.
+ *
+ * @param columnDescriptions
+ * describes the columns
+ * @param contentProvider
+ * provides the content from the input
+ * @param input
+ * the view's input
+ * @param title
+ * the part's label
+ * @param titleImage
+ * the part's image
+ * @param openListener
+ * a listener called when hitting Enter or double-clicking on an element in the view
+ * @return the view part
+ */
+ ViewPart createElementsView(Collection<? extends IColumnDescription> columnDescriptions,
+ ITreeContentProvider contentProvider, Object input, String title, Image titleImage, IOpenListener openListener);
+
+ /**
+ * Creates a column description for
+ * {@link IElementsViewFactory#createElementsView(Collection, ITreeContentProvider, Object, String, Image, IOpenListener)
+ * createElementsView}
+ *
+ * @param title
+ * the column label
+ * @param uniqueID
+ * a unique ID that will identify the column (used for serialization)
+ * @param defaultWidth
+ * the initial width of the column, before the user resizes it
+ * @param columnLabelProvider
+ * A label provider that returns the text (and optionally image and other font attributes) for each
+ * element in this column
+ * @return a column description
+ */
+ IColumnDescription createColumnDescription(String title, String uniqueID,
+ int defaultWidth, ColumnLabelProvider columnLabelProvider);
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/messages.properties b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/messages.properties
new file mode 100644
index 00000000000..8505a5f4b7a
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/messages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2012 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:
+# Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+###############################################################################
+ElementsView_refreshJobTitle=Refreshing view {0}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/preference/pages/EmfFacetRootPreferencePage.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/preference/pages/EmfFacetRootPreferencePage.java
new file mode 100644
index 00000000000..28708ad05ef
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/preference/pages/EmfFacetRootPreferencePage.java
@@ -0,0 +1,59 @@
+/**********************************************************************************
+ * Copyright (c) 2011 Mia-Software.
+ * 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:
+ * Nicolas Guyomar (Mia-Software) - Bug 333652 Extension point offering the possibility to declare an EPackage browser
+ ***********************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.preference.pages;
+
+import org.eclipse.emf.facet.common.ui.internal.Activator;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * This class is the EmfFacet root preference page that is contributed to the
+ * Preferences dialog. By sub-classing {@link FieldEditorPreferencePage}, we can
+ * use the field support built into JFace that allows us to create a page that
+ * is small and knows how to save, restore and apply itself.
+ * <p>
+ * This page is used to modify preferences, that are stored in the preference
+ * store that belongs to the main plug-in class. That way, preferences can be
+ * accessed directly via the preference store.
+ */
+
+public class EmfFacetRootPreferencePage extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ public static final String P_DEFAULT_EPACKAGE_VIEWER = "emf_facet_default_epackage_viewer"; //$NON-NLS-1$
+
+ public EmfFacetRootPreferencePage() {
+ super(FieldEditorPreferencePage.GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+ /**
+ * Creates the field editors. Field editors are abstractions of the common
+ * GUI blocks needed to manipulate various types of preferences. Each field
+ * editor knows how to save and restore itself.
+ */
+ @Override
+ public void createFieldEditors() {
+ // The page is empty for now
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(final IWorkbench workbench) {
+ // Nothing to do
+ }
+
+} \ No newline at end of file
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/AbstractTreeView.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/AbstractTreeView.java
new file mode 100644
index 00000000000..5b176128e26
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/AbstractTreeView.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ *******************************************************************************/
+
+package org.eclipse.emf.facet.common.ui.internal.views;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.facet.common.ui.internal.Activator;
+import org.eclipse.emf.facet.common.ui.internal.controls.PersistableColumn;
+import org.eclipse.emf.facet.util.core.Logger;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+
+/** An abstract Eclipse view that displays a list of elements. */
+public abstract class AbstractTreeView extends ViewPart {
+
+ private final List<PersistableColumn> columns = new ArrayList<PersistableColumn>();
+ private final Map<String, Integer> persistedValues = new HashMap<String, Integer>();
+
+ private static final int JOB_SCHEDULE_DELAY = 500;
+ private Job fRefreshJob = null;
+
+ private TreeViewer fTreeViewer;
+
+ public TreeViewer getViewer() {
+ return this.fTreeViewer;
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ parent.setLayout(new FillLayout());
+
+ this.fTreeViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE
+ | SWT.FULL_SELECTION);
+ this.fTreeViewer.getTree().setLinesVisible(true);
+ this.fTreeViewer.getTree().setHeaderVisible(true);
+
+ this.fTreeViewer.addOpenListener(new IOpenListener() {
+ public void open(final OpenEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) AbstractTreeView.this
+ .getViewer().getSelection();
+ openElement(selection.getFirstElement());
+ }
+ });
+
+ createColumns();
+
+ this.fTreeViewer.setContentProvider(getContentProvider());
+
+ createContextMenu();
+ getSite().setSelectionProvider(this.fTreeViewer);
+ refresh(false);
+ }
+
+ protected void createContextMenu() {
+ final MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
+ contextMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ final Menu menu = contextMenu.createContextMenu(getViewer().getControl());
+ getViewer().getControl().setMenu(menu);
+ getSite().registerContextMenu(contextMenu, getViewer());
+ }
+
+ protected abstract void createColumns();
+
+ protected abstract IContentProvider getContentProvider();
+
+ protected abstract void openElement(Object element);
+
+ @Override
+ public void setFocus() {
+ this.fTreeViewer.getControl().setFocus();
+ }
+
+ /** Optionally delayed refresh */
+ protected void refresh(final boolean delayed) {
+ if (this.fRefreshJob == null) {
+ this.fRefreshJob = new Job(getRefreshMessage()) {
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ doRefresh();
+ return Status.OK_STATUS;
+ }
+ };
+ }
+ // delayed until it stops changing
+ this.fRefreshJob.cancel();
+ if (delayed) {
+ this.fRefreshJob.setPriority(Job.DECORATE);
+ this.fRefreshJob.schedule(AbstractTreeView.JOB_SCHEDULE_DELAY);
+ } else {
+ this.fRefreshJob.setPriority(Job.INTERACTIVE);
+ this.fRefreshJob.schedule();
+ }
+ }
+
+ protected abstract String getRefreshMessage();
+
+ protected abstract Object getInput();
+
+ protected void doRefresh() {
+ // Accesses the catalog, which can block if done inside the UI thread.
+ final Object input = getInput();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ getViewer().setInput(input);
+ getViewer().refresh();
+ }
+ });
+ }
+
+ protected void createColumn(final String columnText, final String uniqueID,
+ final int defaultWidth, final ColumnLabelProvider columnLabelProvider) {
+ PersistableColumn persistableColumn = new PersistableColumn(columnText, uniqueID,
+ defaultWidth, columnLabelProvider, this.fTreeViewer);
+ this.columns.add(persistableColumn);
+ Integer width = this.persistedValues.get(uniqueID);
+ if (width != null) {
+ persistableColumn.setWidth(width.intValue());
+ }
+ }
+
+ @Override
+ public void saveState(final IMemento memento) {
+ super.saveState(memento);
+ try {
+ for (PersistableColumn column : this.columns) {
+ column.saveState(memento);
+ }
+ } catch (Exception e) {
+ Logger.logError(e, "Error saving view state", Activator.getDefault()); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void init(final IViewSite site, final IMemento memento) throws PartInitException {
+ super.init(site, memento);
+ if (memento != null) {
+ String[] attributeKeys = memento.getAttributeKeys();
+ for (String key : attributeKeys) {
+ this.persistedValues.put(key, memento.getInteger(key));
+ }
+ }
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsView.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsView.java
new file mode 100644
index 00000000000..28d18adac5c
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsView.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2012 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software) - initial API and implementation
+ * Nicolas Bros (Mia-Software) - Bug 334116 - common tree view with columns
+ * Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.views;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.facet.common.ui.internal.Activator;
+import org.eclipse.emf.facet.common.ui.internal.Messages;
+import org.eclipse.emf.facet.common.ui.internal.controls.PersistableColumn;
+import org.eclipse.emf.facet.common.ui.internal.exported.views.IColumnDescription;
+import org.eclipse.emf.facet.util.core.Logger;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.ViewPart;
+
+public class ElementsView extends ViewPart {
+
+ private static final int JOB_SCHEDULE_DELAY = 500;
+ private final Collection<? extends IColumnDescription> columnDescriptions;
+ private final ITreeContentProvider contentProvider;
+ private final Object input;
+ private final List<PersistableColumn> columns = new ArrayList<PersistableColumn>();
+ private final Map<String, Integer> persistedValues = new HashMap<String, Integer>();
+ private TreeViewer treeViewer;
+ private Job refreshJob = null;
+ private final IOpenListener openListener;
+ private final String title;
+ private final Image titleImage;
+
+ public ElementsView(final Collection<? extends IColumnDescription> columnDescriptions,
+ final ITreeContentProvider contentProvider, final Object input, final String title, final Image titleImage, final IOpenListener openListener) {
+ this.columnDescriptions = columnDescriptions;
+ this.contentProvider = contentProvider;
+ this.input = input;
+ this.title = title;
+ this.titleImage = titleImage;
+ this.openListener = openListener;
+ }
+
+ public TreeViewer getViewer() {
+ return this.treeViewer;
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ setPartName(this.title);
+ setTitleImage(this.titleImage);
+ parent.setLayout(new FillLayout());
+
+ this.treeViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE
+ | SWT.FULL_SELECTION);
+ this.treeViewer.getTree().setLinesVisible(true);
+ this.treeViewer.getTree().setHeaderVisible(true);
+
+ this.treeViewer.addOpenListener(new IOpenListener() {
+ public void open(final OpenEvent event) {
+ ElementsView.this.open(event);
+ }
+ });
+
+ createColumns();
+ this.treeViewer.setContentProvider(getContentProvider());
+ createContextMenu();
+ getSite().setSelectionProvider(this.treeViewer);
+ refresh(false);
+ }
+
+ protected void createContextMenu() {
+ final MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
+ contextMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ final Menu menu = contextMenu.createContextMenu(getViewer().getControl());
+ getViewer().getControl().setMenu(menu);
+ getSite().registerContextMenu(contextMenu, getViewer());
+ }
+
+ protected void createColumns() {
+ for (IColumnDescription columnDescription : this.columnDescriptions) {
+ createColumn(columnDescription.getTitle(), columnDescription.getUniqueID(),
+ columnDescription.getDefaultWidth(), columnDescription.getColumnLabelProvider());
+ }
+ }
+
+ protected IContentProvider getContentProvider() {
+ return this.contentProvider;
+ }
+
+ protected void open(final OpenEvent event) {
+ if (this.openListener != null) {
+ this.openListener.open(event);
+ }
+ }
+
+ @Override
+ public void setFocus() {
+ this.treeViewer.getControl().setFocus();
+ }
+
+ /** Optionally delayed refresh */
+ protected void refresh(final boolean delayed) {
+ if (this.refreshJob == null) {
+ this.refreshJob = new Job(getRefreshMessage()) {
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ doRefresh();
+ return Status.OK_STATUS;
+ }
+ };
+ }
+ // delayed until it stops changing
+ this.refreshJob.cancel();
+ if (delayed) {
+ this.refreshJob.setPriority(Job.DECORATE);
+ this.refreshJob.schedule(ElementsView.JOB_SCHEDULE_DELAY);
+ } else {
+ this.refreshJob.setPriority(Job.INTERACTIVE);
+ this.refreshJob.schedule();
+ }
+ }
+
+ protected String getRefreshMessage() {
+ return NLS.bind(Messages.ElementsView_refreshJobTitle, this.title);
+ }
+
+ protected Object getInput() {
+ return this.input;
+ }
+
+ protected void doRefresh() {
+ // Accesses the catalog, which can block if done inside the UI thread.
+ final Object viewerInput = getInput();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ getViewer().setInput(viewerInput);
+ getViewer().refresh();
+ }
+ });
+ }
+
+ protected void createColumn(final String columnText, final String uniqueID,
+ final int defaultWidth, final ColumnLabelProvider columnLabelProvider) {
+ PersistableColumn persistableColumn = new PersistableColumn(columnText, uniqueID,
+ defaultWidth, columnLabelProvider, this.treeViewer);
+ this.columns.add(persistableColumn);
+ Integer width = this.persistedValues.get(uniqueID);
+ if (width != null) {
+ persistableColumn.setWidth(width.intValue());
+ }
+ }
+
+ @Override
+ public void saveState(final IMemento memento) {
+ super.saveState(memento);
+ try {
+ for (PersistableColumn column : this.columns) {
+ column.saveState(memento);
+ }
+ } catch (Exception e) {
+ Logger.logError(e, "Error saving view state", Activator.getDefault()); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void init(final IViewSite site, final IMemento memento) throws PartInitException {
+ super.init(site, memento);
+ if (memento != null) {
+ String[] attributeKeys = memento.getAttributeKeys();
+ for (String key : attributeKeys) {
+ this.persistedValues.put(key, memento.getInteger(key));
+ }
+ }
+ }
+
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsViewFactory.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsViewFactory.java
new file mode 100644
index 00000000000..ed4539ab2d4
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/views/ElementsViewFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Nicolas Bros (Mia-Software) - Bug 372732 - [Facet] Rewrite the catalog views for 0.2
+ *******************************************************************************/
+
+package org.eclipse.emf.facet.common.ui.internal.views;
+
+import java.util.Collection;
+
+import org.eclipse.emf.facet.common.ui.internal.exported.views.IColumnDescription;
+import org.eclipse.emf.facet.common.ui.internal.exported.views.IElementsViewFactory;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.part.ViewPart;
+
+public class ElementsViewFactory implements IElementsViewFactory {
+
+ public ViewPart createElementsView(final Collection<? extends IColumnDescription> columns,
+ final ITreeContentProvider contentProvider, final Object input, final String title, final Image titleImage, final IOpenListener openListener) {
+ return new ElementsView(columns, contentProvider, input, title, titleImage, openListener);
+ }
+
+ public IColumnDescription createColumnDescription(final String columnText,
+ final String uniqueID, final int defaultWidth,
+ final ColumnLabelProvider columnLabelProvider) {
+ return new IColumnDescription() {
+ public String getUniqueID() {
+ return uniqueID;
+ }
+
+ public int getDefaultWidth() {
+ return defaultWidth;
+ }
+
+ public String getTitle() {
+ return columnText;
+ }
+
+ public ColumnLabelProvider getColumnLabelProvider() {
+ return columnLabelProvider;
+ }
+ };
+ }
+}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/widgets/AnywhereFilterMatcher.java b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/widgets/AnywhereFilterMatcher.java
new file mode 100644
index 00000000000..393a2adc01b
--- /dev/null
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.common.ui/src/org/eclipse/papyrus/emf/facet/common/ui/internal/widgets/AnywhereFilterMatcher.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Mia-Software.
+ * 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:
+ * Nicolas Bros (Mia-Software)
+ *******************************************************************************/
+package org.eclipse.emf.facet.common.ui.internal.widgets;
+
+import org.eclipse.emf.facet.common.core.internal.utils.StringMatcher;
+import org.eclipse.ui.dialogs.FilteredList.FilterMatcher;
+
+/** This is a matcher that matches anywhere, not just at the beginning. */
+public class AnywhereFilterMatcher implements FilterMatcher {
+ private StringMatcher fMatcher;
+
+ public void setFilter(final String pattern, final boolean ignoreCase,
+ final boolean ignoreWildCards) {
+ this.fMatcher = new StringMatcher('*' + pattern + '*', ignoreCase, ignoreWildCards);
+ }
+
+ public boolean match(final Object element) {
+ return this.fMatcher.match(element.toString());
+ }
+}

Back to the top