diff options
author | Eike Stepper | 2015-02-15 17:11:37 +0000 |
---|---|---|
committer | Eike Stepper | 2015-02-15 20:56:26 +0000 |
commit | 34c089e5e862eef6769c0b1375216ec90d5c4d59 (patch) | |
tree | 96c51f8cc10bb409c2e45f426ac53188f2af459b | |
parent | 55d88086cf1e01606e4c0b1fb97780ed0e4c2127 (diff) | |
download | cdo-34c089e5e862eef6769c0b1375216ec90d5c4d59.tar.gz cdo-34c089e5e862eef6769c0b1375216ec90d5c4d59.tar.xz cdo-34c089e5e862eef6769c0b1375216ec90d5c4d59.zip |
[458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
24 files changed, 657 insertions, 98 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.explorer.ui/META-INF/MANIFEST.MF index a3ba254fa1..cd3fec280d 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/META-INF/MANIFEST.MF @@ -14,6 +14,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.navigator;bundle-version="[3.5.0,4.0.0)", org.eclipse.ui.views.properties.tabbed;bundle-version="[3.5.0,4.0.0)", org.eclipse.emf.cdo.explorer;bundle-version="[4.4.0,5.0.0)", + org.eclipse.emf.cdo.workspace;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.admin;bundle-version="[4.0.0,5.0.0)", org.eclipse.emf.cdo.ui;bundle-version="[4.0.0,5.0.0)", diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml index 6b6e1d4cca..624d1c8362 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml @@ -375,6 +375,14 @@ id="org.eclipse.emf.cdo.explorer.ui.CheckoutClose" name="Close Checkout" defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.CheckoutCloseHandler"/> + <command + id="org.eclipse.emf.cdo.explorer.ui.WorkspaceUpdate" + name="Update Workspace" + defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.WorkspaceUpdateHandler"/> + <command + id="org.eclipse.emf.cdo.explorer.ui.WorkspaceCheckin" + name="Checkin Workspace" + defaultHandler="org.eclipse.emf.cdo.explorer.ui.handlers.WorkspaceCheckinHandler"/> </extension> <extension @@ -551,7 +559,7 @@ icon="icons/delete.gif" label="Delete..." style="push" - tooltip="Delete the repository"> + tooltip="Delete the repositories"> <visibleWhen checkEnabled="false"> <with @@ -569,7 +577,7 @@ icon="icons/delete.gif" label="Delete..." style="push" - tooltip="Delete the checkout"> + tooltip="Delete the checkouts"> <visibleWhen checkEnabled="false"> <with @@ -587,7 +595,7 @@ icon="icons/delete.gif" label="Delete..." style="push" - tooltip="Delete the object"> + tooltip="Delete the objects"> <visibleWhen checkEnabled="false"> <with @@ -667,6 +675,44 @@ </visibleWhen> </command> </menuContribution> + <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.ui.popup.any?group=additions"> + <command + commandId="org.eclipse.emf.cdo.explorer.ui.WorkspaceUpdate" + label="Update" + style="push" + tooltip="Update the checkout from the remote repository"> + <visibleWhen + checkEnabled="false"> + <with + variable="activeMenuSelection"> + <iterate> + <adapt + type="org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout"> + </adapt> + </iterate> + </with> + </visibleWhen> + </command> + <command + commandId="org.eclipse.emf.cdo.explorer.ui.WorkspaceCheckin" + label="Checkin" + style="push" + tooltip="Checkin the local changes into the remote repository"> + <visibleWhen + checkEnabled="false"> + <with + variable="activeMenuSelection"> + <iterate> + <adapt + type="org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout"> + </adapt> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> </extension> </plugin> diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java index 5bec7adf6c..8d8674cc22 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java @@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.util.CDOCommonUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.ui.BaseLabelDecorator; +import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; /** * @author Eike Stepper @@ -56,6 +57,15 @@ public class CDOCheckoutLabelDecorator extends BaseLabelDecorator { text += " " + CDOCommonUtil.formatTimeStamp(timeStamp); } + + if (element instanceof OfflineCDOCheckout) + { + OfflineCDOCheckout offlineCheckout = (OfflineCDOCheckout)element; + if (offlineCheckout.isDirty()) + { + text += " [dirty]"; + } + } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java index e135b49f42..053752e4c2 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java @@ -248,6 +248,18 @@ public class CDOCheckoutNewActionProvider extends CommonActionProvider implement } @Override + protected CDOTransaction openTransaction(CDOObject object) + { + CDOCheckout checkout = CDOExplorerUtil.getCheckout(object); + if (checkout != null) + { + return checkout.openTransaction(); + } + + return null; + } + + @Override protected void doRun(CDOTransaction transaction, CDOObject resource, IProgressMonitor monitor) throws Exception { EList<EObject> contents = ((CDOResource)resource).getContents(); @@ -270,6 +282,18 @@ public class CDOCheckoutNewActionProvider extends CommonActionProvider implement } @Override + protected CDOTransaction openTransaction(CDOObject object) + { + CDOCheckout checkout = CDOExplorerUtil.getCheckout(object); + if (checkout != null) + { + return checkout.openTransaction(); + } + + return null; + } + + @Override protected void doRun(CDOTransaction transaction, CDOObject parent, IProgressMonitor monitor) throws Exception { BasicCommandStack commandStack = new BasicCommandStack(); diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenWithActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenWithActionProvider.java index d49c1f674c..cfcae20a50 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenWithActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenWithActionProvider.java @@ -16,7 +16,6 @@ import org.eclipse.emf.cdo.eresource.CDOResourceLeaf; import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; -import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.ui.CDOEditorUtil; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOView; @@ -321,10 +320,10 @@ public class CDOCheckoutOpenWithActionProvider extends CommonActionProvider protected IStatus run(IProgressMonitor monitor) { CDOCheckout checkout = CDOExplorerUtil.getCheckout(resourceLeaf); - final CDOTransaction transaction = checkout.openTransaction(); + final CDOView view = checkout.openView(); - CDOResourceLeaf transactionalLeaf = transaction.getObject(resourceLeaf); - final IEditorInput editorInput = CDOEditorUtil.createEditorInput(editorID, transactionalLeaf, false, true); + CDOResourceLeaf contextualLeaf = view.getObject(resourceLeaf); + final IEditorInput editorInput = CDOEditorUtil.createEditorInput(editorID, contextualLeaf, false, true); final IWorkbenchWindow workbenchWindow = page.getWorkbenchWindow(); Display display = workbenchWindow.getShell().getDisplay(); @@ -345,7 +344,7 @@ public class CDOCheckoutOpenWithActionProvider extends CommonActionProvider synchronized (VIEWS) { - VIEWS.put(editor, Pair.create((CDOView)transaction, key)); + VIEWS.put(editor, Pair.create(view, key)); } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java index d9ca0610dc..da716d4bf9 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java @@ -11,10 +11,17 @@ package org.eclipse.emf.cdo.explorer.ui.checkouts; import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.model.CDOPackageRegistryPopulator; import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; +import org.eclipse.emf.cdo.internal.ui.views.CDOSessionsView; +import org.eclipse.emf.cdo.session.CDOSession; + +import org.eclipse.emf.internal.cdo.session.CDOSessionFactory; + +import org.eclipse.net4j.util.container.IPluginContainer; import org.eclipse.emf.ecore.EObject; @@ -76,22 +83,44 @@ public class CDOCheckoutShowInActionProvider extends CommonActionProvider if (selectedElement instanceof CDORepository) { - CDORepository repository = (CDORepository)selectedElement; + final CDORepository repository = (CDORepository)selectedElement; if (repository.isConnected()) { - addShowInAction(page, actions, repository.getSession(), "org.eclipse.team.ui.GenericHistoryView"); + addAction(actions, repository, new ShowInAction(page, CDOSessionsView.ID) + { + @Override + public void run() + { + super.run(); + + String description = repository.getURI(); + int lastSlash = description.lastIndexOf('/'); + description = description.substring(0, lastSlash) + "?repositoryName=" + repository.getName() + + "&automaticPackageRegistry=true&repositoryID=" + repository.getID(); + + CDOSession session = (CDOSession)IPluginContainer.INSTANCE.getElement(CDOSessionFactory.PRODUCT_GROUP, + "cdo", repository.getConnectorType() + "://" + repository.getConnectorDescription() + + "?repositoryName=" + repository.getName() + "&repositoryID=" + repository.getID()); + if (session != null) + { + CDOPackageRegistryPopulator.populate(session.getPackageRegistry()); + } + } + }); + + addAction(actions, repository.getSession(), new ShowInAction(page, "org.eclipse.team.ui.GenericHistoryView")); } } else if (selectedElement instanceof CDOBranch) { - addShowInAction(page, actions, selectedElement, "org.eclipse.team.ui.GenericHistoryView"); + addAction(actions, selectedElement, new ShowInAction(page, "org.eclipse.team.ui.GenericHistoryView")); } else if (selectedElement instanceof CDOCheckout) { CDOCheckout checkout = (CDOCheckout)selectedElement; if (checkout.isOpen()) { - addShowInAction(page, actions, checkout.getView(), "org.eclipse.team.ui.GenericHistoryView"); + addAction(actions, checkout.getView(), new ShowInAction(page, "org.eclipse.team.ui.GenericHistoryView")); } } else if (selectedElement instanceof EObject) @@ -99,7 +128,7 @@ public class CDOCheckoutShowInActionProvider extends CommonActionProvider EObject eObject = (EObject)selectedElement; if (CDOExplorerUtil.getCheckout(eObject) != null) { - addShowInAction(page, actions, selectedElement, "org.eclipse.team.ui.GenericHistoryView"); + addAction(actions, selectedElement, new ShowInAction(page, "org.eclipse.team.ui.GenericHistoryView")); } } @@ -118,9 +147,8 @@ public class CDOCheckoutShowInActionProvider extends CommonActionProvider } } - private static void addShowInAction(IWorkbenchPage page, List<IAction> actions, Object selectedElement, String viewID) + private static void addAction(List<IAction> actions, Object selectedElement, ShowInAction action) { - ShowInAction action = new ShowInAction(page, viewID); action.selectionChanged(selectedElement); if (action.isEnabled()) { diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java index 638c6d52b8..21ac0c7b2e 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandler.java @@ -47,7 +47,7 @@ public class RepositoryCheckoutHandler extends AbstractBaseHandler<CDORepository properties.put("repository", repository.getID()); properties.put("branchID", Integer.toString(repositoryElement.getBranchID())); properties.put("timeStamp", Long.toString(repositoryElement.getTimeStamp())); - properties.put("readOnly", Boolean.TRUE.toString()); + properties.put("readOnly", Boolean.FALSE.toString()); properties.put("rootID", CDOCheckoutImpl.getCDOIDString(repositoryElement.getObjectID())); CDOCheckout checkout = CDOExplorerUtil.getCheckoutManager().addCheckout(properties); diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceCheckinHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceCheckinHandler.java new file mode 100644 index 0000000000..af89ca0b5e --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceCheckinHandler.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009-2015 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.explorer.ui.handlers; + +import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; +import org.eclipse.emf.cdo.workspace.CDOWorkspace; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.ISelection; + +/** + * @author Eike Stepper + */ +public class WorkspaceCheckinHandler extends AbstractBaseHandler<OfflineCDOCheckout> +{ + public WorkspaceCheckinHandler() + { + super(OfflineCDOCheckout.class, false); + } + + @Override + protected boolean updateSelection(ISelection selection) + { + boolean result = super.updateSelection(selection); + + if (result) + { + OfflineCDOCheckout checkout = elements.get(0); + if (!checkout.isDirty()) + { + return false; + } + } + + return result; + } + + @Override + protected void doExecute(ExecutionEvent event, IProgressMonitor monitor) throws Exception + { + OfflineCDOCheckout checkout = elements.get(0); + CDOWorkspace workspace = checkout.getWorkspace(); + if (workspace != null) + { + // TODO Prompt for checkin comment. + // TODO Use progress monitor. + workspace.checkin(); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceUpdateHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceUpdateHandler.java new file mode 100644 index 0000000000..a4856232a1 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceUpdateHandler.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2009-2015 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.explorer.ui.handlers; + +import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; +import org.eclipse.emf.cdo.transaction.CDOMerger; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.workspace.CDOWorkspace; + +import org.eclipse.emf.spi.cdo.DefaultCDOMerger; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Eike Stepper + */ +public class WorkspaceUpdateHandler extends AbstractBaseHandler<OfflineCDOCheckout> +{ + public WorkspaceUpdateHandler() + { + super(OfflineCDOCheckout.class, false); + } + + @Override + protected void doExecute(ExecutionEvent event, IProgressMonitor monitor) throws Exception + { + OfflineCDOCheckout checkout = elements.get(0); + CDOWorkspace workspace = checkout.getWorkspace(); + if (workspace != null) + { + // TODO Use progress monitor in update(). + CDOMerger merger = new DefaultCDOMerger.PerFeature.ManyValued(); + CDOTransaction transaction = workspace.update(merger); + transaction.commit(monitor); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.explorer/.settings/.api_filters b/plugins/org.eclipse.emf.cdo.explorer/.settings/.api_filters new file mode 100644 index 0000000000..0532666bdb --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer/.settings/.api_filters @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<component id="org.eclipse.emf.cdo.explorer" version="2"> + <resource path="src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java" type="org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl"> + <filter id="572522506"> + <message_arguments> + <message_argument value="ReadOnlyException"/> + <message_argument value="CDOCheckoutImpl"/> + </message_arguments> + </filter> + </resource> + <resource path="src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java" type="org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout$RemoteSessionConfiguration"> + <filter id="574619656"> + <message_arguments> + <message_argument value="CDOSessionConfiguration"/> + <message_argument value="RemoteSessionConfiguration"/> + </message_arguments> + </filter> + </resource> +</component> diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerElement.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerElement.java index d05ad2a628..b9e4fb6fd4 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerElement.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerElement.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.IAdaptable; * @author Eike Stepper * @since 4.4 */ -public interface CDOExplorerElement extends INotifier, IAdaptable, Adapter +public interface CDOExplorerElement extends INotifier, IAdaptable, Adapter, Comparable<CDOExplorerElement> { public String getID(); diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerUtil.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerUtil.java index c9cc9969e2..bdf1a56d28 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerUtil.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOExplorerUtil.java @@ -54,6 +54,15 @@ public final class CDOExplorerUtil return container; } + if (object instanceof CDOResource) + { + CDOResource resource = (CDOResource)object; + if (resource.isRoot()) + { + return null; + } + } + Resource resource = object.eResource(); if (resource instanceof CDOResource) { diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java index f41ffab37d..eb8962f9e9 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java @@ -62,6 +62,10 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider public ObjectType getRootType(); + public CDOView openView(); + + public CDOView openView(boolean readOnly); + public CDOTransaction openTransaction(); public String getEditorID(CDOID objectID); diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java index 1035662850..64469be275 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java @@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.util.CDONameProvider; import org.eclipse.emf.cdo.explorer.CDOExplorerElement; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; +import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.session.CDOSessionProvider; import org.eclipse.net4j.util.container.IContainer; @@ -44,6 +45,12 @@ public interface CDORepository extends CDOExplorerElement, IContainer<CDOBranch> public CDOCheckout[] getCheckouts(); + public CDOSession getSession(); + + public CDOSession acquireSession(); + + public void releaseSession(); + /** * @author Eike Stepper */ diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java index 62f64314fd..432ad28ede 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java @@ -87,11 +87,16 @@ public abstract class AbstractElement extends Notifier implements CDOExplorerEle this.label = label; save(); - AbstractManager<?> manager = getManager(); - if (manager != null) - { - manager.fireElementChangedEvent(this); - } + fireElementChangedEvent(); + } + } + + protected final void fireElementChangedEvent() + { + AbstractManager<?> manager = getManager(); + if (manager != null) + { + manager.fireElementChangedEvent(this); } } @@ -183,6 +188,13 @@ public abstract class AbstractElement extends Notifier implements CDOExplorerEle return getClass().hashCode() ^ id.hashCode(); } + public int compareTo(CDOExplorerElement o) + { + String label1 = StringUtil.safe(label); + String label2 = StringUtil.safe(o.getLabel()); + return label1.compareTo(label2); + } + public void delete(boolean deleteContents) { if (deleteContents) diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java index 0dc4670042..8ed2f77405 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java @@ -10,6 +10,7 @@ */ package org.eclipse.emf.cdo.internal.explorer.checkouts; +import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.id.CDOIDUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; @@ -21,6 +22,7 @@ import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryImpl; import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.transaction.CDOTransactionCommentator; +import org.eclipse.emf.cdo.util.ReadOnlyException; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.ObjectUtil; @@ -165,6 +167,7 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec { state = State.Opening; + prepareOpen(); CDOSession session = ((CDORepositoryImpl)repository).openCheckout(this); view = openView(session); @@ -200,6 +203,11 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec } } + protected void prepareOpen() + { + // Do nothing. + } + public final synchronized void close() { boolean closed = false; @@ -260,9 +268,24 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec return ObjectType.valueFor(rootObject); } + public final CDOView openView() + { + return doOpenView(readOnly); + } + + public final CDOView openView(boolean readOnly) + { + return doOpenView(readOnly); + } + public final CDOTransaction openTransaction() { - CDOTransaction transaction = doOpenTransaction(); + if (readOnly) + { + throw new ReadOnlyException("Checkout '" + getLabel() + "' is read-only"); + } + + CDOTransaction transaction = (CDOTransaction)doOpenView(false); if (transaction != null) { new CDOTransactionCommentator(transaction); @@ -271,14 +294,22 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec return transaction; } - protected CDOTransaction doOpenTransaction() + protected CDOView doOpenView(boolean readOnly) { if (view == null) { return null; } - return view.getSession().openTransaction(view.getBranch()); + CDOSession session = view.getSession(); + CDOBranch branch = view.getBranch(); + + if (readOnly) + { + return session.openView(branch); + } + + return session.openTransaction(branch); } public String getEditorID(CDOID objectID) diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java index ff66194127..ecafe53500 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutManagerImpl.java @@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.event.Event; import java.io.File; +import java.util.Arrays; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; @@ -86,6 +87,14 @@ public class CDOCheckoutManagerImpl extends AbstractManager<CDOCheckout> impleme } @Override + protected CDOCheckout[] sortElements(CDOCheckout[] array) + { + CDOCheckout[] sorted = super.sortElements(array); + Arrays.sort(sorted); + return sorted; + } + + @Override protected void doDeactivate() throws Exception { for (CDOCheckout checkout : getCheckouts()) diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java index ce9e799cd9..a01eb122bf 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java @@ -10,30 +10,33 @@ */ package org.eclipse.emf.cdo.internal.explorer.checkouts; -import org.eclipse.emf.cdo.common.revision.CDORevisionCache; -import org.eclipse.emf.cdo.common.revision.CDORevisionUtil; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.LockNotificationMode; +import org.eclipse.emf.cdo.common.CDOCommonSession.Options.PassiveUpdateMode; +import org.eclipse.emf.cdo.common.branch.CDOBranchManager; +import org.eclipse.emf.cdo.common.id.CDOIDGenerator; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; -import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; -import org.eclipse.emf.cdo.net4j.CDONet4jUtil; import org.eclipse.emf.cdo.server.IStore; import org.eclipse.emf.cdo.server.db.CDODBUtil; import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy; import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.session.CDOSession.ExceptionHandler; import org.eclipse.emf.cdo.session.CDOSessionConfiguration; import org.eclipse.emf.cdo.session.CDOSessionConfigurationFactory; -import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.CDOFetchRuleManager; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.emf.cdo.workspace.CDOWorkspace; +import org.eclipse.emf.cdo.workspace.CDOWorkspace.DirtyStateChangedEvent; import org.eclipse.emf.cdo.workspace.CDOWorkspaceBase; import org.eclipse.emf.cdo.workspace.CDOWorkspaceConfiguration; import org.eclipse.emf.cdo.workspace.CDOWorkspaceUtil; -import org.eclipse.net4j.Net4jUtil; -import org.eclipse.net4j.connector.IConnector; import org.eclipse.net4j.db.DBUtil; import org.eclipse.net4j.db.IDBAdapter; import org.eclipse.net4j.db.IDBConnectionProvider; -import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.collection.Closeable; +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; import org.h2.jdbcx.JdbcDataSource; @@ -44,34 +47,46 @@ import java.io.File; */ public class OfflineCDOCheckout extends CDOCheckoutImpl { + private final IListener workspaceListener = new IListener() + { + public void notifyEvent(IEvent event) + { + if (event instanceof DirtyStateChangedEvent) + { + fireElementChangedEvent(); + } + } + }; + private CDOWorkspace workspace; public OfflineCDOCheckout() { } - @Override - protected CDOView openView(CDOSession session) + public final CDOWorkspace getWorkspace() { - final IManagedContainer container = getContainer(); - final CDORepository repository = getRepository(); + return workspace; + } - final String connectorType = repository.getConnectorType(); - final String connectorDescription = repository.getConnectorDescription(); - final String repositoryName = repository.getName(); + public final boolean isDirty() + { + if (workspace == null) + { + return false; + } + return workspace.isDirty(); + } + + @Override + protected CDOView openView(CDOSession session) + { CDOSessionConfigurationFactory remote = new CDOSessionConfigurationFactory() { public CDOSessionConfiguration createSessionConfiguration() { - IConnector connector = Net4jUtil.getConnector(container, connectorType, connectorDescription); - - CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration(); - config.setConnector(connector); - config.setRepositoryName(repositoryName); - config.setRevisionManager(CDORevisionUtil.createRevisionManager(CDORevisionCache.NOOP)); - - return config; + return new RemoteSessionConfiguration(); } }; @@ -90,7 +105,7 @@ public class OfflineCDOCheckout extends CDOCheckoutImpl File baseFolder = new File(folder, "base"); CDOWorkspaceBase base = CDOWorkspaceUtil.createFolderWorkspaceBase(baseFolder); - String localRepositoryName = repositoryName + "-workspace" + getID(); + String localRepositoryName = getRepository().getName() + "-workspace" + getID(); int branchID = getBranchID(); long timeStamp = getTimeStamp(); @@ -112,12 +127,8 @@ public class OfflineCDOCheckout extends CDOCheckoutImpl workspace = configuration.checkout(); } - if (isReadOnly()) - { - return workspace.openView(); - } - - return workspace.openTransaction(); + workspace.addListener(workspaceListener); + return workspace.openView(); } @Override @@ -133,13 +144,167 @@ public class OfflineCDOCheckout extends CDOCheckoutImpl } @Override - protected CDOTransaction doOpenTransaction() + protected CDOView doOpenView(boolean readOnly) { if (workspace == null) { return null; } + if (readOnly) + { + return workspace.openView(); + } + return workspace.openTransaction(); } + + /** + * @author Eike Stepper + */ + private final class RemoteSessionConfiguration implements CDOSessionConfiguration, Closeable + { + private boolean closed; + + public void addListener(IListener listener) + { + } + + public void removeListener(IListener listener) + { + } + + public boolean hasListeners() + { + return false; + } + + public IListener[] getListeners() + { + return null; + } + + public String getUserID() + { + return null; + } + + public void setUserID(String userID) + { + } + + public boolean isPassiveUpdateEnabled() + { + return false; + } + + public void setPassiveUpdateEnabled(boolean passiveUpdateEnabled) + { + } + + public PassiveUpdateMode getPassiveUpdateMode() + { + return null; + } + + public void setPassiveUpdateMode(PassiveUpdateMode passiveUpdateMode) + { + } + + public LockNotificationMode getLockNotificationMode() + { + return null; + } + + public void setLockNotificationMode(LockNotificationMode mode) + { + } + + public ExceptionHandler getExceptionHandler() + { + return null; + } + + public void setExceptionHandler(ExceptionHandler exceptionHandler) + { + } + + public CDOIDGenerator getIDGenerator() + { + return null; + } + + public void setIDGenerator(CDOIDGenerator idGenerator) + { + } + + public CDOFetchRuleManager getFetchRuleManager() + { + return null; + } + + public void setFetchRuleManager(CDOFetchRuleManager fetchRuleManager) + { + } + + public CDOBranchManager getBranchManager() + { + return null; + } + + public void setBranchManager(CDOBranchManager branchManager) + { + } + + @Deprecated + public org.eclipse.emf.cdo.common.protocol.CDOAuthenticator getAuthenticator() + { + return null; + } + + public IPasswordCredentialsProvider getCredentialsProvider() + { + return null; + } + + public void setCredentialsProvider(IPasswordCredentialsProvider credentialsProvider) + { + } + + public boolean isActivateOnOpen() + { + return false; + } + + public void setActivateOnOpen(boolean activateOnOpen) + { + } + + public boolean isSessionOpen() + { + return !closed; + } + + public CDOSession openSession() + { + CDORepository repository = getRepository(); + return repository.acquireSession(); + } + + public void close() + { + if (!closed) + { + CDORepository repository = getRepository(); + repository.releaseSession(); + + closed = true; + } + } + + public boolean isClosed() + { + return closed; + } + } } diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java index 04ecfdbd31..a701a209fe 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java @@ -37,4 +37,11 @@ public class OnlineCDOCheckout extends CDOCheckoutImpl return session.openTransaction(branch); } + + @Override + protected void prepareOpen() + { + getRepository().connect(); + super.prepareOpen(); + } } diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java index b4f9794ee1..fb6486b26e 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryImpl.java @@ -101,6 +101,10 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe private State state = State.Disconnected; + private boolean explicitelyConnected; + + private int sessionRefCount; + private CDOSession session; public CDORepositoryImpl() @@ -130,6 +134,12 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe public final void connect() { + explicitelyConnected = true; + doConnect(); + } + + protected void doConnect() + { boolean connected = false; synchronized (sessionListener) @@ -178,6 +188,20 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe public final void disconnect() { + explicitelyConnected = false; + doDisconnect(false); + } + + protected void doDisconnect(boolean force) + { + if (!force) + { + if (explicitelyConnected || sessionRefCount != 0) + { + return; + } + } + boolean disconnected = false; CDOSession oldSession = null; @@ -218,7 +242,7 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe { if (openCheckouts.isEmpty()) { - disconnect(); + doDisconnect(false); } } } @@ -228,6 +252,20 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe return session; } + public CDOSession acquireSession() + { + ++sessionRefCount; + doConnect(); + + return session; + } + + public void releaseSession() + { + --sessionRefCount; + doDisconnect(false); + } + @Override public void delete(boolean deleteContents) { @@ -268,8 +306,6 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe public final CDOSession openCheckout(CDOCheckout checkout) { - connect(); - synchronized (checkouts) { openCheckouts.add(checkout); diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java index bab4b2ae6e..4af129443c 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CDORepositoryManagerImpl.java @@ -102,7 +102,7 @@ public class CDORepositoryManagerImpl extends AbstractManager<CDORepository> imp { for (CDORepository repository : getRepositories()) { - repository.disconnect(); + ((CDORepositoryImpl)repository).doDisconnect(true); } super.doDeactivate(); diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java index 4e3b5c483f..94ca9c1693 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java @@ -42,15 +42,20 @@ public abstract class TransactionalBackgroundAction extends LongRunningAction return object; } - @Override - protected final void doRun(IProgressMonitor progressMonitor) throws Exception + protected CDOTransaction openTransaction(CDOObject object) { - progressMonitor.beginTask(Messages.getString("TransactionalBackgroundAction_1"), 100); //$NON-NLS-1$ - CDOView view = object.cdoView(); CDOTransaction transaction = view.getSession().openTransaction(view.getBranch()); OpenTransactionAction.configureTransaction(transaction); + return transaction; + } + + @Override + protected final void doRun(IProgressMonitor progressMonitor) throws Exception + { + progressMonitor.beginTask(Messages.getString("TransactionalBackgroundAction_1"), 100); //$NON-NLS-1$ + CDOTransaction transaction = openTransaction(object); CDOObject transactionalObject = transaction.getObject(object); progressMonitor.worked(5); @@ -70,6 +75,7 @@ public abstract class TransactionalBackgroundAction extends LongRunningAction if (commitInfo != null) { + CDOView view = object.cdoView(); view.waitForUpdate(commitInfo.getTimeStamp(), 5000); postRun(view, object); } diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java index cee8d3f934..8d271d049b 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java @@ -74,6 +74,7 @@ import org.eclipse.net4j.jvm.JVMUtil; import org.eclipse.net4j.signal.ISignalProtocol; import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.collection.Closeable; import org.eclipse.net4j.util.container.ContainerUtil; import org.eclipse.net4j.util.container.IManagedContainer; import org.eclipse.net4j.util.event.Event; @@ -102,6 +103,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; /** * @author Eike Stepper @@ -142,6 +144,8 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace private CDOSessionConfigurationFactory remoteSessionConfigurationFactory; + private Map<InternalCDOSession, Closeable> closeables = new ConcurrentHashMap<InternalCDOSession, Closeable>(); + private Set<InternalCDOView> views = new HashSet<InternalCDOView>(); /** @@ -236,7 +240,7 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace finally { remoteSession.getPackageRegistry().clear(); - LifecycleUtil.deactivate(remoteSession); + closeRemoteSession(remoteSession); } accessor.rawCommit(1, monitor); @@ -487,7 +491,7 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace } finally { - LifecycleUtil.deactivate(remoteSession); + closeRemoteSession(remoteSession); } } @@ -607,33 +611,40 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace InternalCDOBranch branch = remoteSession.getBranchManager().getBranch(branchPath); InternalCDOTransaction transaction = (InternalCDOTransaction)remoteSession.openTransaction(branch); - CDOChangeSetData changes = getLocalChanges(); - try { - ApplyChangeSetResult result = transaction.applyChangeSet(changes, base, this, head, true); - if (!result.getIDMappings().isEmpty()) + CDOChangeSetData changes = getLocalChanges(); + + try { - throw new IllegalStateException("Attaching new objects is only supported for IDGenerationLocation.CLIENT"); + ApplyChangeSetResult result = transaction.applyChangeSet(changes, base, this, head, true); + if (!result.getIDMappings().isEmpty()) + { + throw new IllegalStateException("Attaching new objects is only supported for IDGenerationLocation.CLIENT"); + } + } + catch (ChangeSetOutdatedException ex) + { + throw new CommitException(ex); } - } - catch (ChangeSetOutdatedException ex) - { - throw new CommitException(ex); - } - transaction.setCommitComment(comment); - CDOCommitInfo info = transaction.commit(); + transaction.setCommitComment(comment); + CDOCommitInfo info = transaction.commit(); - adjustLocalRevisions(transaction, info); - clearBase(); - setTimeStamp(info.getTimeStamp()); + adjustLocalRevisions(transaction, info); + clearBase(); + setTimeStamp(info.getTimeStamp()); - return info; + return info; + } + finally + { + transaction.close(); + } } finally { - LifecycleUtil.deactivate(remoteSession); + closeRemoteSession(remoteSession); } } @@ -972,23 +983,29 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace protected InternalCDOSession openRemoteSession() { CDOSessionConfiguration configuration = remoteSessionConfigurationFactory.createSessionConfiguration(); - InternalCDOSession session = (InternalCDOSession)configuration.openSession(); + InternalCDOSession remoteSession = (InternalCDOSession)configuration.openSession(); - CDORepositoryInfo repositoryInfo = session.getRepositoryInfo(); + if (configuration instanceof Closeable) + { + Closeable closeable = (Closeable)configuration; + closeables.put(remoteSession, closeable); + } + + CDORepositoryInfo repositoryInfo = remoteSession.getRepositoryInfo(); if (!repositoryInfo.isSupportingAudits()) { - session.close(); + remoteSession.close(); throw new IllegalStateException("Remote repository does not support auditing"); } IDGenerationLocation remoteLocation = repositoryInfo.getIDGenerationLocation(); if (!remoteLocation.equals(idGenerationLocation)) { - session.close(); + remoteSession.close(); throw new IllegalStateException("Remote repository uses different ID generation location: " + remoteLocation); } - InternalCDOBranch branch = session.getBranchManager().getBranch(branchID); + InternalCDOBranch branch = remoteSession.getBranchManager().getBranch(branchID); String pathName = branch.getPathName(); if (!ObjectUtil.equals(pathName, branchPath)) { @@ -996,7 +1013,20 @@ public class CDOWorkspaceImpl extends Notifier implements InternalCDOWorkspace saveProperties(); } - return session; + return remoteSession; + } + + protected void closeRemoteSession(InternalCDOSession remoteSession) + { + Closeable closeable = closeables.remove(remoteSession); + if (closeable != null) + { + closeable.close(); + } + else + { + LifecycleUtil.deactivate(remoteSession); + } } protected void setTimeStamp(long timeStamp) diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java index 48ea677926..8044165c2b 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultPropertySource.java @@ -21,9 +21,8 @@ import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertyDescriptor; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +import java.util.LinkedHashMap; import java.util.Map; /** @@ -32,7 +31,7 @@ import java.util.Map; */ public class DefaultPropertySource<RECEIVER> implements IPropertySource { - private List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>(); + private Map<Object, IPropertyDescriptor> descriptors = new LinkedHashMap<Object, IPropertyDescriptor>(); private RECEIVER receiver; @@ -55,9 +54,16 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource /** * @since 3.5 */ - public void addDescriptor(IPropertyDescriptor descriptor) + public boolean addDescriptor(IPropertyDescriptor descriptor) { - descriptors.add(descriptor); + Object id = descriptor.getId(); + if (descriptors.containsKey(id)) + { + return false; + } + + descriptors.put(id, descriptor); + return true; } public PropertyDescriptor addDescriptor(String category, Object id, String displayName, String description) @@ -66,7 +72,11 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource descriptor.setCategory(category); descriptor.setDescription(description); - addDescriptor(descriptor); + if (!addDescriptor(descriptor)) + { + return null; + } + return descriptor; } @@ -76,19 +86,20 @@ public class DefaultPropertySource<RECEIVER> implements IPropertySource { if (property.getLabel() != null) { - descriptors.add(new DelegatingPropertyDescriptor<RECEIVER>(property)); + DelegatingPropertyDescriptor<RECEIVER> descriptor = new DelegatingPropertyDescriptor<RECEIVER>(property); + addDescriptor(descriptor); } } } public IPropertyDescriptor[] getPropertyDescriptors() { - return descriptors.toArray(new IPropertyDescriptor[descriptors.size()]); + return descriptors.values().toArray(new IPropertyDescriptor[descriptors.size()]); } public IPropertyDescriptor getPropertyDescriptor(Object id) { - for (IPropertyDescriptor propertyDescriptor : descriptors) + for (IPropertyDescriptor propertyDescriptor : descriptors.values()) { if (propertyDescriptor.getId().equals(id)) { |