summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-02 06:30:36 (EDT)
committerEike Stepper2007-07-02 06:30:36 (EDT)
commit9a3e455cc925d4c73665e5920b9485a7a8254273 (patch)
tree9438ac01a314691af7bb40563e024073736bb0b6
parent8c0ce1f30e6fd4e85f76ddd873bebdcdce92519e (diff)
downloadcdo-9a3e455cc925d4c73665e5920b9485a7a8254273.zip
cdo-9a3e455cc925d4c73665e5920b9485a7a8254273.tar.gz
cdo-9a3e455cc925d4c73665e5920b9485a7a8254273.tar.bz2
task 1: Develop 0.8.0
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java116
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java207
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java173
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java2
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/actions/LongRunningAction.java70
-rw-r--r--plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/views/ContainerItemProvider.java55
6 files changed, 500 insertions, 123 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 eafe1f7..3a36bff 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
@@ -896,41 +896,49 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
*/
public void createModel()
{
- CDOEditorInput input = (CDOEditorInput)getEditorInput();
- adapter = input.getView();
- URI resourceURI = CDOUtil.createURI(input.getResourcePath());
-
- BasicCommandStack commandStack = new BasicCommandStack();
- commandStack.addCommandStackListener(new CommandStackListener()
+ try
{
- public void commandStackChanged(final EventObject event)
+ CDOEditorInput input = (CDOEditorInput)getEditorInput();
+ adapter = input.getView();
+ URI resourceURI = CDOUtil.createURI(input.getResourcePath());
+
+ BasicCommandStack commandStack = new BasicCommandStack();
+ commandStack.addCommandStackListener(new CommandStackListener()
{
- getContainer().getDisplay().asyncExec(new Runnable()
+ public void commandStackChanged(final EventObject event)
{
- public void run()
+ getContainer().getDisplay().asyncExec(new Runnable()
{
- firePropertyChange(IEditorPart.PROP_DIRTY);
-
- Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
- if (mostRecentCommand != null)
+ public void run()
{
- setSelectionToViewer(mostRecentCommand.getAffectedObjects());
- }
- if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed())
- {
- propertySheetPage.refresh();
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+
+ Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
+ if (mostRecentCommand != null)
+ {
+ setSelectionToViewer(mostRecentCommand.getAffectedObjects());
+ }
+ if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed())
+ {
+ propertySheetPage.refresh();
+ }
}
- }
- });
- }
- });
+ });
+ }
+ });
- ResourceSet resourceSet = adapter.getResourceSet();
- editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);
- editingDomain.setResourceToReadOnlyMap(new HashMap<Resource, Boolean>());
+ ResourceSet resourceSet = adapter.getResourceSet();
+ editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, resourceSet);
+ editingDomain.setResourceToReadOnlyMap(new HashMap<Resource, Boolean>());
- resourceSet.getResource(resourceURI, true);
- resourceSet.eAdapters().add(problemIndicationAdapter);
+ resourceSet.getResource(resourceURI, true);
+ resourceSet.eAdapters().add(problemIndicationAdapter);
+ }
+ catch (RuntimeException ex)
+ {
+ ex.printStackTrace();
+ throw ex;
+ }
}
/**
@@ -965,7 +973,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
* This is the method used by the framework to install your own controls. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
- * @generated
+ * @generated NOT
*/
@Override
public void createPages()
@@ -976,28 +984,29 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
// Only creates the other pages if there is something that can be edited
//
- if (!getEditingDomain().getResourceSet().getResources().isEmpty()
- && !(getEditingDomain().getResourceSet().getResources().get(0)).getContents().isEmpty())
- {
- // Create a page for the selection tree view.
- //
- Tree tree = new Tree(getContainer(), SWT.MULTI);
- selectionViewer = new TreeViewer(tree);
- setCurrentViewer(selectionViewer);
+ // if (!getEditingDomain().getResourceSet().getResources().isEmpty()
+ // &&
+ // !getEditingDomain().getResourceSet().getResources().get(0).getContents().isEmpty())
+ // {
+ // Create a page for the selection tree view.
+ //
+ Tree tree = new Tree(getContainer(), SWT.MULTI);
+ selectionViewer = new TreeViewer(tree);
+ setCurrentViewer(selectionViewer);
- selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
- selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
- selectionViewer.setInput(editingDomain.getResourceSet());
- selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
+ selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
+ selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
+ selectionViewer.setInput(editingDomain.getResourceSet());
+ selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
- new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
+ new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
- createContextMenuFor(selectionViewer);
- int pageIndex = addPage(tree);
- setPageText(pageIndex, getString("_UI_SelectionPage_label"));
+ createContextMenuFor(selectionViewer);
+ int pageIndex = addPage(tree);
+ setPageText(pageIndex, getString("_UI_SelectionPage_label"));
- setActivePage(0);
- }
+ setActivePage(0);
+ // }
// Ensures that this editor will only display the page's tab
// area if there are more than one page
@@ -1387,7 +1396,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
*/
protected void doSaveAs(URI uri, IEditorInput editorInput)
{
- (editingDomain.getResourceSet().getResources().get(0)).setURI(uri);
+ editingDomain.getResourceSet().getResources().get(0).setURI(uri);
setInputWithNotify(editorInput);
setPartName(editorInput.getName());
IProgressMonitor progressMonitor = getActionBars().getStatusLineManager() != null ? getActionBars()
@@ -1659,17 +1668,22 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
/**
* @ADDED
*/
- public static CDOEditor open(IWorkbenchPage page, CDOView adapter, String resourcePath)
+ public static CDOEditor open(IWorkbenchPage page, CDOView view, String resourcePath)
{
try
{
- IEditorInput input = new CDOEditorInput(adapter, resourcePath);
- return (CDOEditor)page.openEditor(input, EDITOR_ID);
+ IEditorInput input = new CDOEditorInput(view, resourcePath);
+ IEditorPart editor = page.openEditor(input, EDITOR_ID);
+ if (editor instanceof CDOEditor)
+ {
+ return (CDOEditor)editor;
+ }
}
catch (Exception ex)
{
CDOUI.LOG.error(ex);
- return null;
}
+
+ return null;
}
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java
index 5205e18..a21c500 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java
@@ -14,23 +14,33 @@ import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.internal.ui.ResourceHistory;
import org.eclipse.emf.cdo.internal.ui.bundle.SharedIcons;
+import org.eclipse.emf.cdo.internal.ui.editor.CDOEditor;
+import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory.Entry;
import org.eclipse.net4j.IConnector;
import org.eclipse.net4j.ui.actions.LongRunningAction;
import org.eclipse.net4j.ui.views.ContainerItemProvider;
import org.eclipse.net4j.ui.views.IElementFilter;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.ISetSelectionTarget;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
/**
* @author Eike Stepper
@@ -39,10 +49,17 @@ public class CDOItemProvider extends ContainerItemProvider
{
private IWorkbenchPage page;
- public CDOItemProvider(IWorkbenchPage page)
+ private Map<CDOView, CDOViewHistory> viewHistories = new HashMap();
+
+ private IListener historyListener = new IListener()
{
- this(page, null);
- }
+ public void notifyEvent(IEvent event)
+ {
+ CDOViewHistory history = (CDOViewHistory)event.getSource();
+ CDOView view = history.getView();
+ refreshElement(view, false);
+ }
+ };
public CDOItemProvider(IWorkbenchPage page, IElementFilter rootElementFilter)
{
@@ -50,19 +67,59 @@ public class CDOItemProvider extends ContainerItemProvider
this.page = page;
}
+ public CDOItemProvider(IWorkbenchPage page)
+ {
+ this(page, null);
+ }
+
@Override
public Object[] getChildren(Object element)
{
if (element instanceof CDOView)
{
CDOView view = (CDOView)element;
- return getResources(view);
+ CDOViewHistory history = viewHistories.get(view);
+ if (history != null)
+ {
+ return history.getEntries();
+ }
+
+ return NO_CHILDREN;
}
return super.getChildren(element);
}
@Override
+ public boolean hasChildren(Object element)
+ {
+ if (element instanceof CDOView)
+ {
+ CDOView view = (CDOView)element;
+ CDOViewHistory history = viewHistories.get(view);
+ if (history != null)
+ {
+ return history.hasEntries();
+ }
+
+ return false;
+ }
+
+ return super.hasChildren(element);
+ }
+
+ @Override
+ public Object getParent(Object element)
+ {
+ if (element instanceof CDOViewHistory.Entry)
+ {
+ return ((CDOViewHistory.Entry)element).getView();
+ }
+
+ return super.getParent(element);
+ }
+
+ @Override
public String getText(Object obj)
{
if (obj instanceof CDOSession)
@@ -119,40 +176,109 @@ public class CDOItemProvider extends ContainerItemProvider
Object object = selection.getFirstElement();
if (object instanceof CDOSession)
{
- CDOSession session = (CDOSession)object;
- manager.add(new OpenViewAction("Open Transaction", "Open a CDO transaction", session)
+ fillSession(manager, (CDOSession)object);
+ }
+ else if (object instanceof CDOView)
+ {
+ fillView(manager, (CDOView)object);
+ }
+ else if (object instanceof CDOViewHistory.Entry)
+ {
+ fillHistoryEntry(manager, (CDOViewHistory.Entry)object);
+ }
+ }
+ }
+
+ protected void fillSession(IMenuManager manager, CDOSession session)
+ {
+ manager.add(new OpenViewAction("Open Transaction", "Open a CDO transaction", session)
+ {
+ @Override
+ protected CDOView createView()
+ {
+ return getSession().openView(new ResourceSetImpl());
+ }
+ });
+
+ manager.add(new OpenViewAction("Open View", "Open a read-only CDO view", session)
+ {
+ @Override
+ protected CDOView createView()
+ {
+ return getSession().openView(new ResourceSetImpl(), true);
+ }
+ });
+
+ manager.add(new OpenViewAction("Open Historical View", "Open a historical CDO view", session)
+ {
+ @Override
+ protected CDOView createView()
+ {
+ return getSession().openView(new ResourceSetImpl(), System.currentTimeMillis());
+ }
+ });
+ }
+
+ protected void fillView(IMenuManager manager, final CDOView view)
+ {
+ if (view.isReadWrite())
+ {
+ manager.add(new LongRunningAction(page, "Create Resource", "Create a CDO resource", null)
+ {
+ private String resourcePath;
+
+ @Override
+ protected void preRun(IWorkbenchPage page) throws Exception
{
- @Override
- protected CDOView createView()
+ InputDialog dialog = new InputDialog(page.getWorkbenchWindow().getShell(), "Create Resource",
+ "Enter resource path:", "/res" + (int)Math.random(), null);
+ if (dialog.open() == InputDialog.OK)
{
- return getSession().openView(new ResourceSetImpl());
+ resourcePath = dialog.getValue();
}
- });
-
- manager.add(new OpenViewAction("Open View", "Open a read-only CDO view", session)
- {
- @Override
- protected CDOView createView()
+ else
{
- return getSession().openView(new ResourceSetImpl(), true);
+ cancel();
}
- });
+ }
- manager.add(new OpenViewAction("Open Historical View", "Open a historical CDO view", session)
+ @Override
+ protected void doRun(final IWorkbenchPage page, IProgressMonitor monitor) throws Exception
{
- @Override
- protected CDOView createView()
+ final Exception[] exception = new Exception[1];
+ view.createResource(resourcePath);
+ final IWorkbenchPart part = page.getActivePart();
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (part instanceof ISetSelectionTarget)
+ {
+ ((ISetSelectionTarget)part).selectReveal(new StructuredSelection(view));
+ }
+
+ CDOEditor.open(page, view, resourcePath);
+ }
+ catch (Exception ex)
+ {
+ exception[0] = ex;
+ }
+ }
+ });
+
+ if (exception[0] != null)
{
- return getSession().openView(new ResourceSetImpl(), System.currentTimeMillis());
+ throw exception[0];
}
- });
- }
+ }
+ });
}
}
- public static ImageDescriptor getOpenEditorImageDescriptor()
+ protected void fillHistoryEntry(IMenuManager manager, Entry entry)
{
- return SharedIcons.getDescriptor(SharedIcons.ETOOL_OPEN_EDITOR);
}
@Override
@@ -177,11 +303,42 @@ public class CDOItemProvider extends ContainerItemProvider
return display;
}
+ @Override
+ protected void elementAdded(Object element, Object parent)
+ {
+ super.elementAdded(element, parent);
+ if (element instanceof CDOView)
+ {
+ CDOView view = (CDOView)element;
+ CDOViewHistory history = new CDOViewHistory(view);
+ history.addListener(historyListener);
+ viewHistories.put(view, history);
+ }
+ }
+
+ @Override
+ protected void elementRemoved(Object element, Object parent)
+ {
+ super.elementRemoved(element, parent);
+ if (element instanceof CDOView)
+ {
+ CDOView view = (CDOView)element;
+ CDOViewHistory history = viewHistories.remove(view);
+ history.removeListener(historyListener);
+ history.dispose();
+ }
+ }
+
protected Object[] getResources(CDOView view)
{
return ResourceHistory.INSTANCE.getEntries(view);
}
+ public static ImageDescriptor getOpenEditorImageDescriptor()
+ {
+ return SharedIcons.getDescriptor(SharedIcons.ETOOL_OPEN_EDITOR);
+ }
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java
new file mode 100644
index 0000000..fec0b3d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java
@@ -0,0 +1,173 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.internal.ui.views;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.CDOViewResourcesEvent;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+
+import org.eclipse.net4j.internal.util.event.Event;
+import org.eclipse.net4j.internal.util.event.Notifier;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+
+import org.eclipse.emf.ecore.resource.Resource;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public final class CDOViewHistory extends Notifier
+{
+ private CDOView view;
+
+ private Set<Entry> entries = new HashSet();
+
+ private IListener viewListener = new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof CDOViewResourcesEvent)
+ {
+ CDOViewResourcesEvent e = (CDOViewResourcesEvent)event;
+ if (e.getView() == view && e.getKind() == CDOViewResourcesEvent.Kind.ADDED)
+ {
+ addResource(e.getResourcePath());
+ }
+ }
+ }
+ };
+
+ public CDOViewHistory(CDOView view)
+ {
+ this.view = view;
+ view.addListener(viewListener);
+ }
+
+ public void dispose()
+ {
+ view.removeListener(viewListener);
+ entries.clear();
+ }
+
+ public CDOView getView()
+ {
+ return view;
+ }
+
+ public Entry[] getEntries()
+ {
+ synchronized (entries)
+ {
+ return entries.toArray(new Entry[entries.size()]);
+ }
+ }
+
+ public boolean hasEntries()
+ {
+ synchronized (entries)
+ {
+ return !entries.isEmpty();
+ }
+ }
+
+ public void reset()
+ {
+ Set<Entry> openResources = new HashSet();
+ for (Resource resource : view.getResourceSet().getResources())
+ {
+ if (resource instanceof CDOResource)
+ {
+ CDOResource cdoResource = (CDOResource)resource;
+ openResources.add(new Entry(cdoResource.getPath()));
+ }
+ }
+
+ boolean changed;
+ synchronized (entries)
+ {
+ changed = entries.retainAll(openResources);
+ }
+
+ if (changed)
+ {
+ fireEvent(new Event(this));
+ }
+ }
+
+ protected void addResource(String resourcePath)
+ {
+ Entry entry = new Entry(resourcePath);
+ boolean changed;
+ synchronized (entries)
+ {
+ changed = entries.add(entry);
+ }
+
+ if (changed)
+ {
+ fireEvent(new Event(this));
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public final class Entry implements Comparable
+ {
+ private String resourcePath;
+
+ public Entry(String resourcePath)
+ {
+ if (resourcePath == null)
+ {
+ throw new IllegalArgumentException("resourcePath == null");
+ }
+
+ this.resourcePath = resourcePath;
+ }
+
+ public CDOView getView()
+ {
+ return view;
+ }
+
+ public String getResourcePath()
+ {
+ return resourcePath;
+ }
+
+ public int compareTo(Object o)
+ {
+ return resourcePath.compareTo(((Entry)o).resourcePath);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return resourcePath.equals(obj);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return resourcePath.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return resourcePath;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 6d4c82b..f5b8524 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -103,7 +103,7 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
public boolean isReadWrite()
{
- return timeStamp == CDOView.UNSPECIFIED_DATE;
+ return transaction != null;
}
public boolean isReadOnly()
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/actions/LongRunningAction.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/actions/LongRunningAction.java
index 32947d4..75d0734 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/actions/LongRunningAction.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/actions/LongRunningAction.java
@@ -12,6 +12,7 @@ package org.eclipse.net4j.ui.actions;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.internal.net4j.bundle.OM;
@@ -27,6 +28,8 @@ public abstract class LongRunningAction extends SafeAction
private IStatus status;
+ private int totalWork;
+
public LongRunningAction(IWorkbenchPage page)
{
this.page = page;
@@ -50,31 +53,60 @@ public abstract class LongRunningAction extends SafeAction
this.page = page;
}
- protected void setStatus(IStatus status)
+ protected final int getTotalWork()
+ {
+ return totalWork;
+ }
+
+ protected final void setTotalWork(int totalWork)
+ {
+ this.totalWork = totalWork;
+ }
+
+ protected final void cancel()
+ {
+ totalWork = 0;
+ }
+
+ protected final void setStatus(IStatus status)
{
this.status = status;
}
@Override
- protected void doRun() throws Exception
+ protected final void doRun() throws Exception
{
- new Job(getText())
+ totalWork = IProgressMonitor.UNKNOWN;
+ preRun(page);
+ if (totalWork != 0)
{
- @Override
- protected IStatus run(IProgressMonitor monitor)
+ new Job(getText())
{
- try
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
{
- setStatus(Status.OK_STATUS);
- doRun(page, monitor);
- return status;
+ monitor.beginTask("", totalWork);
+ try
+ {
+ setStatus(Status.OK_STATUS);
+ doRun(page, monitor);
+ return status;
+ }
+ catch (Exception ex)
+ {
+ return handleException(ex);
+ }
+ finally
+ {
+ monitor.done();
+ }
}
- catch (Exception ex)
- {
- return handleException(ex);
- }
- }
- }.schedule();
+ }.schedule();
+ }
+ }
+
+ protected void preRun(IWorkbenchPage page) throws Exception
+ {
}
protected abstract void doRun(IWorkbenchPage page, IProgressMonitor monitor) throws Exception;
@@ -83,4 +115,12 @@ public abstract class LongRunningAction extends SafeAction
{
return new Status(IStatus.ERROR, OM.BUNDLE_ID, "An error has occured.", ex);
}
+
+ protected final void checkCancelation(IProgressMonitor monitor)
+ {
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/views/ContainerItemProvider.java b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/views/ContainerItemProvider.java
index 3387dae..39de5b6 100644
--- a/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/views/ContainerItemProvider.java
+++ b/plugins/org.eclipse.net4j.ui/src/org/eclipse/net4j/ui/views/ContainerItemProvider.java
@@ -55,7 +55,7 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
Node node = getNode(element);
return !node.getChildren().isEmpty();
}
- catch (RuntimeException ex)
+ catch (Exception ex)
{
return false;
}
@@ -119,6 +119,14 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
nodes.clear();
}
+ protected void elementAdded(Object element, Object parent)
+ {
+ }
+
+ protected void elementRemoved(Object element, Object parent)
+ {
+ }
+
protected ContainerNode getRoot()
{
return root;
@@ -246,7 +254,12 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
{
if (container == ContainerNode.this.container)
{
- elementAdded(element);
+ Node node = addChild(getChildren(), element);
+ if (node != null)
+ {
+ refreshElement(container, false);
+ elementAdded(element, container);
+ }
}
}
@@ -255,7 +268,14 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
{
if (container == ContainerNode.this.container)
{
- elementRemoved(element);
+ Node node = nodes.remove(element);
+ if (node != null)
+ {
+ getChildren().remove(node);
+ node.dispose();
+ refreshElement(container, false);
+ elementRemoved(element, container);
+ }
}
}
};
@@ -266,6 +286,7 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
this.container = container;
}
+ @Override
public void dispose()
{
container.removeListener(containerListener);
@@ -310,34 +331,6 @@ public class ContainerItemProvider<CONTAINER extends IContainer> extends ItemPro
return null;
}
-
- protected void elementAdded(final Object element)
- {
- if (addChild(getChildren(), element) != null)
- {
- refreshElement(getElement(), false);
- }
- }
-
- protected void elementRemoved(Object element)
- {
- Node node = nodes.remove(element);
- if (node != null)
- {
- Object parentElement = node.getParent().getElement();
- getChildren().remove(node);
- node.dispose();
-
- if (parentElement == null)
- {
- refreshElement(root, false);
- }
- else
- {
- refreshElement(parentElement, false);
- }
- }
- }
}
/**