Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2015-04-28 12:13:36 +0000
committerEike Stepper2015-04-28 12:13:36 +0000
commit84b2faf3ad89eb903998b733796ec8c78e8e8de2 (patch)
treea096a28b9dd4218471bb203b2689e94f520640d2 /plugins/org.eclipse.emf.cdo.ui
parented36d8dab2d94cd4ebdb0b68ea9c062ae66fa7cb (diff)
downloadcdo-84b2faf3ad89eb903998b733796ec8c78e8e8de2.tar.gz
cdo-84b2faf3ad89eb903998b733796ec8c78e8e8de2.tar.xz
cdo-84b2faf3ad89eb903998b733796ec8c78e8e8de2.zip
[458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui')
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java190
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOTreeExpansionAgent.java183
3 files changed, 216 insertions, 163 deletions
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 5c4221dbdb..4119321321 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
@@ -13,25 +13,22 @@
package org.eclipse.emf.cdo.internal.ui.editor;
import org.eclipse.emf.cdo.CDOObject;
-import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.model.CDOPackageInfo;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.ui.bundle.OM;
import org.eclipse.emf.cdo.internal.ui.dialogs.BulkAddDialog;
import org.eclipse.emf.cdo.internal.ui.dialogs.RollbackTransactionDialog;
import org.eclipse.emf.cdo.internal.ui.messages.Messages;
-import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.ui.CDOEditorInput;
import org.eclipse.emf.cdo.ui.CDOEventHandler;
-import org.eclipse.emf.cdo.ui.CDOLabelProvider;
import org.eclipse.emf.cdo.ui.CDOInvalidRootAgent;
+import org.eclipse.emf.cdo.ui.CDOLabelProvider;
+import org.eclipse.emf.cdo.ui.CDOTreeExpansionAgent;
import org.eclipse.emf.cdo.ui.shared.SharedIcons;
-import org.eclipse.emf.cdo.ui.widgets.TimeSlider;
import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ValidationException;
@@ -41,7 +38,6 @@ import org.eclipse.emf.internal.cdo.view.CDOStateMachine;
import org.eclipse.net4j.util.AdapterUtil;
import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.actions.LongRunningAction;
import org.eclipse.net4j.util.ui.actions.SafeAction;
@@ -128,11 +124,8 @@ import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
@@ -224,6 +217,11 @@ public class CDOEditor extends MultiPageEditorPart
/**
* @ADDED
*/
+ protected CDOTreeExpansionAgent treeExpansionAgent;
+
+ /**
+ * @ADDED
+ */
protected CDOEventHandler eventHandler;
/**
@@ -1167,152 +1165,8 @@ public class CDOEditor extends MultiPageEditorPart
// Creates the model from the editor input
createModel();
- // Create a page for the selection tree view.
- getContainer().setLayoutData(UIUtil.createGridData());
- getContainer().setLayout(UIUtil.createGridLayout(1));
-
- final Composite composite = UIUtil.createGridComposite(getContainer(), 1);
- composite.setLayoutData(UIUtil.createGridData());
- composite.setLayout(UIUtil.createGridLayout(1));
-
- Tree tree = new Tree(composite, SWT.MULTI);
- tree.setLayoutData(UIUtil.createGridData());
-
- final boolean timeSliderAllowed = view.isReadOnly() && view.getSession().getRepositoryInfo().isSupportingAudits();
- if (timeSliderAllowed)
- {
- final IAction toolbarToggleAction = new Action()
- {
- private Group group;
-
- private TimeSlider timeSlider;
-
- @Override
- public void run()
- {
- if (group == null)
- {
- group = new Group(composite, SWT.NONE);
- group.setLayoutData(new GridData(SWT.FILL, 50, true, false));
- group.setLayout(new FillLayout());
- group.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
-
- timeSlider = new TimeSlider(group, SWT.HORIZONTAL)
- {
- @Override
- protected void timeStampChanged(long timeStamp)
- {
- super.timeStampChanged(timeStamp);
- group.setText(formatTimeSliderLabel(timeStamp));
- }
- };
-
- timeSlider.connect(view, selectionViewer);
- group.setText(formatTimeSliderLabel(timeSlider.getTimeStamp()));
- }
- else
- {
- timeSlider.disconnect();
- group.dispose();
- group = null;
- timeSlider = null;
- }
-
- composite.layout();
- }
- };
-
- final String id = "time-slider-" + System.currentTimeMillis();
- toolbarToggleAction.setId(id);
- toolbarToggleAction.setEnabled(true);
- toolbarToggleAction.setChecked(false);
- toolbarToggleAction.setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.ETOOL_SLIDER));
- toolbarToggleAction.setToolTipText(Messages.getString("CDOEditor.1")); //$NON-NLS-1$
-
- getSite().getPage().addPartListener(new IPartListener()
- {
- private IToolBarManager toolBarManager = getActionBars().getToolBarManager();
-
- public void partActivated(IWorkbenchPart part)
- {
- showToggleAction(part, true);
- }
-
- public void partDeactivated(IWorkbenchPart part)
- {
- showToggleAction(part, false);
- }
-
- private void showToggleAction(IWorkbenchPart part, boolean show)
- {
- if (part == CDOEditor.this)
- {
- if (show)
- {
- toolBarManager.add(toolbarToggleAction);
- }
- else
- {
- toolBarManager.remove(id);
- }
-
- toolBarManager.update(true);
- }
- }
-
- public void partClosed(IWorkbenchPart part)
- {
- // Do nothing.
- }
-
- public void partOpened(IWorkbenchPart part)
- {
- // Do nothing.
- }
-
- public void partBroughtToTop(IWorkbenchPart part)
- {
- // Do nothing.
- }
- });
- }
-
- selectionViewer = new TreeViewer(tree)
- {
- @Override
- public void setSelection(ISelection selection, boolean reveal)
- {
- if (timeSliderAllowed && selection instanceof IStructuredSelection)
- {
- IStructuredSelection ssel = (IStructuredSelection)selection;
- for (Iterator<?> it = ssel.iterator(); it.hasNext();)
- {
- Object object = it.next();
- if (object instanceof EObject)
- {
- CDOObject cdoObject = CDOUtil.getCDOObject((EObject)object);
- switch (cdoObject.cdoState())
- {
- case TRANSIENT:
- case PREPARED:
- case INVALID:
- case INVALID_CONFLICT:
- it.remove();
- }
- }
- }
- }
-
- super.setSelection(selection, reveal);
- }
-
- @Override
- public String toString()
- {
- return "SelectionViewer";
- }
- };
-
+ Tree tree = new Tree(getContainer(), SWT.MULTI);
+ selectionViewer = new TreeViewer(tree);
setCurrentViewer(selectionViewer);
selectionViewer.setContentProvider(createContentProvider());
@@ -1322,7 +1176,7 @@ public class CDOEditor extends MultiPageEditorPart
new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
createContextMenuFor(selectionViewer);
- int pageIndex = addPage(composite);
+ int pageIndex = addPage(tree);
setPageText(pageIndex, getString("_UI_SelectionPage_label")); //$NON-NLS-1$
setActivePage(0);
@@ -1442,6 +1296,11 @@ public class CDOEditor extends MultiPageEditorPart
throw ex;
}
+ if (view.isReadOnly())
+ {
+ treeExpansionAgent = new CDOTreeExpansionAgent(view, selectionViewer);
+ }
+
getViewer().getControl().addMouseListener(new MouseListener()
{
public void mouseDoubleClick(MouseEvent e)
@@ -1468,12 +1327,6 @@ public class CDOEditor extends MultiPageEditorPart
});
}
- protected String formatTimeSliderLabel(long timeStamp)
- {
- CDOBranchPoint branchPoint = CDOBranchUtil.normalizeBranchPoint(view.getBranch(), timeStamp);
- return branchPoint.getBranch().getPathName() + " [" + CDOCommonUtil.formatTimeStamp(timeStamp) + "]";
- }
-
/**
* @ADDED
*/
@@ -2306,7 +2159,18 @@ public class CDOEditor extends MultiPageEditorPart
public void dispose()
{
updateProblemIndication = false;
- invalidRootAgent.dispose();
+
+ if (treeExpansionAgent != null)
+ {
+ treeExpansionAgent.dispose();
+ treeExpansionAgent = null;
+ }
+
+ if (invalidRootAgent != null)
+ {
+ invalidRootAgent.dispose();
+ invalidRootAgent = null;
+ }
if (!view.isClosed())
{
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java
index d0bdd867f6..f07fd6a7e1 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java
@@ -116,4 +116,10 @@ public class CDOTimeMachineView extends ViewPart implements ISelectionListener
return null;
}
+
+ // protected String formatTimeSliderLabel(long timeStamp)
+ // {
+ // CDOBranchPoint branchPoint = CDOBranchUtil.normalizeBranchPoint(view.getBranch(), timeStamp);
+ // return branchPoint.getBranch().getPathName() + " [" + CDOCommonUtil.formatTimeStamp(timeStamp) + "]";
+ // }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOTreeExpansionAgent.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOTreeExpansionAgent.java
new file mode 100644
index 0000000000..d8fb112eaf
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOTreeExpansionAgent.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.ui;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent;
+
+import org.eclipse.net4j.util.CheckUtil;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.ILifecycleEvent.Kind;
+
+import org.eclipse.emf.ecore.EObject;
+
+import org.eclipse.jface.viewers.ITreeViewerListener;
+import org.eclipse.jface.viewers.TreeExpansionEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Tree;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ * @since 4.4
+ */
+public class CDOTreeExpansionAgent
+{
+ private final Listener listener = new Listener();
+
+ private final Set<CDOID> expandedIDs = new HashSet<CDOID>();
+
+ private final CDOView view;
+
+ private final TreeViewer viewer;
+
+ public CDOTreeExpansionAgent(final CDOView view, final TreeViewer viewer)
+ {
+ CheckUtil.checkArg(view, "view");
+ CheckUtil.checkArg(viewer, "viewer");
+
+ this.view = view;
+ this.viewer = viewer;
+
+ final Tree tree = viewer.getTree();
+ if (!tree.isDisposed())
+ {
+ tree.getDisplay().syncExec(new Runnable()
+ {
+ public void run()
+ {
+ for (Object element : viewer.getExpandedElements())
+ {
+ CDOID id = getID(element);
+ if (id != null)
+ {
+ expandedIDs.add(id);
+ }
+ }
+
+ view.addListener(listener);
+ viewer.addTreeListener(listener);
+ viewer.getTree().addDisposeListener(listener);
+ }
+ });
+ }
+ }
+
+ public void setExpandedStates()
+ {
+ for (CDOID id : expandedIDs)
+ {
+ try
+ {
+ CDOObject object = view.getObject(id);
+ viewer.setExpandedState(object, true);
+ }
+ catch (Exception ex)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ public void dispose()
+ {
+ Tree tree = viewer.getTree();
+ if (!tree.isDisposed())
+ {
+ tree.removeDisposeListener(listener);
+ }
+
+ viewer.removeTreeListener(listener);
+ view.removeListener(listener);
+ expandedIDs.clear();
+ }
+
+ private CDOID getID(Object element)
+ {
+ if (element instanceof EObject)
+ {
+ CDOObject object = CDOUtil.getCDOObject((EObject)element, false);
+ if (object != null && object.cdoView() == view)
+ {
+ return object.cdoID();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class Listener implements IListener, ITreeViewerListener, DisposeListener
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof CDOViewTargetChangedEvent)
+ {
+ final Tree tree = viewer.getTree();
+ if (!tree.isDisposed())
+ {
+ tree.getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (!tree.isDisposed() && !view.isClosed())
+ {
+ setExpandedStates();
+ }
+ }
+ });
+ }
+ }
+ else if (event instanceof ILifecycleEvent)
+ {
+ ILifecycleEvent e = (ILifecycleEvent)event;
+ if (e.getKind() == Kind.ABOUT_TO_DEACTIVATE)
+ {
+ dispose();
+ }
+ }
+ }
+
+ public void treeExpanded(TreeExpansionEvent event)
+ {
+ CDOID id = getID(event.getElement());
+ if (id != null)
+ {
+ expandedIDs.add(id);
+ }
+ }
+
+ public void treeCollapsed(TreeExpansionEvent event)
+ {
+ CDOID id = getID(event.getElement());
+ if (id != null)
+ {
+ expandedIDs.remove(id);
+ }
+ }
+
+ public void widgetDisposed(DisposeEvent e)
+ {
+ dispose();
+ }
+ }
+}

Back to the top