summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-04 12:11:56 (EDT)
committerEike Stepper2007-07-04 12:11:56 (EDT)
commit46c569b928c62254b0818c60676370dee31b594c (patch)
tree32bffad2cc94fc41a1ed5bec3ab045cc1973320b
parentc3d64741110cbeebd67e2e28863d48fc99707b77 (diff)
downloadcdo-46c569b928c62254b0818c60676370dee31b594c.zip
cdo-46c569b928c62254b0818c60676370dee31b594c.tar.gz
cdo-46c569b928c62254b0818c60676370dee31b594c.tar.bz2
task 1: Develop 0.8.0
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/ItemsProcessor.java86
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java67
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOItemProvider.java44
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java82
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewCommitedEvent.java28
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java42
6 files changed, 269 insertions, 80 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/ItemsProcessor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/ItemsProcessor.java
new file mode 100644
index 0000000..0e85719
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/ItemsProcessor.java
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * 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;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.protocol.CDOID;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.TreeItem;
+
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ItemsProcessor
+{
+ public ItemsProcessor()
+ {
+ }
+
+ public void processCDOObjects(TreeViewer viewer)
+ {
+ processCDOObjects(viewer, null);
+ }
+
+ public void processCDOObjects(final TreeViewer viewer, final Set<CDOID> ids)
+ {
+ try
+ {
+ viewer.getControl().getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ processItems(viewer, ids, viewer.getTree().getItems());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ });
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ protected abstract void processCDOObject(TreeViewer viewer, CDOObject cdoObject);
+
+ private void processItems(TreeViewer viewer, Set<CDOID> ids, TreeItem[] items)
+ {
+ for (TreeItem item : items)
+ {
+ Object object = item.getData();
+ if (object instanceof CDOObject)
+ {
+ CDOObject cdoObject = (CDOObject)object;
+ if (ids == null)
+ {
+ processCDOObject(viewer, cdoObject);
+ }
+ else if (ids.contains(cdoObject.cdoID()))
+ {
+ processCDOObject(viewer, cdoObject);
+ }
+ }
+
+ if (item.getItemCount() != 0)
+ {
+ processItems(viewer, ids, item.getItems());
+ }
+ }
+ }
+}
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 935c51d..2d37de4 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
@@ -6,9 +6,12 @@
*/
package org.eclipse.emf.cdo.internal.ui.editor;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOSessionInvalidationEvent;
import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.internal.ui.ItemsProcessor;
import org.eclipse.emf.cdo.internal.ui.bundle.CDOUI;
+import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOPackageManager;
@@ -54,6 +57,7 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage;
+import org.eclipse.emf.internal.cdo.CDOViewCommitedEvent;
import org.eclipse.emf.internal.cdo.util.EMFUtil;
import org.eclipse.core.resources.IFile;
@@ -123,10 +127,12 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EventObject;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* This is an example of a CDO model editor. <!-- begin-user-doc --> <!--
@@ -161,25 +167,38 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
{
if (event instanceof CDOSessionInvalidationEvent)
{
- try
+ Set<CDOID> dirtyOIDs = ((CDOSessionInvalidationEvent)event).getDirtyOIDs();
+ new ItemsProcessor()
{
- selectionViewer.getTree().getDisplay().asyncExec(new Runnable()
+ @Override
+ protected void processCDOObject(TreeViewer viewer, CDOObject cdoObject)
{
- public void run()
- {
- try
- {
- selectionViewer.refresh();
- }
- catch (Exception ignore)
- {
- }
- }
- });
- }
- catch (Exception ignore)
+ viewer.refresh(cdoObject, true);
+ }
+ }.processCDOObjects(selectionViewer, dirtyOIDs);
+ }
+ }
+ };
+
+ /**
+ * @ADDED
+ */
+ private IListener viewListener = new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof CDOViewCommitedEvent)
+ {
+ Map<CDOID, CDOID> idMappings = ((CDOViewCommitedEvent)event).getIDMappings();
+ HashSet newOIDs = new HashSet(idMappings.values());
+ new ItemsProcessor()
{
- }
+ @Override
+ protected void processCDOObject(TreeViewer viewer, CDOObject cdoObject)
+ {
+ viewer.update(cdoObject, null);
+ }
+ }.processCDOObjects(selectionViewer, newOIDs);
}
}
};
@@ -1054,7 +1073,19 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
setCurrentViewer(selectionViewer);
selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
- selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
+ selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)
+ {
+ @Override
+ public String getColumnText(Object object, int columnIndex)
+ {
+ if (object instanceof CDOObject)
+ {
+ return super.getColumnText(object, columnIndex) + " [" + ((CDOObject)object).cdoID() + "]";
+ }
+
+ return super.getColumnText(object, columnIndex);
+ }
+ });
selectionViewer.setInput(viewerInput);
// selectionViewer.setSelection(new StructuredSelection(viewerInput), true);
@@ -1088,6 +1119,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
updateProblemIndication();
view.getSession().addListener(sessionListener);
+ view.addListener(viewListener);
}
/**
@@ -1718,6 +1750,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv
public void dispose()
{
updateProblemIndication = false;
+ view.removeListener(viewListener);
view.getSession().removeListener(sessionListener);
getSite().getPage().removePartListener(partListener);
adapterFactory.dispose();
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 81f4200..278da1e 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
@@ -194,35 +194,35 @@ public class CDOItemProvider extends ContainerItemProvider
protected void fillView(IMenuManager manager, final CDOView view)
{
- if (view.isReadWrite())
+ manager.add(new LongRunningAction(page, "Load Resource", "Load a CDO resource")
{
- manager.add(new LongRunningAction(page, "Load Resource", "Load a CDO resource")
- {
- private String resourcePath;
+ private String resourcePath;
- @Override
- protected void preRun(IWorkbenchPage page) throws Exception
+ @Override
+ protected void preRun(IWorkbenchPage page) throws Exception
+ {
+ String uri = lastNumber == -1 ? "" : "/res" + lastNumber;
+ InputDialog dialog = new InputDialog(page.getWorkbenchWindow().getShell(), "Load Resource",
+ "Enter resource path:", uri, null);
+ if (dialog.open() == InputDialog.OK)
{
- String uri = lastNumber == -1 ? "" : "/res" + lastNumber;
- InputDialog dialog = new InputDialog(page.getWorkbenchWindow().getShell(), "Load Resource",
- "Enter resource path:", uri, null);
- if (dialog.open() == InputDialog.OK)
- {
- resourcePath = dialog.getValue();
- }
- else
- {
- cancel();
- }
+ resourcePath = dialog.getValue();
}
-
- @Override
- protected void doRun(final IWorkbenchPage page, IProgressMonitor monitor) throws Exception
+ else
{
- CDOEditor.open(page, view, resourcePath);
+ cancel();
}
- });
+ }
+ @Override
+ protected void doRun(final IWorkbenchPage page, IProgressMonitor monitor) throws Exception
+ {
+ CDOEditor.open(page, view, resourcePath);
+ }
+ });
+
+ if (view.isReadWrite())
+ {
manager.add(new LongRunningAction(page, "Create Resource", "Create a CDO resource")
{
private String resourcePath;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 980927f..a0a8333 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -84,46 +84,53 @@ public class CDOTransactionImpl
nextTemporaryID = INITIAL_TEMPORARY_ID;
}
- public void commit()
+ /**
+ * @return
+ * @return A set of the ids that have changed due to object creation
+ */
+ public CommitTransactionResult commit()
{
- if (!dirty)
+ if (dirty)
{
- return;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("commit()");
- }
-
- try
- {
- CDOSessionImpl session = view.getSession();
- CommitTransactionRequest signal = new CommitTransactionRequest(session.getChannel(), this);
- CommitTransactionResult result = signal.send();
-
- postCommit(newResources, result);
- postCommit(newObjects, result);
- postCommit(dirtyObjects, result);
- if (!dirtyObjects.isEmpty())
+ if (TRACER.isEnabled())
{
- session.notifyInvalidation(result.getTimeStamp(), dirtyObjects.keySet(), view);
+ TRACER.trace("commit()");
}
- newResources.clear();
- newObjects.clear();
- dirtyObjects.clear();
- dirty = false;
- nextTemporaryID = INITIAL_TEMPORARY_ID;
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new RuntimeException(ex);
+ try
+ {
+ CDOSessionImpl session = view.getSession();
+ CommitTransactionRequest signal = new CommitTransactionRequest(session.getChannel(), this);
+ CommitTransactionResult result = signal.send();
+
+ postCommit(newResources, result);
+ postCommit(newObjects, result);
+ postCommit(dirtyObjects, result);
+
+ if (!dirtyObjects.isEmpty())
+ {
+ session.notifyInvalidation(result.getTimeStamp(), dirtyObjects.keySet(), view);
+ }
+
+ newResources.clear();
+ newObjects.clear();
+ dirtyObjects.clear();
+ dirty = false;
+ nextTemporaryID = INITIAL_TEMPORARY_ID;
+ return result;
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ // TODO Better exception handling
+ throw new RuntimeException(ex);
+ }
}
+
+ return null;
}
public void rollback()
@@ -177,9 +184,12 @@ public class CDOTransactionImpl
private void postCommit(Map objects, CommitTransactionResult result)
{
- for (Object object : objects.values())
+ if (!objects.isEmpty())
{
- CDOStateMachine.INSTANCE.commit((CDOObjectImpl)object, result);
+ for (Object object : objects.values())
+ {
+ CDOStateMachine.INSTANCE.commit((CDOObjectImpl)object, result);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewCommitedEvent.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewCommitedEvent.java
new file mode 100644
index 0000000..ad44c4a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewCommitedEvent.java
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * 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.internal.cdo;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.protocol.CDOID;
+
+import org.eclipse.net4j.util.event.IEvent;
+
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public interface CDOViewCommitedEvent extends IEvent
+{
+ public CDOView getView();
+
+ public Map<CDOID, CDOID> getIDMappings();
+}
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 5356614..676595e 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
@@ -35,6 +35,7 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.internal.cdo.bundle.CDO;
+import org.eclipse.emf.internal.cdo.protocol.CommitTransactionResult;
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
import java.text.MessageFormat;
@@ -187,10 +188,10 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
return lastLookupObject;
}
- if (TRACER.isEnabled())
- {
- TRACER.format("Looking up object {0}", id);
- }
+ // if (TRACER.isEnabled())
+ // {
+ // TRACER.format("Looking up object {0}", id);
+ // }
lastLookupID = id;
lastLookupObject = objects.get(id);
@@ -280,7 +281,15 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
public void commit()
{
checkWritable();
- transaction.commit();
+ CommitTransactionResult result = transaction.commit();
+ if (result != null)
+ {
+ Map<CDOID, CDOID> idMappings = result.getIdMappings();
+ if (idMappings != null && !idMappings.isEmpty())
+ {
+ fireEvent(new CommittedEvent(idMappings));
+ }
+ }
}
public void rollback()
@@ -544,4 +553,27 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
return MessageFormat.format("CDOViewResourcesEvent[{0}, {1}, {2}]", getView(), resourcePath, kind);
}
}
+
+ private final class CommittedEvent extends Event implements CDOViewCommitedEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private Map<CDOID, CDOID> idMappings;
+
+ private CommittedEvent(Map<CDOID, CDOID> idMappings)
+ {
+ super(CDOViewImpl.this);
+ this.idMappings = idMappings;
+ }
+
+ public CDOView getView()
+ {
+ return CDOViewImpl.this;
+ }
+
+ public Map<CDOID, CDOID> getIDMappings()
+ {
+ return idMappings;
+ }
+ }
}