diff options
9 files changed, 236 insertions, 77 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.properties b/plugins/org.eclipse.emf.cdo.ui/plugin.properties index 8ffd36cf31..74f7ff2410 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.properties +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.properties @@ -3,10 +3,10 @@ # 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: # Eike Stepper - initial API and implementation - + # NLS_MESSAGEFORMAT_VAR # ============================================================================== @@ -60,10 +60,14 @@ _UI_CDOModelWizard_description = Create a new CDO model
_UI_CDOEditorFilenameDefaultBase = My _UI_CDOEditorFilenameExtension = cdo +_UI_CDOLabelDecorator_description = Decorates CDOObject with several features like state, CDOID, ... +_UI_CDOLabelDecorator_label = CDOObject Label Decorator + + # ============================================================================== # %%% END OF TRANSLATED PROPERTIES %%% # The above properties have been shipped for translation. # ============================================================================== _UI_CDOEditorFilenameExtensions = cdo
_WARN_FilenameExtensions = The file name must have one of the following extensions: {0} -
+ diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml index 37456fb2cf..48966e43a5 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml @@ -77,4 +77,23 @@ </page> </extension> + <extension + point="org.eclipse.ui.decorators"> + <decorator + class="org.eclipse.emf.cdo.ui.CDOLabelDecorator" + id="org.eclipse.emf.cdo.ui.cdolabeldecorator" + label="%_UI_CDOLabelDecorator_label" + lightweight="false" + state="true"> + <enablement> + <objectClass + name="org.eclipse.emf.cdo.CDOObject"> + </objectClass> + </enablement> + <description> + %_UI_CDOLabelDecorator_description + </description> + </decorator> + </extension> + </plugin> diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java index 721877389d..6dca8f0d34 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java @@ -11,7 +11,7 @@ **************************************************************************/ package org.eclipse.emf.cdo.internal.ui.bundle; -import org.eclipse.emf.cdo.ui.CDOLabelProvider; +import org.eclipse.emf.cdo.ui.CDOLabelDecorator; import org.eclipse.net4j.util.om.OMBundle; import org.eclipse.net4j.util.om.OMPlatform; @@ -43,7 +43,7 @@ public abstract class OM public static final OMPreferences PREFS = BUNDLE.preferences(); public static final OMPreference<String> PREF_LABEL_DECORATION = // - PREFS.init("PREF_LABEL_DECORATION", CDOLabelProvider.DEFAULT_DECORATION); //$NON-NLS-1$ + PREFS.init("PREF_LABEL_DECORATION", CDOLabelDecorator.DEFAULT_DECORATION); //$NON-NLS-1$ public static final OMPreference<String[]> PREF_HISTORY_SELECT_PACKAGES = // PREFS.initArray("PREF_HISTORY_SELECT_PACKAGES"); //$NON-NLS-1$ diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java index 6dbb69147a..88c1cfec43 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java @@ -4,7 +4,7 @@ * 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: * Eike Stepper - initial API and implementation **************************************************************************/ @@ -97,6 +97,10 @@ import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ILabelDecorator; +import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; @@ -127,6 +131,7 @@ import org.eclipse.ui.IPartListener; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.WorkspaceModifyOperation; import org.eclipse.ui.dialogs.SaveAsDialog; import org.eclipse.ui.ide.IGotoMarker; @@ -1101,7 +1106,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv selectionViewer = new TreeViewer(tree); setCurrentViewer(selectionViewer); - selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); + selectionViewer.setContentProvider(createContentProvider()); selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); selectionViewer.setInput(editingDomain.getResourceSet()); selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true); @@ -1167,8 +1172,9 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv selectionViewer = new TreeViewer(tree); setCurrentViewer(selectionViewer); - selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); - selectionViewer.setLabelProvider(new CDOLabelProvider(adapterFactory, view, selectionViewer)); + selectionViewer.setContentProvider(createContentProvider()); + selectionViewer.setLabelProvider(createLabelProvider()); + selectionViewer.setInput(viewerInput); // selectionViewer.setSelection(new StructuredSelection(viewerInput), // true); @@ -1249,6 +1255,31 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv } /** + * @ADDED + */ + protected IContentProvider createContentProvider() + { + return new AdapterFactoryContentProvider(adapterFactory); + } + + /** + * @ADDED + */ + protected ILabelProvider createLabelProvider() + { + return new DecoratingLabelProvider(new CDOLabelProvider(adapterFactory, view, selectionViewer), + createLabelDecorator()); + } + + /** + * @ADDED + */ + protected ILabelDecorator createLabelDecorator() + { + return PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); + } + + /** * If there is just one page in the multi-page editor part, this hides the single tab at the bottom. <!-- * begin-user-doc --> <!-- end-user-doc --> * diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java index 204a466730..8bd9cc87ab 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java @@ -4,7 +4,7 @@ * 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: * Eike Stepper - initial API and implementation **************************************************************************/ @@ -89,11 +89,6 @@ public class CDOPreferencePage extends OMPreferencePage new Label(viewGroup, SWT.NONE).setText("EMF invalidation notifications:"); invalidationNotifications = new Button(viewGroup, SWT.CHECK); - Group transactionGroup = new Group(composite, SWT.NONE); - transactionGroup.setLayout(new GridLayout(2, false)); - transactionGroup.setText("Transaction Defaults"); - transactionGroup.setLayoutData(UIUtil.createGridData(true, false)); - initValues(); return composite; } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java index efc6cceb23..16b7d79a14 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java @@ -12,7 +12,7 @@ package org.eclipse.emf.cdo.internal.ui.preferences; import org.eclipse.emf.cdo.internal.ui.bundle.OM; -import org.eclipse.emf.cdo.ui.CDOLabelProvider; +import org.eclipse.emf.cdo.ui.CDOLabelDecorator; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.net4j.util.ui.prefs.OMPreferencePage; @@ -52,7 +52,7 @@ public class CDOUIPreferencePage extends OMPreferencePage composite.setLayoutData(UIUtil.createGridData()); new Label(composite, SWT.NONE).setText("Label decoration:"); - decoration = new TextAndDisable(composite, SWT.BORDER, CDOLabelProvider.NO_DECORATION) + decoration = new TextAndDisable(composite, SWT.BORDER, CDOLabelDecorator.NO_DECORATION) { @Override protected GridData createTextLayoutData() @@ -63,13 +63,21 @@ public class CDOUIPreferencePage extends OMPreferencePage decoration.setLayoutData(UIUtil.createGridData(true, false)); Text text = decoration.getText(); + StringBuffer tags = new StringBuffer(); + for (String tag : CDOLabelDecorator.DECORATION_PROPOSALS) + { + tags.append(tag + " "); + } + text.setToolTipText("Available tags: " + tags.toString()); IControlContentAdapter contentAdapter = new TextContentAdapter(); - IContentProposalProvider provider = new SimpleContentProposalProvider(CDOLabelProvider.DECORATION_PROPOSALS); + IContentProposalProvider provider = new SimpleContentProposalProvider(CDOLabelDecorator.DECORATION_PROPOSALS); new ContentAssistCommandAdapter(text, contentAdapter, provider, null, new char[] { '$' }, true); UIUtil.addDecorationMargin(text); autoReload = new Button(composite, SWT.CHECK); autoReload.setText("Enable CDOEditor Auto-Reload"); + autoReload.setLayoutData(UIUtil.createGridData(false, false)); + UIUtil.setIndentation(autoReload, -1, 10); initValues(); return composite; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java index a21746d7ac..af33e51471 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java @@ -32,6 +32,7 @@ import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.ui.PlatformUI; import java.util.Set; @@ -124,6 +125,29 @@ public class CDOEventHandler refreshTreeViewer(); } } + else if (OM.PREF_LABEL_DECORATION.getName().equals(preferenceChangeEvent.getPreference().getName())) + { + // Fire a LabelProviderChangedEvent in case user changed decoration pattern + try + { + treeViewer.getControl().getDisplay().syncExec(new Runnable() + { + public void run() + { + try + { + PlatformUI.getWorkbench().getDecoratorManager().update(CDOLabelDecorator.DECORATOR_ID); + } + catch (Exception ignore) + { + } + } + }); + } + catch (Exception ignore) + { + } + } } }; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelDecorator.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelDecorator.java new file mode 100644 index 0000000000..464fc322d2 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelDecorator.java @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2008 Eike Stepper and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Victor Roldan Betancort - initial API and implementation + **************************************************************************/ +package org.eclipse.emf.cdo.ui; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.internal.ui.bundle.OM; + +import org.eclipse.emf.internal.cdo.InternalCDOObject; +import org.eclipse.emf.internal.cdo.InternalCDOView; +import org.eclipse.emf.internal.cdo.util.FSMUtil; + +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.om.pref.OMPreferencesChangeEvent; + +import org.eclipse.jface.viewers.ILabelDecorator; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; + +import java.text.MessageFormat; + +/** + * Decorates labels of {@link CDOObject CDO objects} according to a pattern. + * + * @author Victor Roldan Betancort + * @since 2.0 + */ +public class CDOLabelDecorator implements ILabelDecorator +{ + public static final String[] DECORATION_PROPOSALS = { "${element}", "${id}", "${state}", "${created}", "${revised}" }; + + public static final String DEFAULT_DECORATION = DECORATION_PROPOSALS[0] + " [" + DECORATION_PROPOSALS[1] + "]"; + + public static final String NO_DECORATION = DECORATION_PROPOSALS[0]; + + private static final String[] DECORATION_ARGS = { "{0}", "{1}", "{2}", "{3,date} {3,time}", "{4,date} {4,time}" }; + + public static final String DECORATOR_ID = "org.eclipse.emf.cdo.ui.cdolabeldecorator"; + + private String pattern; + + private IListener preferenceListener = new IListener() + { + public void notifyEvent(IEvent event) + { + @SuppressWarnings("unchecked") + OMPreferencesChangeEvent<String> preferenceChangeEvent = (OMPreferencesChangeEvent<String>)event; + if (OM.PREF_LABEL_DECORATION.getName().equals(preferenceChangeEvent.getPreference().getName())) + { + pattern = parsePattern(preferenceChangeEvent.getNewValue()); + } + } + }; + + public CDOLabelDecorator() + { + pattern = parsePattern(OM.PREF_LABEL_DECORATION.getValue()); + OM.PREFS.addListener(preferenceListener); + } + + public void dispose() + { + OM.PREFS.removeListener(preferenceListener); + } + + public String parsePattern(String unparsedPattern) + { + if (ObjectUtil.equals(unparsedPattern, NO_DECORATION)) + { + return null; + } + + return StringUtil.replace(unparsedPattern, DECORATION_PROPOSALS, DECORATION_ARGS); + } + + public CDOLabelDecorator(String pattern) + { + this.pattern = pattern; + } + + public Image decorateImage(Image image, Object element) + { + // Use default + return null; + } + + public String decorateText(String text, Object element) + { + try + { + if (pattern != null && element instanceof InternalCDOObject) + { + InternalCDOView view = ((InternalCDOObject)element).cdoView(); + InternalCDOObject obj = FSMUtil.adapt(element, view); + CDORevision rev = obj.cdoRevision(); + long created = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getCreated(); + long revised = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getRevised(); + text = MessageFormat.format(pattern, text, obj.cdoID(), obj.cdoState(), created, revised); + } + } + catch (RuntimeException ignore) + { + } + + return text; + } + + public boolean isLabelProperty(Object element, String property) + { + return false; + } + + public void addListener(ILabelProviderListener listener) + { + // Ignore listeners, DecoratorManager handles it + } + + public void removeListener(ILabelProviderListener listener) + { + // Ignore listeners, DecoratorManager handles it + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java index 61e0878d1f..c7963eedda 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java @@ -4,21 +4,17 @@ * 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: * Eike Stepper - initial API and implementation **************************************************************************/ package org.eclipse.emf.cdo.ui; import org.eclipse.emf.cdo.CDOView; -import org.eclipse.emf.cdo.common.revision.CDORevision; -import org.eclipse.emf.cdo.internal.ui.bundle.OM; import org.eclipse.emf.internal.cdo.InternalCDOObject; import org.eclipse.emf.internal.cdo.util.FSMUtil; -import org.eclipse.net4j.util.ObjectUtil; -import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.emf.common.notify.AdapterFactory; @@ -32,21 +28,11 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; -import java.text.MessageFormat; - /** * @author Eike Stepper */ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements IColorProvider, IFontProvider { - public static final String[] DECORATION_PROPOSALS = { "${element}", "${id}", "${state}", "${created}", "${revised}" }; - - public static final String DEFAULT_DECORATION = DECORATION_PROPOSALS[0] + " [" + DECORATION_PROPOSALS[1] + "]"; - - public static final String NO_DECORATION = DECORATION_PROPOSALS[0]; - - private static final String[] DECORATION_ARGS = { "{0}", "{1}", "{2}", "{3,date} {3,time}", "{4,date} {4,time}" }; - private static final Color GRAY = UIUtil.getDisplay().getSystemColor(SWT.COLOR_GRAY); private static final Color RED = UIUtil.getDisplay().getSystemColor(SWT.COLOR_RED); @@ -57,24 +43,12 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo private TreeViewer viewer; - private String pattern; - public CDOLabelProvider(AdapterFactory adapterFactory, CDOView view, TreeViewer viewer) { super(adapterFactory); this.view = view; this.viewer = viewer; bold = UIUtil.getBoldFont(viewer.getControl()); - - pattern = OM.PREF_LABEL_DECORATION.getValue(); - if (ObjectUtil.equals(pattern, NO_DECORATION)) - { - pattern = null; - } - else - { - pattern = StringUtil.replace(pattern, DECORATION_PROPOSALS, DECORATION_ARGS); - } } public CDOView getView() @@ -121,20 +95,9 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo } @Override - public String getText(Object object) - { - return decorateText(super.getText(object), object); - } - - @Override - public String getColumnText(Object object, int columnIndex) - { - return decorateText(super.getColumnText(object, columnIndex), object); - } - - @Override public Color getBackground(Object object) { + // Use default return null; } @@ -157,6 +120,7 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo { } + // Use default return null; } @@ -178,26 +142,7 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo { } + // Use default return null; } - - protected String decorateText(String text, Object object) - { - try - { - if (pattern != null) - { - InternalCDOObject obj = FSMUtil.adapt(object, view); - CDORevision rev = obj.cdoRevision(); - long created = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getCreated(); - long revised = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getRevised(); - text = MessageFormat.format(pattern, text, obj.cdoID(), obj.cdoState(), created, revised); - } - } - catch (RuntimeException ignore) - { - } - - return text; - } } |