summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-25 06:25:49 (EST)
committerEike Stepper2007-02-25 06:25:49 (EST)
commit859e4e780dfbfd9f0c168c7a4a1b55640cfc0b3d (patch)
treeadb613915d00c48dc1cb06ed838dadc74ca39c44
parent85fffaaa9c2b25243b6d9f7f5934b1247b591b97 (diff)
downloadcdo-859e4e780dfbfd9f0c168c7a4a1b55640cfc0b3d.zip
cdo-859e4e780dfbfd9f0c168c7a4a1b55640cfc0b3d.tar.gz
cdo-859e4e780dfbfd9f0c168c7a4a1b55640cfc0b3d.tar.bz2
Develop CDO2 - http://www.eclipse.org/emft/projects/cdo/#cdo
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsItemProvider.java50
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java154
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/StructuredView.java173
3 files changed, 260 insertions, 117 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsItemProvider.java
index 8b52810..3ecbcc6 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsItemProvider.java
@@ -10,10 +10,18 @@
**************************************************************************/
package org.eclipse.emf.cdo.internal.ui.views;
+import static org.eclipse.net4j.util.registry.IRegistryDelta.Kind.DEREGISTERED;
+import static org.eclipse.net4j.util.registry.IRegistryDelta.Kind.REGISTERED;
+
+import org.eclipse.emf.cdo.CDOAdapter;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.container.CDOContainerAdapter;
+import org.eclipse.emf.cdo.internal.container.CDOContainerAdapterImpl;
import org.eclipse.emf.cdo.internal.ui.bundle.SharedIcons;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.registry.IRegistryDelta;
import org.eclipse.net4j.util.registry.IRegistryEvent;
import org.eclipse.net4j.util.registry.IRegistryListener;
@@ -22,7 +30,7 @@ import org.eclipse.swt.graphics.Image;
import java.text.MessageFormat;
import java.util.Collection;
-public class CDOSessionsItemProvider extends ItemProvider<CDOContainerAdapter> implements IRegistryListener
+public class CDOSessionsItemProvider extends ItemProvider<CDOContainerAdapter> implements IRegistryListener, IListener
{
public CDOSessionsItemProvider()
{
@@ -35,6 +43,12 @@ public class CDOSessionsItemProvider extends ItemProvider<CDOContainerAdapter> i
return getInput();
}
+ if (child instanceof CDOAdapter)
+ {
+ CDOAdapter adapter = (CDOAdapter)child;
+ return adapter.getSession();
+ }
+
return null;
}
@@ -46,11 +60,41 @@ public class CDOSessionsItemProvider extends ItemProvider<CDOContainerAdapter> i
return values.toArray(new Object[values.size()]);
}
+ if (parent instanceof CDOSession)
+ {
+ CDOSession session = (CDOSession)parent;
+ return session.getAdapters();
+ }
+
return NO_CHILDREN;
}
public void notifyRegistryEvent(IRegistryEvent event)
{
+ IRegistryDelta[] deltas = event.getDeltas();
+ for (IRegistryDelta delta : deltas)
+ {
+ Object element = delta.getValue();
+ if (element instanceof CDOSession)
+ {
+ CDOSession session = (CDOSession)element;
+ switch (delta.getKind())
+ {
+ case REGISTERED:
+ session.addListener(this);
+ break;
+ case DEREGISTERED:
+ session.removeListener(this);
+ break;
+ }
+ }
+ }
+
+ refreshViewer(false);
+ }
+
+ public void notifyEvent(IEvent event)
+ {
refreshViewer(false);
}
@@ -60,8 +104,8 @@ public class CDOSessionsItemProvider extends ItemProvider<CDOContainerAdapter> i
if (obj instanceof CDOSession)
{
CDOSession session = (CDOSession)obj;
- return MessageFormat.format("[{0}] {1}@{2}", session.getSessionID(), session.getRepository().getName(), session
- .getChannel().getConnector().getDescription());
+ String description = CDOContainerAdapterImpl.getDescription(session);
+ return MessageFormat.format("[{0}] {1}", session.getSessionID(), description);
}
return super.getText(obj);
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
index 279d6d6..c68b29a 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
@@ -9,33 +9,18 @@ import org.eclipse.net4j.container.ContainerManager;
import org.eclipse.net4j.transport.ConnectorException;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.IContributionManager;
-import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.ViewPart;
-public class CDOSessionsView extends ViewPart
+public class CDOSessionsView extends StructuredView
{
private static final Container CONTAINER = ContainerManager.INSTANCE.getContainer();
@@ -43,21 +28,18 @@ public class CDOSessionsView extends ViewPart
private static final ItemProvider ITEM_PROVIDER = new CDOSessionsItemProvider();
- private StructuredViewer viewer;
-
- // private DrillDownAdapter drillDownAdapter;
-
- private Action doubleClickAction = new DoubleClickAction();
+ private TreeViewer viewer;
private Action openSessionAction = new OpenSessionAction();
- private Action addConnectorAction;
+ private Action attachAdapterAction = new AttachAdapterAction();
public CDOSessionsView()
{
}
- public void createPartControl(Composite parent)
+ @Override
+ protected void doCreatePartControl(Composite parent)
{
viewer = new TreeViewer(parent, (SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL));
viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
@@ -67,126 +49,70 @@ public class CDOSessionsView extends ViewPart
viewer.setLabelProvider(ITEM_PROVIDER);
viewer.setSorter(new CDOSessionsNameSorter());
viewer.setInput(CDO_ADAPTER);
-
- hookContextMenu();
- hookDoubleClickAction();
- contributeToActionBars();
- }
-
- private void hookContextMenu()
- {
- MenuManager menuMgr = new MenuManager("#PopupMenu");
- menuMgr.setRemoveAllWhenShown(true);
- menuMgr.addMenuListener(new IMenuListener()
- {
- public void menuAboutToShow(IMenuManager manager)
- {
- CDOSessionsView.this.fillContextMenu(manager);
- }
- });
-
- Menu menu = menuMgr.createContextMenu(getCurrentViewer().getControl());
- getCurrentViewer().getControl().setMenu(menu);
- getSite().registerContextMenu(menuMgr, getCurrentViewer());
}
- private StructuredViewer getCurrentViewer()
+ @Override
+ protected StructuredViewer getCurrentViewer()
{
return viewer;
}
- private void contributeToActionBars()
- {
- IActionBars bars = getViewSite().getActionBars();
- fillLocalPullDown(bars.getMenuManager());
- fillLocalToolBar(bars.getToolBarManager());
- }
-
- private void fillLocalPullDown(IMenuManager manager)
+ @Override
+ protected void fillLocalPullDown(IMenuManager manager)
{
addContribution(manager, openSessionAction);
- addContribution(manager, addConnectorAction);
- // manager.add(new Separator());
- // manager.add(action2);
+ addContribution(manager, attachAdapterAction);
+ super.fillLocalPullDown(manager);
}
- private void fillContextMenu(IMenuManager manager)
- {
- // manager.add(action2);
- // manager.add(new Separator());
- // drillDownAdapter.addNavigationActions(manager);
-
- // Other plug-ins can contribute there actions here
- manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
- }
-
- private void fillLocalToolBar(IToolBarManager manager)
+ @Override
+ protected void fillLocalToolBar(IToolBarManager manager)
{
addContribution(manager, openSessionAction);
- addContribution(manager, addConnectorAction);
- // manager.add(new Separator());
- // drillDownAdapter.addNavigationActions(manager);
+ addContribution(manager, attachAdapterAction);
+ super.fillLocalToolBar(manager);
}
- protected void addContribution(IContributionManager manager, IContributionItem item)
+ /**
+ * @author Eike Stepper
+ */
+ private final class OpenSessionAction extends Action
{
- if (manager != null && item != null)
+ public OpenSessionAction()
{
- manager.add(item);
+ setText("Open Session");
+ setToolTipText("Open a CDO session");
+ setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_TOOL_NEW_WIZARD));
}
- }
- protected void addContribution(IContributionManager manager, IAction action)
- {
- if (manager != null && action != null)
- {
- manager.add(action);
- }
- }
-
- private void hookDoubleClickAction()
- {
- getCurrentViewer().addDoubleClickListener(new IDoubleClickListener()
+ public void run()
{
- public void doubleClick(DoubleClickEvent event)
+ String description = showInputDialog("Enter a session description");
+ if (description != null)
{
- doubleClickAction.run();
+ try
+ {
+ CDO_ADAPTER.getSession(description);
+ }
+ catch (ConnectorException ex)
+ {
+ CDOUI.LOG.error(ex);
+ showMessage("Error while creating session for description " + description);
+ }
}
- });
- }
-
- protected void showMessage(String message)
- {
- MessageDialog.openInformation(getCurrentViewer().getControl().getShell(), "Net4j Explorer", message);
- }
-
- public void setFocus()
- {
- getCurrentViewer().getControl().setFocus();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class DoubleClickAction extends Action
- {
- public void run()
- {
- ISelection selection = getCurrentViewer().getSelection();
- Object obj = ((IStructuredSelection)selection).getFirstElement();
- showMessage("Double-click detected on " + obj.toString());
}
}
/**
* @author Eike Stepper
*/
- private final class OpenSessionAction extends Action
+ private final class AttachAdapterAction extends Action
{
- public OpenSessionAction()
+ public AttachAdapterAction()
{
- setText("Open Session");
- setToolTipText("Open a CDO session");
+ setText("Attach Adapter");
+ setToolTipText("Attach a CDO adapter");
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_NEW_WIZARD));
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/StructuredView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/StructuredView.java
new file mode 100644
index 0000000..ec6d429
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/StructuredView.java
@@ -0,0 +1,173 @@
+package org.eclipse.emf.cdo.internal.ui.views;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.part.ViewPart;
+
+public abstract class StructuredView extends ViewPart
+{
+ private Action doubleClickAction = createDoubleClickAction();
+
+ public StructuredView()
+ {
+ }
+
+ public void setFocus()
+ {
+ StructuredViewer viewer = getCurrentViewer();
+ if (viewer != null)
+ {
+ viewer.getControl().setFocus();
+ }
+ }
+
+ public final void createPartControl(Composite parent)
+ {
+ doCreatePartControl(parent);
+ hookContextMenu();
+ hookDoubleClickAction();
+ contributeToActionBars();
+ }
+
+ protected abstract StructuredViewer getCurrentViewer();
+
+ protected abstract void doCreatePartControl(Composite parent);
+
+ protected Action createDoubleClickAction()
+ {
+ return new DoubleClickAction();
+ }
+
+ protected void fillLocalPullDown(IMenuManager manager)
+ {
+ }
+
+ protected void fillLocalToolBar(IToolBarManager manager)
+ {
+ }
+
+ protected void fillContextMenu(IMenuManager manager)
+ {
+ manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+
+ protected void addContribution(IContributionManager manager, IContributionItem item)
+ {
+ if (manager != null && item != null)
+ {
+ manager.add(item);
+ }
+ }
+
+ protected void addContribution(IContributionManager manager, IAction action)
+ {
+ if (manager != null && action != null)
+ {
+ manager.add(action);
+ }
+ }
+
+ protected void showMessage(String message)
+ {
+ MessageDialog.openInformation(getShell(), getTitle(), message);
+ }
+
+ protected String showInputDialog(String message)
+ {
+ return showInputDialog(message, null);
+ }
+
+ protected String showInputDialog(String message, String defaultValue)
+ {
+ if (!message.endsWith(":"))
+ {
+ message += ":";
+ }
+
+ InputDialog dialog = new InputDialog(getShell(), getTitle(), message, defaultValue, null);
+ if (dialog.open() == InputDialog.OK)
+ {
+ return dialog.getValue();
+ }
+
+ return null;
+ }
+
+ protected Shell getShell()
+ {
+ return getCurrentViewer().getControl().getShell();
+ }
+
+ private void contributeToActionBars()
+ {
+ IActionBars bars = getViewSite().getActionBars();
+ fillLocalPullDown(bars.getMenuManager());
+ fillLocalToolBar(bars.getToolBarManager());
+ }
+
+ private void hookContextMenu()
+ {
+ MenuManager menuMgr = new MenuManager("#PopupMenu");
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ StructuredView.this.fillContextMenu(manager);
+ }
+ });
+
+ Menu menu = menuMgr.createContextMenu(getCurrentViewer().getControl());
+ getCurrentViewer().getControl().setMenu(menu);
+ getSite().registerContextMenu(menuMgr, getCurrentViewer());
+ }
+
+ private void hookDoubleClickAction()
+ {
+ getCurrentViewer().addDoubleClickListener(new IDoubleClickListener()
+ {
+ public void doubleClick(DoubleClickEvent event)
+ {
+ doubleClickAction.run();
+ }
+ });
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class DoubleClickAction extends Action
+ {
+ public void run()
+ {
+ StructuredViewer viewer = getCurrentViewer();
+ if (viewer instanceof TreeViewer)
+ {
+ TreeViewer treeViewer = (TreeViewer)viewer;
+ ISelection selection = viewer.getSelection();
+ Object obj = ((IStructuredSelection)selection).getFirstElement();
+ treeViewer.setExpandedState(obj, !treeViewer.getExpandedState(obj));
+ }
+ }
+ }
+} \ No newline at end of file