diff options
Diffstat (limited to 'plugins')
67 files changed, 2788 insertions, 698 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java index d50088498c..b2d7900ffc 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/notifications/impl/DawnGMFHandler.java @@ -73,17 +73,25 @@ public class DawnGMFHandler extends BasicDawnTransactionHandler TRACER.format("Detached Objects {0} ", e.getDetachedObjects()); //$NON-NLS-1$ TRACER.format("Dirty Objects {0} ", e.getDirtyObjects()); //$NON-NLS-1$ } - adjustDeletedEdges(e); - for (CDOObject dirtyObject : e.getDirtyObjects()) + int xxx; + // if (!e.getDetachedObjects().isEmpty()) { - handleObject(dirtyObject); + editor.getDawnEditorSupport().refresh(); + return; } - for (CDOObject detachedObject : e.getDetachedObjects()) - { - handleObject(detachedObject); - } + // adjustDeletedEdges(e); + // + // for (CDOObject dirtyObject : e.getDirtyObjects()) + // { + // handleObject(dirtyObject); + // } + // + // for (CDOObject detachedObject : e.getDetachedObjects()) + // { + // handleObject(detachedObject); + // } } /** diff --git a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java index 96fb38bcd0..3ae568bf77 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java +++ b/plugins/org.eclipse.emf.cdo.dawn.gmf/src/org/eclipse/emf/cdo/dawn/gmf/util/DawnDiagramUpdater.java @@ -131,7 +131,6 @@ public class DawnDiagramUpdater { try { - // EObject modelElement = ((View)(editPart).getModel()).getElement(); // List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement); // for (Iterator it = editPolicies.iterator(); it.hasNext();) @@ -144,7 +143,7 @@ public class DawnDiagramUpdater } catch (Exception e) { - e.printStackTrace(); + //$FALL-THROUGH$ } if (editPart instanceof DiagramEditPart) diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnResourceFactoryImpl.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnResourceFactoryImpl.java index fd31c440d5..87264d0f92 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnResourceFactoryImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnResourceFactoryImpl.java @@ -25,6 +25,8 @@ public class DawnResourceFactoryImpl extends CDOResourceFactoryImpl implements D protected CDOResourceImpl createCDOResource(URI uri) { uri = URI.createURI(uri.toString().replace("dawn:", "cdo:")); - return new DawnWrapperResourceImpl(uri); + // return new DawnWrapperResourceImpl(uri); + + return new CDOResourceImpl(uri); } } diff --git a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnWrapperResourceImpl.java b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnWrapperResourceImpl.java index 43dfcf1c21..5aabc415c6 100644 --- a/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnWrapperResourceImpl.java +++ b/plugins/org.eclipse.emf.cdo.dawn/src/org/eclipse/emf/cdo/dawn/resources/impl/DawnWrapperResourceImpl.java @@ -56,109 +56,130 @@ public class DawnWrapperResourceImpl extends CDOResourceImpl implements DawnWrap /************ XML STUFF BEGIN ********************/ + @Override public DOMHelper getDOMHelper() { throw new UnsupportedOperationException(); } + @Override public Map<Object, Object> getDefaultLoadOptions() { throw new UnsupportedOperationException(); } + @Override public Map<Object, Object> getDefaultSaveOptions() { throw new UnsupportedOperationException(); } + @Override public Map<EObject, AnyType> getEObjectToExtensionMap() { throw new UnsupportedOperationException(); } + @Override @Deprecated public Map<EObject, String> getEObjectToIDMap() { throw new UnsupportedOperationException(); } + @Override public String getEncoding() { throw new UnsupportedOperationException(); } + @Override public String getID(EObject eObject) { return getURIFragment(eObject); } + @Override @Deprecated public Map<String, EObject> getIDToEObjectMap() { throw new UnsupportedOperationException(); } + @Override public String getPublicId() { throw new UnsupportedOperationException(); } + @Override public String getSystemId() { throw new UnsupportedOperationException(); } + @Override public String getXMLVersion() { throw new UnsupportedOperationException(); } + @Override public void load(Node node, Map<?, ?> options) throws IOException { throw new UnsupportedOperationException(); } + @Override public void load(InputSource inputSource, Map<?, ?> options) throws IOException { throw new UnsupportedOperationException(); } + @Override public void save(Writer writer, Map<?, ?> options) throws IOException { throw new UnsupportedOperationException(); } + @Override public Document save(Document document, Map<?, ?> options, DOMHandler handler) { throw new UnsupportedOperationException(); } + @Override public void setDoctypeInfo(String publicId, String systemId) { throw new UnsupportedOperationException(); } + @Override public void setEncoding(String encoding) { throw new UnsupportedOperationException(); } + @Override public void setID(EObject eObject, String id) { throw new UnsupportedOperationException(); } + @Override public void setUseZip(boolean useZip) { throw new UnsupportedOperationException(); } + @Override public void setXMLVersion(String version) { throw new UnsupportedOperationException(); } + @Override public boolean useZip() { return false; diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/.project b/plugins/org.eclipse.emf.cdo.explorer.ui/.project index 2066f9bf48..d41256489f 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/.project +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/.project @@ -16,6 +16,11 @@ </arguments> </buildCommand> <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name> <arguments> </arguments> diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/build.properties b/plugins/org.eclipse.emf.cdo.explorer.ui/build.properties index 9e30e92de4..8cef8ac9b3 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/build.properties +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/build.properties @@ -17,7 +17,9 @@ bin.includes = META-INF/,\ plugin.properties,\ .options,\ about.html,\ - icons/ + icons/,\ + schema/,\ + splash.bmp src.includes = about.html,\ CDOExplorer.launch diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/icons/cdo_editor.gif b/plugins/org.eclipse.emf.cdo.explorer.ui/icons/cdo_editor.gif Binary files differnew file mode 100644 index 0000000000..995960173e --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/icons/cdo_editor.gif diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml index e971b4569a..5f2d938882 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml @@ -13,6 +13,8 @@ <plugin> + <extension-point id="editorOpeners" name="Editor Openers" schema="schema/editorOpeners.exsd"/> + <extension id="app" point="org.eclipse.core.runtime.applications" name="%app.name"> <application> <run class="org.eclipse.emf.cdo.explorer.ui.application.CDOExplorerApplication"/> @@ -121,7 +123,7 @@ </description> </wizard> </extension> - + <extension point="org.eclipse.ui.newWizards"> <wizard category="org.eclipse.emf.cdo.category" @@ -525,11 +527,11 @@ allPopups="false" locationURI="popup:org.eclipse.ui.popup.any?after=group.checkout"> <command - commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckout" + commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutQuick" icon="icons/new_checkout.gif" - label="Checkout..." + label="Checkout" style="push" - tooltip="Check the repository out into the Project Explorer"> + tooltip="Check the repository out as an online connection"> <visibleWhen checkEnabled="false"> <with variable="activeMenuSelection"> <and> @@ -542,11 +544,11 @@ </visibleWhen> </command> <command - commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckoutQuick" - icon="icons/new_checkout_quick.gif" - label="Checkout Quick" + commandId="org.eclipse.emf.cdo.explorer.ui.RepositoryCheckout" + icon="icons/new_checkout.gif" + label="Checkout As..." style="push" - tooltip="Check the repository out as an online connection"> + tooltip="Check the repository out into the Project Explorer"> <visibleWhen checkEnabled="false"> <with variable="activeMenuSelection"> <and> @@ -723,20 +725,20 @@ id="org.eclipse.emf.cdo.explorer.ui.contribution1" objectClass="org.eclipse.emf.cdo.common.commit.CDOCommitInfo"> <action - class="org.eclipse.emf.cdo.explorer.ui.actions.CheckoutCommitInfoActionDelegate$Quick" + class="org.eclipse.emf.cdo.explorer.ui.actions.CheckoutCommitInfoActionDelegate" enablesFor="1" - icon="icons/new_checkout_quick.gif" + icon="icons/new_checkout.gif" id="org.eclipse.emf.cdo.explorer.ui.CheckoutCommitInfo" - label="Checkout Quick" + label="Checkout As..." menubarPath="additions" style="push"> </action> <action - class="org.eclipse.emf.cdo.explorer.ui.actions.CheckoutCommitInfoActionDelegate" + class="org.eclipse.emf.cdo.explorer.ui.actions.CheckoutCommitInfoActionDelegate$Quick" enablesFor="1" icon="icons/new_checkout.gif" id="org.eclipse.emf.cdo.explorer.ui.CheckoutCommitInfo" - label="Checkout..." + label="Checkout" menubarPath="additions" style="push"> </action> diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/schema/editorOpeners.exsd b/plugins/org.eclipse.emf.cdo.explorer.ui/schema/editorOpeners.exsd new file mode 100644 index 0000000000..a1151f2e59 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/schema/editorOpeners.exsd @@ -0,0 +1,140 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.emf.cdo.explorer.ui" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.emf.cdo.explorer.ui" id="editorOpeners" name="Editor Openers"/> + </appinfo> + <documentation> + [Enter description of this extension point.] + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="editorOpener"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="editorOpener"> + <complexType> + <attribute name="id" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="icon" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="resource"/> + </appinfo> + </annotation> + </attribute> + <attribute name="regex" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="priority" type="string" use="default" value="500"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.emf.cdo.explorer.ui.checkouts.CDOCheckoutEditorOpener"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="implementation"/> + </appinfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/bundle/OM.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/bundle/OM.java index 7c31debabd..9166c66fd0 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/bundle/OM.java @@ -11,6 +11,7 @@ */ package org.eclipse.emf.cdo.explorer.ui.bundle; +import org.eclipse.emf.cdo.explorer.ui.checkouts.CDOCheckoutEditorOpenerRegistry; import org.eclipse.emf.cdo.ui.OverlayImage; import org.eclipse.net4j.util.om.OMBundle; @@ -87,5 +88,17 @@ public abstract class OM super(BUNDLE); INSTANCE = this; } + + @Override + protected void doStart() throws Exception + { + CDOCheckoutEditorOpenerRegistry.INSTANCE.activate(); + } + + @Override + protected void doStop() throws Exception + { + CDOCheckoutEditorOpenerRegistry.INSTANCE.deactivate(); + } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java index 640a049d37..7bd28f3d9a 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java @@ -16,7 +16,7 @@ import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.revision.CDOList; import org.eclipse.emf.cdo.common.revision.CDORevision; import org.eclipse.emf.cdo.common.revision.CDORevisionManager; -import org.eclipse.emf.cdo.eresource.CDOResourceFolder; +import org.eclipse.emf.cdo.eresource.CDOResourceNode; import org.eclipse.emf.cdo.explorer.CDOExplorerManager; import org.eclipse.emf.cdo.explorer.CDOExplorerManager.ElementsChangedEvent; import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; @@ -864,16 +864,17 @@ public class CDOCheckoutContentProvider implements ICommonContentProvider, IProp ViewerUtil.expand(viewer, checkout, true); } } - else if (element instanceof CDOResourceFolder) + else if (element instanceof CDOResourceNode) { // Do nothing special. } else if (element instanceof EObject) { EObject eObject = (EObject)element; - IWorkbenchPage page = getWorkbenchPage(); + + Shell shell = getWorkbenchPage().getWorkbenchWindow().getShell(); ComposedAdapterFactory adapterFactory = stateManager.getAdapterFactory(eObject); - OpenWithActionProvider.openEditor(page, adapterFactory, eObject, null); + OpenWithActionProvider.editObject(shell, adapterFactory, eObject); } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpener.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpener.java new file mode 100644 index 0000000000..ef1af4ece2 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpener.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2009-2013 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.checkouts; + +import org.eclipse.emf.cdo.explorer.ui.bundle.OM; + +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; + +import org.eclipse.emf.common.util.URI; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; + +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Eike Stepper + */ +public interface CDOCheckoutEditorOpener +{ + public static final int DEFAULT_PRIORITY = 500; + + public String getID(); + + public String getName(); + + public ImageDescriptor getIcon(); + + /** + * Returns the priority of this editor opener. Usually used to choose between several editor openers that + * match the same repository URI. + */ + public int getPriority(); + + /** + * Returns the regular expression that determines if the editor opener can open a certain URI. + */ + public String getRegex(); + + /** + * Checks if the URI matches the regular expression of this editor opener. + */ + public boolean matchesRegex(URI uri); + + public IEditorPart openEditor(IWorkbenchPage page, URI uri); + + /** + * @author Eike Stepper + */ + public static abstract class Default implements CDOCheckoutEditorOpener + { + private String id; + + private String name; + + private ImageDescriptor icon; + + private String regex; + + private int priority = DEFAULT_PRIORITY; + + @ExcludeFromDump + private transient Pattern pattern; + + public Default() + { + } + + public Default(String id, String name, ImageDescriptor icon, String regex, int priority) + { + this.id = id; + this.name = name; + this.icon = icon; + this.regex = regex; + this.priority = priority; + } + + public String getID() + { + return id; + } + + public String getName() + { + return name; + } + + public ImageDescriptor getIcon() + { + return icon; + } + + public final int getPriority() + { + return priority; + } + + public final String getRegex() + { + return regex; + } + + public final boolean matchesRegex(URI uri) + { + synchronized (regex) + { + if (pattern == null) + { + pattern = Pattern.compile(regex); + } + } + + Matcher matcher = pattern.matcher(uri.toString()); + return matcher.matches(); + } + + public IEditorPart openEditor(final IWorkbenchPage page, URI uri) + { + final Set<IEditorPart> editors = new HashSet<IEditorPart>(); + final IEditorPart[] editor = { null }; + + IPartListener partListener = new IPartListener() + { + public void partClosed(IWorkbenchPart part) + { + if (part == editor[0]) + { + try + { + // view.close(); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + finally + { + page.removePartListener(this); + } + } + } + + public void partOpened(IWorkbenchPart part) + { + // Do nothing. + } + + public void partDeactivated(IWorkbenchPart part) + { + // Do nothing. + } + + public void partBroughtToTop(IWorkbenchPart part) + { + // Do nothing. + } + + public void partActivated(IWorkbenchPart part) + { + // Do nothing. + } + }; + + page.addPartListener(partListener); + editor[0] = doOpenEditor(page, uri); + + if (!editors.contains(editor)) + { + // The editor must have been open already and someone else will handle close. + page.removePartListener(partListener); + } + + return editor[0]; + } + + protected abstract IEditorPart doOpenEditor(IWorkbenchPage page, URI uri); + + @Override + public String toString() + { + return id + "[" + regex + "]"; + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpenerRegistry.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpenerRegistry.java new file mode 100644 index 0000000000..6abca20f71 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutEditorOpenerRegistry.java @@ -0,0 +1,397 @@ +/* + * Copyright (c) 2009-2013 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.checkouts; + +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.ui.CDOEditorUtil; +import org.eclipse.emf.cdo.util.CDOURIUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.om.OMPlatform; + +import org.eclipse.emf.common.util.URI; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Eike Stepper + */ +public class CDOCheckoutEditorOpenerRegistry extends Container<CDOCheckoutEditorOpener> +{ + public static final CDOCheckoutEditorOpenerRegistry INSTANCE = new CDOCheckoutEditorOpenerRegistry(); + + private static final String EXT_POINT = "editorOpeners"; //$NON-NLS-1$ + + private final Map<String, CDOCheckoutEditorOpener> editorOpeners = new HashMap<String, CDOCheckoutEditorOpener>(); + + public CDOCheckoutEditorOpenerRegistry() + { + addEditorOpener(new CDOModelEditorOpener()); + } + + public IEditorPart openEditor(IWorkbenchPage page, URI uri) + { + if (uri == null) + { + return null; + } + + for (CDOCheckoutEditorOpener editorOpener : getEditorOpeners(uri)) + { + IEditorPart editor = editorOpener.openEditor(page, uri); + if (editor != null) + { + return editor; + } + } + + return null; + } + + public CDOCheckoutEditorOpener getEditorOpener(String id) + { + synchronized (editorOpeners) + { + return editorOpeners.get(id); + } + } + + public CDOCheckoutEditorOpener[] getEditorOpeners(URI uri) + { + List<CDOCheckoutEditorOpener> result = new ArrayList<CDOCheckoutEditorOpener>(); + + synchronized (editorOpeners) + { + for (CDOCheckoutEditorOpener editorOpener : editorOpeners.values()) + { + if (editorOpener.matchesRegex(uri)) + { + result.add(editorOpener); + } + } + } + + // Sort highest priority first + Collections.sort(result, new Comparator<CDOCheckoutEditorOpener>() + { + public int compare(CDOCheckoutEditorOpener o1, CDOCheckoutEditorOpener o2) + { + return -Integer.valueOf(o1.getPriority()).compareTo(o2.getPriority()); + } + }); + + return result.toArray(new CDOCheckoutEditorOpener[result.size()]); + } + + public void addEditorOpener(CDOCheckoutEditorOpener editorOpener) + { + boolean added; + synchronized (editorOpeners) + { + String id = editorOpener.getID(); + added = !editorOpeners.containsKey(id); + if (added) + { + editorOpeners.put(id, editorOpener); + } + } + + if (added) + { + fireElementAddedEvent(editorOpener); + } + } + + public void removeEditorOpener(CDOCheckoutEditorOpener editorOpener) + { + boolean removed; + synchronized (editorOpeners) + { + String id = editorOpener.getID(); + removed = editorOpeners.remove(id) != null; + } + + if (removed) + { + fireElementRemovedEvent(editorOpener); + } + } + + public CDOCheckoutEditorOpener[] getElements() + { + synchronized (editorOpeners) + { + return editorOpeners.values().toArray(new CDOCheckoutEditorOpener[editorOpeners.size()]); + } + } + + @Override + public boolean isEmpty() + { + synchronized (editorOpeners) + { + return editorOpeners.isEmpty(); + } + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + if (OMPlatform.INSTANCE.isOSGiRunning()) + { + try + { + readExtensions(); + } + catch (Throwable t) + { + OM.LOG.error(t); + } + } + } + + public void readExtensions() + { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT); + for (IConfigurationElement element : configurationElements) + { + try + { + EditorOpenerDescriptor descriptor = new EditorOpenerDescriptor(element); + addEditorOpener(descriptor); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + } + + /** + * @author Eike Stepper + */ + private static final class CDOModelEditorOpener extends CDOCheckoutEditorOpener.Default + { + private static final String REGEX = "cdo\\.checkout://.*"; + + public CDOModelEditorOpener() + { + super(CDOEditorUtil.EDITOR_ID, "CDO Editor", OM.getImageDescriptor("icons/cdo_editor.gif"), REGEX, 100); + } + + @Override + protected IEditorPart doOpenEditor(final IWorkbenchPage page, URI uri) + { + CDOCheckout checkout = CDOExplorerUtil.getCheckout(uri); + final CDOView view = checkout.openView(); + + final IEditorPart editor = openEditor(page, view, CDOURIUtil.extractResourcePath(uri)); + page.addPartListener(new IPartListener() + { + public void partClosed(IWorkbenchPart part) + { + if (part == editor) + { + try + { + view.close(); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + finally + { + page.removePartListener(this); + } + } + } + + public void partOpened(IWorkbenchPart part) + { + // Do nothing. + } + + public void partDeactivated(IWorkbenchPart part) + { + // Do nothing. + } + + public void partBroughtToTop(IWorkbenchPart part) + { + // Do nothing. + } + + public void partActivated(IWorkbenchPart part) + { + // Do nothing. + } + }); + + return editor; + } + + private IEditorPart openEditor(IWorkbenchPage page, CDOView view, String resourcePath) + { + try + { + String editorID = CDOEditorUtil.getEditorID(); + + IEditorReference[] references = CDOEditorUtil.findEditor(page, view, resourcePath); + for (IEditorReference reference : references) + { + if (editorID.equals(reference.getId())) + { + IEditorPart editor = references[0].getEditor(true); + page.activate(editor); + return editor; + } + } + + IEditorInput input = CDOEditorUtil.createCDOEditorInput(view, resourcePath, false); + return page.openEditor(input, editorID); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + + return null; + } + } + + /** + * @author Eike Stepper + */ + public static final class EditorOpenerDescriptor extends CDOCheckoutEditorOpener.Default + { + private IConfigurationElement element; + + public EditorOpenerDescriptor(IConfigurationElement element) + { + super(getID(element), getName(element), getIcon(element), getRegex(element), getPriority(element)); + this.element = element; + + if (StringUtil.isEmpty(element.getAttribute("class"))) //$NON-NLS-1$ + { + throw new IllegalArgumentException(MessageFormat.format("Class not defined for extension {0}", element)); //$NON-NLS-1$ + } + } + + @Override + protected IEditorPart doOpenEditor(IWorkbenchPage page, URI uri) + { + return getEditorOpener().openEditor(page, uri); + } + + private CDOCheckoutEditorOpener getEditorOpener() + { + try + { + return (CDOCheckoutEditorOpener)element.createExecutableExtension("class"); //$NON-NLS-1$ + } + catch (CoreException ex) + { + throw WrappedException.wrap(ex); + } + } + + private static String getID(IConfigurationElement element) + { + String value = element.getAttribute("id"); //$NON-NLS-1$ + if (StringUtil.isEmpty(value)) + { + throw new IllegalArgumentException(MessageFormat.format("ID not defined for extension {0}", element)); //$NON-NLS-1$ + } + + return value; + } + + private static String getName(IConfigurationElement element) + { + String value = element.getAttribute("name"); //$NON-NLS-1$ + if (StringUtil.isEmpty(value)) + { + throw new IllegalArgumentException(MessageFormat.format("Name not defined for extension {0}", element)); //$NON-NLS-1$ + } + + return value; + } + + private static ImageDescriptor getIcon(IConfigurationElement element) + { + String icon = element.getAttribute("icon"); //$NON-NLS-1$ + if (icon != null) + { + try + { + return AbstractUIPlugin.imageDescriptorFromPlugin(element.getNamespaceIdentifier(), icon); + } + catch (Exception ex) + { + //$FALL-THROUGH$ + } + } + + return null; + } + + private static String getRegex(IConfigurationElement element) + { + String value = element.getAttribute("regex"); //$NON-NLS-1$ + if (StringUtil.isEmpty(value)) + { + throw new IllegalArgumentException(MessageFormat.format("Regex not defined for extension {0}", element)); //$NON-NLS-1$ + } + + return value; + } + + private static int getPriority(IConfigurationElement element) + { + try + { + String value = element.getAttribute("priority"); //$NON-NLS-1$ + return Integer.parseInt(value); + } + catch (Exception ex) + { + return DEFAULT_PRIORITY; + } + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/NewActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/NewActionProvider.java index 41edeb965b..47f970b1ef 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/NewActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/NewActionProvider.java @@ -445,7 +445,8 @@ public class NewActionProvider extends CommonActionProvider implements ISelectio @Override protected final void doRun(CDOTransaction transaction, CDOObject parent, IProgressMonitor monitor) throws Exception { - newObject = doRun(transaction, parent, new StructuredSelection(parent)); + ISelection selection = new StructuredSelection(CDOUtil.getEObject(parent)); + newObject = doRun(transaction, parent, selection); } protected abstract EObject doRun(CDOTransaction transaction, CDOObject parent, ISelection selection); diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/OpenWithActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/OpenWithActionProvider.java index a7c9eb9ab1..5e4a9e1591 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/OpenWithActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/OpenWithActionProvider.java @@ -11,32 +11,31 @@ package org.eclipse.emf.cdo.explorer.ui.checkouts.actions; import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.eresource.CDOResourceFolder; import org.eclipse.emf.cdo.eresource.CDOResourceLeaf; import org.eclipse.emf.cdo.eresource.CDOResourceNode; 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.explorer.ui.checkouts.CDOCheckoutEditorOpener; +import org.eclipse.emf.cdo.explorer.ui.checkouts.CDOCheckoutEditorOpenerRegistry; import org.eclipse.emf.cdo.internal.ui.dialogs.EditObjectDialog; 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; -import org.eclipse.net4j.util.collection.Pair; +import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IMenuManager; @@ -44,65 +43,53 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IPageListener; -import org.eclipse.ui.IPartListener2; -import org.eclipse.ui.IWindowListener; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartReference; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.navigator.CommonActionProvider; import org.eclipse.ui.navigator.ICommonActionConstants; import org.eclipse.ui.navigator.ICommonActionExtensionSite; import org.eclipse.ui.navigator.ICommonMenuConstants; import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; -import java.util.HashMap; -import java.util.Map; - /** * @author Eike Stepper */ public class OpenWithActionProvider extends CommonActionProvider { - private static final String WORKBENCH_PART_KEY = IWorkbenchPart.class.getName(); - - private static final Map<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>> VIEWS = new HashMap<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>>(); - - private static final Map<Pair<CDOResourceLeaf, String>, Object> EDITORS = new HashMap<Pair<CDOResourceLeaf, String>, Object>(); - - private static final Object EDITOR_OPENING = new Object(); - - private static final IPartListener2 PART_LISTENER = new PartListener(); - - private static final IPageListener PAGE_LISTENER = new PageListener(); - - private static final IWindowListener WINDOW_LISTENER = new WindowListener(); - - static - { - IWorkbench workbench = UIUtil.getWorkbench(); - for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) - { - window.addPageListener(PAGE_LISTENER); - - for (IWorkbenchPage page : window.getPages()) - { - page.addPartListener(PART_LISTENER); - } - } - - workbench.addWindowListener(WINDOW_LISTENER); - } + // private static final String WORKBENCH_PART_KEY = IWorkbenchPart.class.getName(); + // + // private static final Map<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>> VIEWS = new + // HashMap<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>>(); + // + // private static final Map<Pair<CDOResourceLeaf, String>, Object> EDITORS = new HashMap<Pair<CDOResourceLeaf, + // String>, Object>(); + // + // private static final Object EDITOR_OPENING = new Object(); + // + // private static final IPartListener2 PART_LISTENER = new PartListener(); + // + // private static final IPageListener PAGE_LISTENER = new PageListener(); + // + // private static final IWindowListener WINDOW_LISTENER = new WindowListener(); + // + // static + // { + // IWorkbench workbench = UIUtil.getWorkbench(); + // for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) + // { + // window.addPageListener(PAGE_LISTENER); + // + // for (IWorkbenchPage page : window.getPages()) + // { + // page.addPartListener(PART_LISTENER); + // } + // } + // + // workbench.addWindowListener(WINDOW_LISTENER); + // } private ICommonViewerWorkbenchSite viewSite; - private OpenFileAction openFileAction; + private OpenAction openAction; public OpenWithActionProvider() { @@ -114,7 +101,7 @@ public class OpenWithActionProvider extends CommonActionProvider if (aConfig.getViewSite() instanceof ICommonViewerWorkbenchSite) { viewSite = (ICommonViewerWorkbenchSite)aConfig.getViewSite(); - openFileAction = new OpenFileAction(viewSite.getPage()); + openAction = new OpenAction(viewSite.getPage()); } } @@ -128,10 +115,10 @@ public class OpenWithActionProvider extends CommonActionProvider Object selectedElement = getSelectedElement(); - openFileAction.selectionChanged(selectedElement); - if (openFileAction.isEnabled()) + openAction.selectionChanged(selectedElement); + if (openAction.isEnabled()) { - actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openFileAction); + actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openAction); } } @@ -145,57 +132,60 @@ public class OpenWithActionProvider extends CommonActionProvider Object selectedElement = getSelectedElement(); - openFileAction.selectionChanged(selectedElement); - if (openFileAction.isEnabled()) + openAction.selectionChanged(selectedElement); + if (openAction.isEnabled()) { - menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openFileAction); + menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openAction); addOpenWithMenu(menu, selectedElement); } } - private Object getSelectedElement() - { - IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); - if (selection.size() == 1) - { - return selection.getFirstElement(); - } - - return null; - } - private void addOpenWithMenu(IMenuManager menu, Object selectedElement) { EObject openableElement = getOpenableElement(selectedElement); - if (openableElement == null) + if (openableElement != null) { - return; - } + CDOObject cdoObject = CDOUtil.getCDOObject(openableElement); + CDOResourceLeaf resourceLeaf = getResourceLeaf(cdoObject); + if (resourceLeaf instanceof CDOResource) + { + CDOResource resource = (CDOResource)resourceLeaf; - CDOObject cdoObject = CDOUtil.getCDOObject(openableElement); - CDOResourceLeaf resourceLeaf = getResourceLeaf(cdoObject); - if (resourceLeaf == null) - { - return; - } + URI uri = resource.getURI(); + uri = resource.getResourceSet().getURIConverter().normalize(uri); - String[] editorIDs = CDOEditorUtil.getAllEditorIDs(resourceLeaf); - if (editorIDs.length == 0) - { - return; - } + CDOCheckout checkout = CDOExplorerUtil.getCheckout(cdoObject); + if (checkout != null) + { + CDOCheckoutEditorOpener[] editorOpeners = CDOCheckoutEditorOpenerRegistry.INSTANCE.getEditorOpeners(uri); + if (editorOpeners.length != 0) + { + IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH); + submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP)); - IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH); - submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP)); + for (CDOCheckoutEditorOpener editorOpener : editorOpeners) + { + OpenWithAction action = new OpenWithAction(viewSite.getPage(), cdoObject, editorOpener); + submenu.add(action); + } + + submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS)); + menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, submenu); + } + } + } + } + } - for (String editorID : editorIDs) + private Object getSelectedElement() + { + IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); + if (selection.size() == 1) { - OpenFileAction action = new OpenFileAction(viewSite.getPage(), cdoObject, editorID); - submenu.add(action); + return selection.getFirstElement(); } - submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS)); - menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, submenu); + return null; } private static EObject getOpenableElement(Object element) @@ -228,60 +218,63 @@ public class OpenWithActionProvider extends CommonActionProvider return cdoObject.cdoResource(); } - private static void openEditor(final IWorkbenchPage page, final CDOObject object, final CDOResourceLeaf resourceLeaf, - final String editorID, final Pair<CDOResourceLeaf, String> key) - { - new Job("Open") - { - @Override - protected IStatus run(IProgressMonitor monitor) - { - final CDOCheckout checkout = CDOExplorerUtil.getCheckout(object); - final CDOView view = checkout.openView(); - - final CDOResourceLeaf contextualLeaf = view.getObject(resourceLeaf); - final IEditorInput editorInput = CDOEditorUtil.createEditorInput(editorID, contextualLeaf, false, true); - - Shell shell = page.getWorkbenchWindow().getShell(); - if (!shell.isDisposed()) - { - shell.getDisplay().asyncExec(new Runnable() - { - public void run() - { - try - { - IEditorPart editor = page.openEditor(editorInput, editorID); - if (editor != null) - { - view.properties().put(WORKBENCH_PART_KEY, editor); - - synchronized (EDITORS) - { - EDITORS.put(key, editor); - } - - synchronized (VIEWS) - { - VIEWS.put(editor, Pair.create(view, key)); - } - } - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - }); - } - - return Status.OK_STATUS; - } - }.schedule(); - } + // private static IEditorInput createEditorInput(String editorID, CDOCheckout checkout, CDOResourceLeaf resourceLeaf) + // { + // if (CDOEditorUtil.EDITOR_ID.equals(editorID)) + // { + // return CDOEditorUtil.createEditorInput(editorID, resourceLeaf, false, true); + // } + // + // String path = resourceLeaf.getPath(); + // URI uri = checkout.createResourceURI(path); + // return new URIEditorInput(uri); + // } + // + // private static void openEditor(final IWorkbenchPage page, final CDOObject object, final CDOResourceLeaf + // resourceLeaf, + // final String editorID, final Pair<CDOResourceLeaf, String> key) + // { + // new Job("Open") + // { + // @Override + // protected IStatus run(IProgressMonitor monitor) + // { + // final CDOCheckout checkout = CDOExplorerUtil.getCheckout(object); + // final CDOView view = checkout.openView(); + // + // final CDOResourceLeaf contextualLeaf = view.getObject(resourceLeaf); + // final IEditorInput editorInput = createEditorInput(editorID, checkout, contextualLeaf); + // + // Shell shell = page.getWorkbenchWindow().getShell(); + // if (!shell.isDisposed()) + // { + // shell.getDisplay().asyncExec(new Runnable() + // { + // public void run() + // { + // try + // { + // IEditorPart editor = page.openEditor(editorInput, editorID); + // if (editor != null) + // { + // registerEditor(editor, view, key); + // } + // } + // catch (Exception ex) + // { + // OM.LOG.error(ex); + // } + // } + // }); + // } + // + // return Status.OK_STATUS; + // } + // }.schedule(); + // } public static void openEditor(IWorkbenchPage page, ComposedAdapterFactory adapterFactory, EObject object, - String editorID) + String editorOpenerID) { if (page == null) { @@ -293,7 +286,7 @@ public class OpenWithActionProvider extends CommonActionProvider throw new IllegalArgumentException("object is null"); } - if (editorID == null && !(object instanceof CDOResourceNode)) + if (editorOpenerID == null && !(object instanceof CDOResourceNode)) { if (adapterFactory == null) { @@ -310,44 +303,70 @@ public class OpenWithActionProvider extends CommonActionProvider CDOObject cdoObject = CDOUtil.getCDOObject(object); CDOResourceLeaf resourceLeaf = getResourceLeaf(cdoObject); - if (resourceLeaf == null) + if (resourceLeaf instanceof CDOResource) { - return; - } + CDOResource resource = (CDOResource)resourceLeaf; - if (editorID == null) - { - CDOCheckout checkout = CDOExplorerUtil.getCheckout(object); + URI uri = resource.getURI(); + uri = resource.getResourceSet().getURIConverter().normalize(uri); + + CDOCheckout checkout = CDOExplorerUtil.getCheckout(cdoObject); if (checkout != null) { - editorID = checkout.getEditorID(cdoObject.cdoID()); - } - } + CDOCheckoutEditorOpener[] editorOpeners = CDOCheckoutEditorOpenerRegistry.INSTANCE.getEditorOpeners(uri); + String defaultEditorOpenerID = editorOpeners.length != 0 ? editorOpeners[0].getID() : null; - if (editorID == null) - { - editorID = CDOEditorUtil.getEffectiveEditorID(resourceLeaf); - } + CDOID objectID = cdoObject.cdoID(); + String lastEditorOpenerID = checkout.getEditorOpenerID(objectID); - Pair<CDOResourceLeaf, String> key = Pair.create(resourceLeaf, editorID); + if (editorOpenerID == null) + { + editorOpenerID = lastEditorOpenerID; + } - synchronized (EDITORS) - { - Object editor = EDITORS.get(key); - if (editor != null) - { - if (editor != EDITOR_OPENING) + if (editorOpenerID == null) { - page.activate((IEditorPart)editor); + editorOpenerID = defaultEditorOpenerID; } - return; - } + if (editorOpenerID != null) + { + CDOCheckoutEditorOpener editorOpener = CDOCheckoutEditorOpenerRegistry.INSTANCE + .getEditorOpener(editorOpenerID); + if (editorOpener != null) + { + if (!ObjectUtil.equals(editorOpenerID, lastEditorOpenerID)) + { + checkout.setEditorOpenerID(objectID, editorOpenerID); + } - EDITORS.put(key, EDITOR_OPENING); + editorOpener.openEditor(page, uri); + } + } + else + { + // Pair<CDOResourceLeaf, String> key = Pair.create(resourceLeaf, editorOpenerID); + // + // synchronized (EDITORS) + // { + // Object editor = EDITORS.get(key); + // if (editor != null) + // { + // if (editor != EDITOR_OPENING) + // { + // page.activate((IEditorPart)editor); + // } + // + // return; + // } + // + // EDITORS.put(key, EDITOR_OPENING); + // } + // + // openEditor(page, cdoObject, resourceLeaf, editorOpenerID, key); + } + } } - - openEditor(page, cdoObject, resourceLeaf, editorID, key); } public static boolean editObject(Shell shell, ComposedAdapterFactory adapterFactory, EObject object) @@ -389,168 +408,229 @@ public class OpenWithActionProvider extends CommonActionProvider return edited; } - /** - * @author Eike Stepper - */ - private static final class WindowListener implements IWindowListener - { - public void windowOpened(IWorkbenchWindow window) - { - window.addPageListener(PAGE_LISTENER); - } - - public void windowClosed(IWorkbenchWindow window) - { - window.removePageListener(PAGE_LISTENER); - } - - public void windowActivated(IWorkbenchWindow window) - { - // Do nothing - } - - public void windowDeactivated(IWorkbenchWindow window) - { - // Do nothing - } - } + // private static void registerEditor(IEditorPart editor, CDOView view, Pair<CDOResourceLeaf, String> key) + // { + // view.properties().put(WORKBENCH_PART_KEY, editor); + // + // synchronized (EDITORS) + // { + // EDITORS.put(key, editor); + // } + // + // synchronized (VIEWS) + // { + // VIEWS.put(editor, Pair.create(view, key)); + // } + // } + // + // /** + // * @author Eike Stepper + // */ + // private static final class WindowListener implements IWindowListener + // { + // public void windowOpened(IWorkbenchWindow window) + // { + // window.addPageListener(PAGE_LISTENER); + // } + // + // public void windowClosed(IWorkbenchWindow window) + // { + // window.removePageListener(PAGE_LISTENER); + // } + // + // public void windowActivated(IWorkbenchWindow window) + // { + // // Do nothing + // } + // + // public void windowDeactivated(IWorkbenchWindow window) + // { + // // Do nothing + // } + // } + // + // /** + // * @author Eike Stepper + // */ + // private static final class PageListener implements IPageListener + // { + // public void pageOpened(IWorkbenchPage page) + // { + // page.addPartListener(PART_LISTENER); + // } + // + // public void pageClosed(IWorkbenchPage page) + // { + // page.removePartListener(PART_LISTENER); + // } + // + // public void pageActivated(IWorkbenchPage page) + // { + // // Do nothing + // } + // } + // + // /** + // * @author Eike Stepper + // */ + // private static final class PartListener implements IPartListener2 + // { + // public void partOpened(IWorkbenchPartReference partRef) + // { + // } + // + // public void partClosed(IWorkbenchPartReference partRef) + // { + // IWorkbenchPart part = partRef.getPart(false); + // if (part != null) + // { + // Pair<CDOView, Pair<CDOResourceLeaf, String>> pair; + // synchronized (VIEWS) + // { + // pair = VIEWS.remove(part); + // } + // + // if (pair != null) + // { + // CDOView view = pair.getElement1(); + // view.close(); + // + // Pair<CDOResourceLeaf, String> key = pair.getElement2(); + // synchronized (EDITORS) + // { + // EDITORS.remove(key); + // } + // } + // } + // } + // + // public void partVisible(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // + // public void partHidden(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // + // public void partActivated(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // + // public void partDeactivated(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // + // public void partBroughtToTop(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // + // public void partInputChanged(IWorkbenchPartReference partRef) + // { + // // Do nothing + // } + // } /** * @author Eike Stepper */ - private static final class PageListener implements IPageListener + private static class OpenAction extends Action { - public void pageOpened(IWorkbenchPage page) - { - page.addPartListener(PART_LISTENER); - } - - public void pageClosed(IWorkbenchPage page) - { - page.removePartListener(PART_LISTENER); - } + public static final String ID = OM.BUNDLE_ID + ".OpenAction"; //$NON-NLS-1$ - public void pageActivated(IWorkbenchPage page) - { - // Do nothing - } - } - - /** - * @author Eike Stepper - */ - private static final class PartListener implements IPartListener2 - { - public void partOpened(IWorkbenchPartReference partRef) - { - } - - public void partClosed(IWorkbenchPartReference partRef) - { - IWorkbenchPart part = partRef.getPart(false); - if (part != null) - { - Pair<CDOView, Pair<CDOResourceLeaf, String>> pair; - synchronized (VIEWS) - { - pair = VIEWS.remove(part); - } - - if (pair != null) - { - CDOView view = pair.getElement1(); - view.close(); - - Pair<CDOResourceLeaf, String> key = pair.getElement2(); - synchronized (EDITORS) - { - EDITORS.remove(key); - } - } - } - } - - public void partVisible(IWorkbenchPartReference partRef) - { - // Do nothing - } - - public void partHidden(IWorkbenchPartReference partRef) - { - // Do nothing - } + private final IWorkbenchPage page; - public void partActivated(IWorkbenchPartReference partRef) - { - // Do nothing - } + private EObject openableElement; - public void partDeactivated(IWorkbenchPartReference partRef) + public OpenAction(IWorkbenchPage page) { - // Do nothing + super("Open"); + setId(ID); + setToolTipText("Edit this resource"); + this.page = page; } - public void partBroughtToTop(IWorkbenchPartReference partRef) + public void selectionChanged(Object selectedElement) { - // Do nothing + openableElement = getOpenableElement(selectedElement); + setEnabled(openableElement != null); } - public void partInputChanged(IWorkbenchPartReference partRef) + @Override + public void run() { - // Do nothing + openEditor(page, null, openableElement, null); } } /** * @author Eike Stepper */ - private static class OpenFileAction extends Action + private static class OpenWithAction extends Action { - public static final String ID = OM.BUNDLE_ID + ".OpenFileAction"; //$NON-NLS-1$ + public static final String ID = OM.BUNDLE_ID + ".OpenWithAction"; //$NON-NLS-1$ private final IWorkbenchPage page; private EObject openableElement; - private String editorID; - - public OpenFileAction(IWorkbenchPage page) - { - this(page, null, null); - } + private CDOCheckoutEditorOpener editorOpener; - public OpenFileAction(IWorkbenchPage page, EObject openableElement, String editorID) + public OpenWithAction(IWorkbenchPage page, EObject openableElement, CDOCheckoutEditorOpener editorOpener) { setId(ID); + setText(editorOpener.getName()); + setImageDescriptor(editorOpener.getIcon()); + setToolTipText("Edit this resource"); this.page = page; this.openableElement = openableElement; - this.editorID = editorID; - - if (editorID != null) - { - IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(editorID); - setText(editorDescriptor.getLabel()); - setImageDescriptor(editorDescriptor.getImageDescriptor()); - } - else - { - setText("Open"); - } - - setToolTipText("Edit this resource"); - } - - public void selectionChanged(Object selectedElement) - { - openableElement = getOpenableElement(selectedElement); - setEnabled(openableElement != null); + this.editorOpener = editorOpener; } @Override public void run() { - openEditor(page, null, openableElement, editorID); + openEditor(page, null, openableElement, editorOpener.getID()); } } + + // /** + // * @author Eike Stepper + // */ + // private static class OpenFileAction extends Action + // { + // public static final String ID = OM.BUNDLE_ID + ".OpenFileAction"; //$NON-NLS-1$ + // + // private final IWorkbenchPage page; + // + // private EObject openableElement; + // + // private String editorID; + // + // public OpenFileAction(IWorkbenchPage page, EObject openableElement, String editorID) + // { + // setId(ID); + // + // this.page = page; + // this.openableElement = openableElement; + // this.editorID = editorID; + // + // IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(editorID); + // setText(editorDescriptor.getLabel()); + // setImageDescriptor(editorDescriptor.getImageDescriptor()); + // + // setToolTipText("Edit this resource"); + // } + // + // @Override + // public void run() + // { + // openEditor(page, null, openableElement, editorID); + // } + // } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/ShowInActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/ShowInActionProvider.java index 0a01fee3e7..807611690a 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/ShowInActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/actions/ShowInActionProvider.java @@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.internal.explorer.AbstractElement; import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; import org.eclipse.emf.cdo.internal.explorer.repositories.LocalCDORepository; import org.eclipse.emf.cdo.internal.ui.views.CDOSessionsView; +import org.eclipse.emf.cdo.internal.ui.views.CDOTimeMachineView; import org.eclipse.emf.cdo.server.CDOServerBrowser; import org.eclipse.emf.cdo.server.internal.db.DBBrowserPage; import org.eclipse.emf.cdo.session.CDOSession; @@ -171,6 +172,11 @@ public class ShowInActionProvider extends AbstractActionProvider<Object> filled |= addAction(menu, checkout, new ShowInSessionsViewAction(page, checkout.getRepository(), checkout)); } + if (checkout.isReadOnly()) + { + filled |= addAction(menu, checkout, new ShowInViewAction(page, CDOTimeMachineView.ID)); + } + filled |= addAction(menu, checkout.getView(), new ShowInViewAction(page, HISTORY_VIEW_ID)); } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/CheckoutTypePage.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/CheckoutTypePage.java index f995a62849..f7cb0e78a3 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/CheckoutTypePage.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/CheckoutTypePage.java @@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.explorer.ui.checkouts.wizards; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl; @@ -180,10 +181,12 @@ public class CheckoutTypePage extends CheckoutWizardPage { transactionalButton.setEnabled(true); - if (repository.getVersioningMode().isSupportingAudits()) + VersioningMode versioningMode = repository.getVersioningMode(); + if (versioningMode == null || versioningMode.isSupportingAudits()) { historicalButton.setEnabled(true); - if (repository.getIDGeneration() == IDGeneration.UUID) + IDGeneration idGeneration = repository.getIDGeneration(); + if (idGeneration == null || idGeneration == IDGeneration.UUID) { offlineButton.setEnabled(true); } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandlerQuick.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandlerQuick.java index 04cd5b6bc4..8d15b811a1 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandlerQuick.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/RepositoryCheckoutHandlerQuick.java @@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.explorer.ui.checkouts.wizards.CheckoutLabelPage; import org.eclipse.emf.cdo.explorer.ui.checkouts.wizards.CheckoutWizard; import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl; +import org.eclipse.net4j.util.AdapterUtil; import org.eclipse.net4j.util.ui.handlers.AbstractBaseHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -41,9 +42,10 @@ public class RepositoryCheckoutHandlerQuick extends AbstractBaseHandler<CDORepos checkout(elements.get(0), CDOCheckout.TYPE_ONLINE_TRANSACTIONAL); } - public static void checkout(CDORepositoryElement repositoryElement, String type) + public static CDOCheckout checkout(CDORepositoryElement repositoryElement, String type) { CDORepository repository = repositoryElement.getRepository(); + String readOnly = (CDOCheckout.TYPE_ONLINE_HISTORICAL.equals(type) ? Boolean.TRUE : Boolean.FALSE).toString(); Properties properties = new Properties(); properties.setProperty("type", type); @@ -51,12 +53,19 @@ public class RepositoryCheckoutHandlerQuick extends AbstractBaseHandler<CDORepos properties.setProperty("repository", repository.getID()); properties.setProperty("branchID", Integer.toString(repositoryElement.getBranchID())); properties.setProperty("timeStamp", Long.toString(repositoryElement.getTimeStamp())); - properties.setProperty("readOnly", Boolean.FALSE.toString()); + properties.setProperty("readOnly", readOnly); properties.setProperty("rootID", CDOCheckoutImpl.getCDOIDString(repositoryElement.getObjectID())); CDOCheckout checkout = CDOExplorerUtil.getCheckoutManager().addCheckout(properties); checkout.open(); CheckoutWizard.showInProjectExplorer(checkout); + return checkout; + } + + public static CDOCheckout checkout(CDORepository repository, String type) + { + CDORepositoryElement repositoryElement = AdapterUtil.adapt(repository, CDORepositoryElement.class); + return checkout(repositoryElement, type); } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoriesView.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoriesView.java index e7f69cc17d..fb1864d97a 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoriesView.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoriesView.java @@ -12,10 +12,14 @@ package org.eclipse.emf.cdo.explorer.ui.repositories; import org.eclipse.emf.cdo.eresource.CDOResource; 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.repositories.CDORepository.IDGeneration; import org.eclipse.emf.cdo.explorer.repositories.CDORepository.State; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.cdo.explorer.ui.checkouts.actions.ShowInActionProvider; +import org.eclipse.emf.cdo.explorer.ui.handlers.RepositoryCheckoutHandlerQuick; import org.eclipse.emf.cdo.explorer.ui.repositories.wizards.NewRepositoryWizard; import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryImpl; import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryManagerImpl; @@ -130,70 +134,75 @@ public class CDORepositoriesView extends ContainerView { addCollapseAllAction(manager); - manager.add(new Action("Test") + if (Boolean.getBoolean("cdo.explorer.testRepo")) { - @Override - public void run() + manager.add(new Action("Test") { - Properties properties = new Properties(); - properties.setProperty(LocalCDORepository.PROP_TYPE, CDORepository.TYPE_LOCAL); - properties.setProperty(LocalCDORepository.PROP_LABEL, "repo2"); - properties.setProperty(LocalCDORepository.PROP_NAME, "repo2"); - properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, - CDORepository.VersioningMode.Branching.toString()); - properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, CDORepository.IDGeneration.UUID.toString()); - properties.setProperty(LocalCDORepository.PROP_TCP_DISABLED, "false"); - properties.setProperty(LocalCDORepository.PROP_TCP_PORT, "2037"); - - CDORepository repository = CDOExplorerUtil.getRepositoryManager().addRepository(properties); - repository.connect(); - - CDOSession session = repository.getSession(); - CDOTransaction transaction = session.openTransaction(); - CDOUtil.configureView(transaction); - - try + @Override + public void run() { - EPackage ePackage = EPackage.Registry.INSTANCE - .getEPackage("http://www.eclipse.org/emf/CDO/examples/company/1.0.0"); - EClass eClass = (EClass)ePackage.getEClassifier("Company"); - - EObject company = EcoreUtil.create(eClass); - addChild(company, "categories", "Category"); - addChild(company, "suppliers", "Supplier"); - addChild(company, "customers", "Customer"); - addChild(company, "purchaseOrders", "PurchaseOrder"); - addChild(company, "salesOrders", "SalesOrder"); - - CDOResource resource = transaction.createResource("model1"); - resource.getContents().add(company); - - transaction.commit(); - } - catch (ConcurrentAccessException ex) - { - ex.printStackTrace(); - } - catch (CommitException ex) - { - ex.printStackTrace(); + Properties properties = new Properties(); + properties.setProperty(LocalCDORepository.PROP_TYPE, CDORepository.TYPE_LOCAL); + properties.setProperty(LocalCDORepository.PROP_LABEL, "repo2"); + properties.setProperty(LocalCDORepository.PROP_NAME, "repo2"); + properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, VersioningMode.Branching.toString()); + properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, IDGeneration.UUID.toString()); + properties.setProperty(LocalCDORepository.PROP_TCP_DISABLED, "false"); + properties.setProperty(LocalCDORepository.PROP_TCP_PORT, "2037"); + + CDORepository repository = CDOExplorerUtil.getRepositoryManager().addRepository(properties); + repository.connect(); + + CDOSession session = repository.getSession(); + CDOTransaction transaction = session.openTransaction(); + CDOUtil.configureView(transaction); + + try + { + EPackage ePackage = EPackage.Registry.INSTANCE + .getEPackage("http://www.eclipse.org/emf/CDO/examples/company/1.0.0"); + EClass eClass = (EClass)ePackage.getEClassifier("Company"); + + EObject company = EcoreUtil.create(eClass); + addChild(company, "categories", "Category"); + addChild(company, "suppliers", "Supplier"); + addChild(company, "customers", "Customer"); + addChild(company, "purchaseOrders", "PurchaseOrder"); + addChild(company, "salesOrders", "SalesOrder"); + + CDOResource resource = transaction.createResource("model1"); + resource.getContents().add(company); + + transaction.commit(); + + RepositoryCheckoutHandlerQuick.checkout(repository, CDOCheckout.TYPE_ONLINE_HISTORICAL); + + } + catch (ConcurrentAccessException ex) + { + ex.printStackTrace(); + } + catch (CommitException ex) + { + ex.printStackTrace(); + } + finally + { + transaction.close(); + } } - finally - { - transaction.close(); - } - } - private void addChild(EObject company, String featureName, String className) - { - EClass companyClass = company.eClass(); - EObject object = EcoreUtil.create((EClass)companyClass.getEPackage().getEClassifier(className)); + private void addChild(EObject company, String featureName, String className) + { + EClass companyClass = company.eClass(); + EObject object = EcoreUtil.create((EClass)companyClass.getEPackage().getEClassifier(className)); - @SuppressWarnings("unchecked") - EList<EObject> list = (EList<EObject>)company.eGet(companyClass.getEStructuralFeature(featureName)); - list.add(object); - } - }); + @SuppressWarnings("unchecked") + EList<EObject> list = (EList<EObject>)company.eGet(companyClass.getEStructuralFeature(featureName)); + list.add(object); + } + }); + } manager.add(newAction); } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoryItemProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoryItemProvider.java index 92d6ae0d52..11ce70e01b 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoryItemProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/CDORepositoryItemProvider.java @@ -15,6 +15,8 @@ import org.eclipse.emf.cdo.common.util.CDOCommonUtil; import org.eclipse.emf.cdo.common.util.CDOTimeProvider; import org.eclipse.emf.cdo.explorer.CDOExplorerManager; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.explorer.repositories.CDORepositoryManager; import org.eclipse.emf.cdo.explorer.repositories.CDORepositoryManager.RepositoryConnectionEvent; import org.eclipse.emf.cdo.explorer.ui.ViewerUtil; @@ -295,7 +297,8 @@ public class CDORepositoryItemProvider extends ContainerItemProvider<IContainer< if (element instanceof CDORepository) { CDORepository repository = (CDORepository)element; - return repository.getVersioningMode().toString(); + VersioningMode versioningMode = repository.getVersioningMode(); + return versioningMode == null ? "Unknown" : versioningMode.toString(); } break; @@ -304,7 +307,8 @@ public class CDORepositoryItemProvider extends ContainerItemProvider<IContainer< if (element instanceof CDORepository) { CDORepository repository = (CDORepository)element; - return repository.getIDGeneration().toString(); + IDGeneration idGeneration = repository.getIDGeneration(); + return idGeneration == null ? "Unknown" : idGeneration.toString(); } } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/MasterRepositoryController.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/MasterRepositoryController.java index d94fc93c9d..400d1d3bb8 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/MasterRepositoryController.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/MasterRepositoryController.java @@ -14,7 +14,8 @@ import org.eclipse.emf.cdo.admin.CDOAdminClient; import org.eclipse.emf.cdo.admin.CDOAdminClientManager; import org.eclipse.emf.cdo.admin.CDOAdminClientRepository; import org.eclipse.emf.cdo.admin.CDOAdminClientUtil; -import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.explorer.ui.ViewerUtil; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.cdo.net4j.CDONet4jSession; @@ -139,6 +140,10 @@ public class MasterRepositoryController private String password; + private VersioningMode versioningMode; + + private IDGeneration idGeneration; + public MasterRepositoryController(Composite parent) { this.parent = parent; @@ -233,6 +238,16 @@ public class MasterRepositoryController return password; } + public final VersioningMode getVersioningMode() + { + return versioningMode; + } + + public final IDGeneration getIDGeneration() + { + return idGeneration; + } + public final boolean isValid() { return portText.isValid() && repositoryNameText.isValid(); @@ -463,6 +478,8 @@ public class MasterRepositoryController { //$FALL-THROUGH$ } + + validateController(); } }); } @@ -580,6 +597,9 @@ public class MasterRepositoryController CDONet4jSession session = null; authenticating = false; + versioningMode = null; + idGeneration = null; + try { IConnector connector = getConnector(); @@ -629,10 +649,11 @@ public class MasterRepositoryController showCredentials(authenticating); CDORepositoryInfo repositoryInfo = session.getRepositoryInfo(); - String message = getMode(repositoryInfo); + versioningMode = VersioningMode.from(repositoryInfo); + idGeneration = IDGeneration.from(repositoryInfo); - if (repositoryInfo.isSupportingBranches() - && repositoryInfo.getIDGenerationLocation() == IDGenerationLocation.CLIENT) + String message = versioningMode.toString(); + if (versioningMode == VersioningMode.Branching && idGeneration == IDGeneration.UUID) { message += ", Replicable"; } @@ -665,21 +686,6 @@ public class MasterRepositoryController return connector; } - - private String getMode(CDORepositoryInfo repositoryInfo) - { - if (repositoryInfo.isSupportingBranches()) - { - return "Branching"; - } - - if (repositoryInfo.isSupportingAudits()) - { - return "Auditing"; - } - - return "Normal"; - } } /** diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryLocalPage.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryLocalPage.java index 067e3ffbdf..a30bce321b 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryLocalPage.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryLocalPage.java @@ -12,6 +12,8 @@ package org.eclipse.emf.cdo.explorer.ui.repositories.wizards; import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.explorer.repositories.CDORepositoryManager; import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryImpl; import org.eclipse.emf.cdo.internal.explorer.repositories.LocalCDORepository; @@ -159,24 +161,24 @@ public class RepositoryLocalPage extends AbstractRepositoryPage if (normalButton.getSelection()) { - properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, CDORepository.VersioningMode.Normal.toString()); + properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, VersioningMode.Normal.toString()); } else if (auditingButton.getSelection()) { - properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, CDORepository.VersioningMode.Auditing.toString()); + properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, VersioningMode.Auditing.toString()); } else if (branchingButton.getSelection()) { - properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, CDORepository.VersioningMode.Branching.toString()); + properties.setProperty(CDORepositoryImpl.PROP_VERSIONING_MODE, VersioningMode.Branching.toString()); } if (counterButton.getSelection()) { - properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, CDORepository.IDGeneration.Counter.toString()); + properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, IDGeneration.Counter.toString()); } else if (uuidButton.getSelection()) { - properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, CDORepository.IDGeneration.UUID.toString()); + properties.setProperty(CDORepositoryImpl.PROP_ID_GENERATION, IDGeneration.UUID.toString()); } boolean tcpPortDisabled = portText.isDisabled(); diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryRemotePage.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryRemotePage.java index 5f0dd84c8c..c2854e9b6a 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryRemotePage.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/repositories/wizards/RepositoryRemotePage.java @@ -10,6 +10,8 @@ */ package org.eclipse.emf.cdo.explorer.ui.repositories.wizards; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.IDGeneration; +import org.eclipse.emf.cdo.explorer.repositories.CDORepository.VersioningMode; import org.eclipse.emf.cdo.internal.explorer.repositories.RemoteCDORepository; import org.eclipse.net4j.util.StringUtil; @@ -67,5 +69,17 @@ public class RepositoryRemotePage extends AbstractRepositoryPage properties.setProperty(RemoteCDORepository.PROP_CONNECTOR_TYPE, "tcp"); properties.setProperty(RemoteCDORepository.PROP_CONNECTOR_DESCRIPTION, connectorDescription); properties.setProperty(RemoteCDORepository.PROP_NAME, repositoryName); + + VersioningMode versioningMode = controller.getVersioningMode(); + if (versioningMode != null) + { + properties.setProperty(RemoteCDORepository.PROP_VERSIONING_MODE, versioningMode.toString()); + } + + IDGeneration idGeneration = controller.getIDGeneration(); + if (idGeneration != null) + { + properties.setProperty(RemoteCDORepository.PROP_ID_GENERATION, idGeneration.toString()); + } } } diff --git a/plugins/org.eclipse.emf.cdo.explorer/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer/plugin.xml index 5f00f5691a..d0876257ef 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.explorer/plugin.xml @@ -42,4 +42,18 @@ class="org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutProperties$Tester"/> </extension> + <extension point="org.eclipse.emf.cdo.viewProviders"> + <viewProvider + class="org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutViewProvider" + priority="500" + regex="cdo\.checkout://.*"/> + </extension> + + <extension + point="org.eclipse.emf.ecore.protocol_parser"> + <parser + class="org.eclipse.emf.cdo.eresource.impl.CDOResourceFactoryImpl" + protocolName="cdo.checkout"/> + </extension> + </plugin> 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 0dd267d342..2768da2f61 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 @@ -15,10 +15,14 @@ import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckoutManager; import org.eclipse.emf.cdo.explorer.repositories.CDORepositoryManager; import org.eclipse.emf.cdo.internal.explorer.bundle.OM; +import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutImpl; +import org.eclipse.emf.cdo.internal.explorer.checkouts.CDOCheckoutViewProvider; +import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.AdapterUtil; import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -42,6 +46,18 @@ public final class CDOExplorerUtil public static CDOCheckout getCheckout(Object object) { + if (object instanceof CDOView) + { + CDOView view = (CDOView)object; + return (CDOCheckout)view.properties().get(CDOCheckoutImpl.CHECKOUT_KEY); + } + + if (object instanceof URI) + { + URI uri = (URI)object; + return CDOCheckoutViewProvider.getCheckout(uri); + } + return walkUp(object, null); } 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 8ca4983bdd..39f77945b2 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 @@ -24,6 +24,7 @@ import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.AdapterUtil; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; @@ -105,11 +106,13 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider, StateP public CDOTransaction openTransaction(ResourceSet resourceSet); + public URI createResourceURI(String path); + public boolean isDirty(); - public String getEditorID(CDOID objectID); + public String getEditorOpenerID(CDOID objectID); - public void setEditorID(CDOID objectID, String editorID); + public void setEditorOpenerID(CDOID objectID, String editorOpenerID); /** * @author Eike Stepper 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 cf5a6cb53e..4582e6bc3b 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.CDOCommonRepository.IDGenerationLocation; import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.explorer.CDOExplorerElement; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; +import org.eclipse.emf.cdo.session.CDORepositoryInfo; import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.session.CDOSessionProvider; import org.eclipse.emf.cdo.transaction.CDOTransactionOpener; @@ -102,6 +103,21 @@ CDOSessionProvider, CDOViewOpener, CDOTransactionOpener { return supportingBranches; } + + public static VersioningMode from(CDORepositoryInfo repositoryInfo) + { + if (repositoryInfo.isSupportingBranches()) + { + return VersioningMode.Branching; + } + + if (repositoryInfo.isSupportingAudits()) + { + return VersioningMode.Auditing; + } + + return VersioningMode.Normal; + } } /** @@ -118,10 +134,20 @@ CDOSessionProvider, CDOViewOpener, CDOTransactionOpener this.location = location; } - public final IDGenerationLocation getLocation() + public IDGenerationLocation getLocation() { return location; } + + public static IDGeneration from(CDORepositoryInfo repositoryInfo) + { + if (repositoryInfo.getIDGenerationLocation() == IDGenerationLocation.CLIENT) + { + return IDGeneration.UUID; + } + + return IDGeneration.Counter; + } } /** diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryElement.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryElement.java index 8855082ccf..a1ad6d4a7f 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryElement.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepositoryElement.java @@ -25,7 +25,5 @@ public interface CDORepositoryElement extends CDOTimeProvider public int getBranchID(); - public long getTimeStamp(); - public CDOID getObjectID(); } 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 9c99aa6f7d..e282eeb6e4 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 @@ -31,6 +31,7 @@ import org.eclipse.emf.cdo.view.CDOViewLocksChangedEvent; import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent; import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.container.IManagedContainer; import org.eclipse.net4j.util.container.IPluginContainer; import org.eclipse.net4j.util.event.IEvent; @@ -40,6 +41,7 @@ import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; import org.eclipse.net4j.util.lifecycle.ILifecycleEvent.Kind; import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; @@ -75,7 +77,7 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec public static final String EDITOR_PROPERTIES = "editor.properties"; - private static final String CHECKOUT_KEY = CDOCheckout.class.getName(); + public static final String CHECKOUT_KEY = CDOCheckout.class.getName(); private static final CDOBranchPoint[] NO_BRANCH_POINTS = {}; @@ -624,11 +626,29 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec } }); + URI from = URI.createURI("cdo://" + view.getSession().getRepositoryInfo().getName() + "/"); + URI to = URI.createURI("cdo.checkout://" + getID() + "/" + repository.getID() + "/"); + view.getResourceSet().getURIConverter().getURIMap().put(from, to); + addView(view); return view; } - public String getEditorID(CDOID objectID) + public URI createResourceURI(String path) + { + if (StringUtil.isEmpty(path)) + { + path = ""; + } + else if (!path.startsWith("/")) + { + path = "/" + path; + } + + return URI.createURI(CDOCheckoutViewProvider.SCHEME + "://" + getID() + "/" + getRepository().getID() + path); + } + + public String getEditorOpenerID(CDOID objectID) { synchronized (editorIDs) { @@ -649,7 +669,7 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec } } - public void setEditorID(CDOID objectID, String editorID) + public void setEditorOpenerID(CDOID objectID, String editorID) { synchronized (editorIDs) { diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutViewProvider.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutViewProvider.java new file mode 100644 index 0000000000..54371a1bf3 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutViewProvider.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2011-2013 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.internal.explorer.checkouts; + +import org.eclipse.emf.cdo.explorer.CDOExplorerUtil; +import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; +import org.eclipse.emf.cdo.view.AbstractCDOViewProvider; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.net4j.util.ref.ReferenceMonitor; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; + +import org.eclipse.core.runtime.Path; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Eike Stepper + */ +public class CDOCheckoutViewProvider extends AbstractCDOViewProvider +{ + public static final String SCHEME = "cdo.checkout"; + + // TODO Move to activator and deactivate via stop(). + private static final ReferenceMonitor<ResourceSet> MONITOR = new ReferenceMonitor<ResourceSet>() + { + @Override + protected void work(ResourceSet resourceSet) + { + disposeResourceSet(resourceSet); + } + }; + + public CDOCheckoutViewProvider() + { + this(DEFAULT_PRIORITY); + } + + public CDOCheckoutViewProvider(int priority) + { + super("cdo\\.checkout://.*", priority); + } + + public CDOView getView(URI uri, ResourceSet resourceSet) + { + CDOCheckout checkout = getCheckout(uri); + if (checkout != null) + { + CheckoutViewProviderAdapter adapter = CheckoutViewProviderAdapter.get(resourceSet); + if (adapter == null) + { + adapter = CheckoutViewProviderAdapter.create(resourceSet); + + MONITOR.activate(); + MONITOR.monitor(resourceSet); + } + + return adapter.getView(checkout); + } + + return null; + } + + @Override + public URI getResourceURI(CDOView view, String path) + { + CDOCheckout checkout = CDOExplorerUtil.getCheckout(view); + if (checkout != null) + { + return checkout.createResourceURI(path); + } + + return super.getResourceURI(view, path); + } + + @Override + public String getPath(URI uri) + { + return new Path(uri.path()).makeAbsolute().removeFirstSegments(1).toString(); + } + + public static void disposeResourceSet(ResourceSet resourceSet) + { + CheckoutViewProviderAdapter adapter = CheckoutViewProviderAdapter.get(resourceSet); + if (adapter != null) + { + adapter.dispose(); + } + } + + public static CDOCheckout getCheckout(URI uri) + { + if (SCHEME.equals(uri.scheme())) + { + String checkoutID = uri.authority(); + return CDOExplorerUtil.getCheckoutManager().getCheckout(checkoutID); + } + + return null; + } + + /** + * @author Eike Stepper + */ + private static final class CheckoutViewProviderAdapter extends AdapterImpl + { + private final Map<CDOCheckout, CDOView> views = new HashMap<CDOCheckout, CDOView>(); + + private CheckoutViewProviderAdapter() + { + } + + public CDOView getView(final CDOCheckout checkout) + { + synchronized (views) + { + CDOView view = views.get(checkout); + if (view == null) + { + ResourceSet resourceSet = getTarget(); + view = checkout.openView(resourceSet); + + if (view != null) + { + views.put(checkout, view); + + view.addListener(new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + synchronized (views) + { + views.remove(checkout); + } + } + }); + } + } + + return view; + } + } + + @Override + public boolean isAdapterForType(Object type) + { + return type == CheckoutViewProviderAdapter.class; + } + + @Override + public ResourceSet getTarget() + { + return (ResourceSet)super.getTarget(); + } + + public void dispose() + { + CDOView[] array; + synchronized (views) + { + array = views.values().toArray(new CDOView[views.size()]); + views.clear(); + } + + for (CDOView view : array) + { + view.close(); + } + + ResourceSet resourceSet = getTarget(); + resourceSet.eAdapters().remove(this); + } + + public static CheckoutViewProviderAdapter get(ResourceSet resourceSet) + { + EList<Adapter> adapters = resourceSet.eAdapters(); + + CheckoutViewProviderAdapter adapter = (CheckoutViewProviderAdapter)EcoreUtil.getAdapter(adapters, + CheckoutViewProviderAdapter.class); + if (adapter != null && adapter.getTarget() != resourceSet) + { + adapters.remove(adapter); + adapter = null; + } + + return adapter; + } + + public static CheckoutViewProviderAdapter create(ResourceSet resourceSet) + { + CheckoutViewProviderAdapter adapter = get(resourceSet); + if (adapter == null) + { + adapter = new CheckoutViewProviderAdapter(); + resourceSet.eAdapters().add(adapter); + } + + return adapter; + } + } +} 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 1bfa484e57..e30e5b6871 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 @@ -18,6 +18,10 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchCreationContext; import org.eclipse.emf.cdo.common.branch.CDOBranchManager; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.id.CDOIDGenerator; +import org.eclipse.emf.cdo.common.id.CDOIDUtil; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; import org.eclipse.emf.cdo.explorer.CDOExplorerManager.ElementsChangedEvent; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.repositories.CDORepository; @@ -29,10 +33,12 @@ import org.eclipse.emf.cdo.net4j.CDONet4jUtil; import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.session.CDOSessionConfiguration; import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.Net4jUtil; import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.UUIDGenerator; import org.eclipse.net4j.util.container.ContainerEvent; import org.eclipse.net4j.util.container.IContainerEvent; import org.eclipse.net4j.util.container.IManagedContainer; @@ -43,13 +49,18 @@ import org.eclipse.net4j.util.lifecycle.ILifecycle; import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; import org.eclipse.net4j.util.security.IPasswordCredentials; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import java.io.File; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; /** * @author Eike Stepper @@ -110,9 +121,9 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe private String name; - private CDORepository.VersioningMode versioningMode; + private VersioningMode versioningMode; - private CDORepository.IDGeneration idGeneration; + private IDGeneration idGeneration; private String realm; @@ -148,12 +159,12 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe return name; } - public final CDORepository.VersioningMode getVersioningMode() + public final VersioningMode getVersioningMode() { return versioningMode; } - public final CDORepository.IDGeneration getIDGeneration() + public final IDGeneration getIDGeneration() { return idGeneration; } @@ -505,8 +516,13 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe { super.init(folder, type, properties); name = properties.getProperty(PROP_NAME); - versioningMode = VersioningMode.valueOf(properties.getProperty(PROP_VERSIONING_MODE)); - idGeneration = IDGeneration.valueOf(properties.getProperty(PROP_ID_GENERATION)); + + String versioningModeProperty = properties.getProperty(PROP_VERSIONING_MODE); + versioningMode = versioningModeProperty == null ? null : VersioningMode.valueOf(versioningModeProperty); + + String idGenerationProperty = properties.getProperty(PROP_ID_GENERATION); + idGeneration = idGenerationProperty == null ? null : IDGeneration.valueOf(idGenerationProperty); + realm = properties.getProperty(PROP_REALM); } @@ -515,8 +531,16 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe { super.collectProperties(properties); properties.setProperty(PROP_NAME, name); - properties.setProperty(PROP_VERSIONING_MODE, versioningMode.toString()); - properties.setProperty(PROP_ID_GENERATION, idGeneration.toString()); + + if (versioningMode != null) + { + properties.setProperty(PROP_VERSIONING_MODE, versioningMode.toString()); + } + + if (idGeneration != null) + { + properties.setProperty(PROP_ID_GENERATION, idGeneration.toString()); + } if (realm != null) { @@ -537,6 +561,97 @@ public abstract class CDORepositoryImpl extends AbstractElement implements CDORe CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration(); config.setConnector(connector); config.setRepositoryName(name); + + if (Boolean.getBoolean("cdo.explorer.readableIDs")) + { + config.setIDGenerator(new CDOIDGenerator() + { + private final UUIDGenerator decoder = new UUIDGenerator(); + + private Map<EClass, AtomicInteger> counters; + + private int typeCounter; + + public CDOID generateCDOID(EObject object) + { + if (counters == null) + { + counters = new HashMap<EClass, AtomicInteger>(); + CDOView view = CDOUtil.getView(object); + view.getSession().getRevisionManager().handleRevisions(null, null, false, CDOBranchPoint.UNSPECIFIED_DATE, + false, new CDORevisionHandler() + { + public boolean handleRevision(CDORevision revision) + { + EClass eClass = revision.getEClass(); + AtomicInteger counter = getCounter(eClass); + + String id = revision.getID().toString(); + id = id.substring(0, id.length() - "A".length()); + id = id.substring(id.lastIndexOf('_') + 1); + + int counterValue = Integer.parseInt(id); + if (counterValue > counter.get()) + { + counter.set(counterValue); + } + + return true; + } + }); + } + + EClass eClass = object.eClass(); + + String type = eClass.getName(); + if (type.length() > 16) + { + String suffix = "_" + (++typeCounter); + type = type.substring(0, 16 - suffix.length()) + suffix; + System.out.println(eClass.getName() + " --> " + type); + } + + type = "_" + type; + + AtomicInteger counter = getCounter(eClass); + + String str = "_" + counter.incrementAndGet(); + String id = type + "____________________________________".substring(0, 22 - type.length() - str.length()) + + str + "A"; + + if ("_CDOResource_________5A".equals(id)) + { + System.out.println(); + } + + byte[] value = decoder.decode(id); + + String encoded = decoder.encode(value); + if (!encoded.equals(id)) + { + throw new IllegalStateException(); + } + + return CDOIDUtil.createUUID(value); + } + + private AtomicInteger getCounter(EClass eClass) + { + AtomicInteger counter = counters.get(eClass); + if (counter == null) + { + counter = new AtomicInteger(); + counters.put(eClass, counter); + } + return counter; + } + + public void reset() + { + } + }); + } + return config; } diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jViewProvider.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jViewProvider.java index c1757a08c0..7630bb4bfa 100644 --- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jViewProvider.java +++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jViewProvider.java @@ -28,6 +28,8 @@ import org.eclipse.net4j.util.security.PasswordCredentialsProvider; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.core.runtime.Path; + import java.text.SimpleDateFormat; import java.util.Date; @@ -79,6 +81,12 @@ public abstract class CDONet4jViewProvider extends AbstractCDOViewProvider } @Override + public String getPath(URI uri) + { + return new Path(uri.path()).makeAbsolute().removeFirstSegments(1).toString(); + } + + @Override public URI getResourceURI(CDOView view, String path) { StringBuilder builder = new StringBuilder(); diff --git a/plugins/org.eclipse.emf.cdo.server.product/.classpath b/plugins/org.eclipse.emf.cdo.server.product/.classpath index bc1d55c305..c83506765b 100644 --- a/plugins/org.eclipse.emf.cdo.server.product/.classpath +++ b/plugins/org.eclipse.emf.cdo.server.product/.classpath @@ -2,4 +2,5 @@ <classpath> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> </classpath> diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_477777_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_477777_Test.java deleted file mode 100644 index 4f5aee9253..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_477777_Test.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2015 Obeo 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: - * Esteban Dugueperoux - initial API and implementation - */ -package org.eclipse.emf.cdo.tests.bugzilla; - -import org.eclipse.emf.cdo.eresource.CDOResource; -import org.eclipse.emf.cdo.session.CDOSession; -import org.eclipse.emf.cdo.tests.AbstractCDOTest; -import org.eclipse.emf.cdo.tests.model1.Company; -import org.eclipse.emf.cdo.transaction.CDOTransaction; -import org.eclipse.emf.cdo.util.CDOUtil; -import org.eclipse.emf.cdo.view.CDOViewSet; - -/** - * Bug 465115 about StackOverflowError on CDOUtil.getViewSet() call with a CDOResource. - * - * @author Esteban Dugueperoux - */ -public class Bugzilla_477777_Test extends AbstractCDOTest -{ - private static final String RESOURCE_NAME = "test1.model1"; - - /** - * Test {@link CDOUtil#getViewSet(org.eclipse.emf.common.notify.Notifier)} on a {@link CDOResource}. - */ - public void testCDOUtilGetViewSet() throws Exception - { - CDOSession session1 = openSession(); - CDOTransaction transaction1 = session1.openTransaction(); - CDOResource resource1 = transaction1.createResource(getResourcePath(RESOURCE_NAME)); - Company company = getModel1Factory().createCompany(); - resource1.getContents().add(company); - transaction1.commit(); - - CDOViewSet viewSet = CDOUtil.getViewSet(resource1); - assertNotNull(viewSet); - assertEquals(1, viewSet.getViews().length); - assertEquals(transaction1, viewSet.getViews()[0]); - } -} diff --git a/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_remote_sessions.gif b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_remote_sessions.gif Binary files differnew file mode 100644 index 0000000000..5d36d23559 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_remote_sessions.gif diff --git a/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_time_machine.gif b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_time_machine.gif Binary files differnew file mode 100644 index 0000000000..3f4f876217 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_time_machine.gif diff --git a/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif Binary files differindex f5cd082e28..29add220f9 100644 --- a/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif +++ b/plugins/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.properties b/plugins/org.eclipse.emf.cdo.ui/plugin.properties index c59f3650dc..fff9e26267 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.properties +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.properties @@ -62,6 +62,7 @@ category.name.0 = CDO view.name.0 = CDO Sessions view.name.1 = CDO Watch List view.name.2 = CDO Collaboration +view.name.3 = CDO Time Machine editor.name.0 = CDO Editor page.name.0 = CDO page.name.1 = User Interface diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml index ce96905f34..8aaf9da46b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml @@ -58,10 +58,17 @@ <view category="org.eclipse.emf.cdo" class="org.eclipse.emf.cdo.internal.ui.views.CDORemoteSessionsView" - icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/watch_list.gif" + icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_remote_sessions.gif" id="org.eclipse.emf.cdo.ui.CDORemoteSessionsView" name="%view.name.2"> </view> + <view + category="org.eclipse.emf.cdo" + class="org.eclipse.emf.cdo.internal.ui.views.CDOTimeMachineView" + icon="platform:/plugin/org.eclipse.emf.cdo.ui.shared/icons/full/view16/cdo_time_machine.gif" + id="org.eclipse.emf.cdo.ui.CDOTimeMachineView" + name="%view.name.3"> + </view> </extension> <extension 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 aee38dbee4..5c4221dbdb 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 @@ -14,7 +14,6 @@ package org.eclipse.emf.cdo.internal.ui.editor; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; -import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.model.CDOPackageInfo; import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; import org.eclipse.emf.cdo.common.model.CDOPackageUnit; @@ -30,20 +29,18 @@ import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.ui.CDOEditorInput; import org.eclipse.emf.cdo.ui.CDOEventHandler; import org.eclipse.emf.cdo.ui.CDOLabelProvider; +import org.eclipse.emf.cdo.ui.CDOInvalidRootAgent; import org.eclipse.emf.cdo.ui.shared.SharedIcons; import org.eclipse.emf.cdo.ui.widgets.TimeSlider; import org.eclipse.emf.cdo.util.CDOURIUtil; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.util.ValidationException; import org.eclipse.emf.cdo.view.CDOView; -import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent; import org.eclipse.emf.internal.cdo.view.CDOStateMachine; import org.eclipse.net4j.util.AdapterUtil; import org.eclipse.net4j.util.ReflectUtil; -import org.eclipse.net4j.util.event.IEvent; -import org.eclipse.net4j.util.event.IListener; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.net4j.util.ui.actions.LongRunningAction; import org.eclipse.net4j.util.ui.actions.SafeAction; @@ -212,17 +209,17 @@ public class CDOEditor extends MultiPageEditorPart /** * @ADDED */ - protected static final Object EMPTY_INPUT = new Object(); + protected CDOView view; /** * @ADDED */ - protected CDOView view; + protected Object viewerInput; /** * @ADDED */ - protected Object viewerInput; + protected CDOInvalidRootAgent invalidRootAgent; /** * @ADDED @@ -472,59 +469,6 @@ public class CDOEditor extends MultiPageEditorPart } }; - protected IListener viewTargetListener = new IListener() - { - protected CDOID inputID; - - public void notifyEvent(IEvent event) - { - if (event instanceof CDOViewTargetChangedEvent) - { - final CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event; - getSite().getShell().getDisplay().asyncExec(new Runnable() - { - public void run() - { - Object input = selectionViewer.getInput(); - if (input == EMPTY_INPUT) - { - if (inputID != null) - { - try - { - CDOObject object = view.getObject(inputID); - selectionViewer.setInput(object); - inputID = null; - } - catch (Exception ex) - { - // Ignore - } - } - } - else if (input instanceof EObject) - { - CDOObject object = CDOUtil.getCDOObject((EObject)input); - if (object.cdoInvalid()) - { - if (e.getBranchPoint().getTimeStamp() == e.getOldBranchPoint().getTimeStamp()) - { - inputID = null; - closeEditor(); - } - else - { - inputID = object.cdoID(); - selectionViewer.setInput(EMPTY_INPUT); - } - } - } - } - }); - } - } - }; - /** * Handles activation of the editor or it's associated views. * <!-- begin-user-doc --> <!-- end-user-doc --> @@ -999,7 +943,31 @@ public class CDOEditor extends MultiPageEditorPart { CDOEditorInput editorInput = (CDOEditorInput)getEditorInput(); view = editorInput.getView(); - view.addListener(viewTargetListener); + + // If the view can be switched to historical times let an InvalidRootAgent handle detached inputs. + if (view.isReadOnly()) + { + invalidRootAgent = new CDOInvalidRootAgent(view) + { + @Override + protected Object getRootFromUI() + { + return selectionViewer.getInput(); + } + + @Override + protected void setRootToUI(Object root) + { + selectionViewer.setInput(root); + } + + @Override + protected void closeUI() + { + closeEditor(); + } + }; + } CommandStack commandStack; @@ -1213,7 +1181,7 @@ public class CDOEditor extends MultiPageEditorPart final boolean timeSliderAllowed = view.isReadOnly() && view.getSession().getRepositoryInfo().isSupportingAudits(); if (timeSliderAllowed) { - IAction toolbarToggleAction = new Action() + final IAction toolbarToggleAction = new Action() { private Group group; @@ -1254,11 +1222,59 @@ public class CDOEditor extends MultiPageEditorPart } }; + final String id = "time-slider-" + System.currentTimeMillis(); + toolbarToggleAction.setId(id); toolbarToggleAction.setEnabled(true); toolbarToggleAction.setChecked(false); toolbarToggleAction.setImageDescriptor(SharedIcons.getDescriptor(SharedIcons.ETOOL_SLIDER)); toolbarToggleAction.setToolTipText(Messages.getString("CDOEditor.1")); //$NON-NLS-1$ - getActionBars().getToolBarManager().add(toolbarToggleAction); + + getSite().getPage().addPartListener(new IPartListener() + { + private IToolBarManager toolBarManager = getActionBars().getToolBarManager(); + + public void partActivated(IWorkbenchPart part) + { + showToggleAction(part, true); + } + + public void partDeactivated(IWorkbenchPart part) + { + showToggleAction(part, false); + } + + private void showToggleAction(IWorkbenchPart part, boolean show) + { + if (part == CDOEditor.this) + { + if (show) + { + toolBarManager.add(toolbarToggleAction); + } + else + { + toolBarManager.remove(id); + } + + toolBarManager.update(true); + } + } + + public void partClosed(IWorkbenchPart part) + { + // Do nothing. + } + + public void partOpened(IWorkbenchPart part) + { + // Do nothing. + } + + public void partBroughtToTop(IWorkbenchPart part) + { + // Do nothing. + } + }); } selectionViewer = new TreeViewer(tree) @@ -2290,7 +2306,7 @@ public class CDOEditor extends MultiPageEditorPart public void dispose() { updateProblemIndication = false; - view.removeListener(viewTargetListener); + invalidRootAgent.dispose(); if (!view.isClosed()) { diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java new file mode 100644 index 0000000000..d0bdd867f6 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOTimeMachineView.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.ui.views; + +import org.eclipse.emf.cdo.CDOElement; +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.ui.widgets.TimeSlider; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.AdapterUtil; + +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; + +import java.util.Iterator; + +/** + * @author Eike Stepper + */ +public class CDOTimeMachineView extends ViewPart implements ISelectionListener +{ + public final static String ID = "org.eclipse.emf.cdo.ui.CDOTimeMachineView"; //$NON-NLS-1$ + + private TimeSlider timeSlider; + + public CDOTimeMachineView() + { + } + + @Override + public void createPartControl(Composite parent) + { + timeSlider = new TimeSlider(parent, SWT.NONE); + + IWorkbenchPage page = getSite().getPage(); + selectionChanged(null, page.getSelection()); + page.addSelectionListener(this); + } + + @Override + public void dispose() + { + getSite().getPage().removeSelectionListener(this); + timeSlider.disconnect(); + super.dispose(); + } + + @Override + public void setFocus() + { + timeSlider.setFocus(); + } + + public void selectionChanged(IWorkbenchPart part, ISelection selection) + { + CDOView view = getView(selection); + if (view != null) + { + timeSlider.connect(view, null); + } + } + + private CDOView getView(ISelection selection) + { + if (selection instanceof IStructuredSelection) + { + IStructuredSelection ssel = (IStructuredSelection)selection; + for (Iterator<?> it = ssel.iterator(); it.hasNext();) + { + Object element = it.next(); + if (element instanceof CDOElement) + { + element = ((CDOElement)element).getDelegate(); + } + + if (element instanceof EObject) + { + EObject eObject = (EObject)element; + CDOObject cdoObject = CDOUtil.getCDOObject(eObject); + if (cdoObject != null) + { + CDOView view = cdoObject.cdoView(); + if (view != null && view.isReadOnly()) + { + return view; + } + } + } + else + { + CDOView view = AdapterUtil.adapt(element, CDOView.class); + if (view != null && view.isReadOnly()) + { + return view; + } + } + } + } + + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java new file mode 100644 index 0000000000..eea70e6990 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOInvalidRootAgent.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.ui; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent; + +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.ui.UIUtil; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.spi.cdo.InternalCDOObject; + +/** + * @author Eike Stepper + * @since 4.4 + */ +public abstract class CDOInvalidRootAgent implements IListener +{ + private static final Object EMPTY_INPUT = new Object(); + + private final CDOView view; + + private CDOID inputID; + + public CDOInvalidRootAgent(CDOView view) + { + this.view = view; + view.addListener(this); + } + + public void notifyEvent(IEvent event) + { + if (event instanceof CDOViewTargetChangedEvent) + { + final CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event; + UIUtil.getDisplay().asyncExec(new Runnable() + { + public void run() + { + Object input = getRootFromUI(); + if (inputID != null) + { + try + { + InternalCDOObject object = (InternalCDOObject)view.getObject(inputID); + if (!object.cdoInvalid()) + { + setRootToUI(object.cdoInternalInstance()); + inputID = null; + } + } + catch (Exception ex) + { + // Ignore + } + } + else if (input instanceof EObject) + { + CDOObject object = CDOUtil.getCDOObject((EObject)input); + if (object.cdoInvalid()) + { + if (e.getBranchPoint().getTimeStamp() == e.getOldBranchPoint().getTimeStamp()) + { + inputID = null; + closeUI(); + } + else + { + inputID = object.cdoID(); + Object emptyRoot = createEmptyRoot(object); + setRootToUI(emptyRoot); + } + } + } + } + }); + } + } + + public void dispose() + { + view.removeListener(this); + } + + protected Object createEmptyRoot(CDOObject invalidRoot) + { + return EMPTY_INPUT; + } + + protected abstract Object getRootFromUI(); + + protected abstract void setRootToUI(Object root); + + protected void closeUI() + { + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java index 966a761dbc..f8d09046c2 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/ComposeBranchPointComposite.java @@ -254,7 +254,8 @@ public class ComposeBranchPointComposite extends Composite timeStampGroup.setLayout(new GridLayout(1, false)); timeStampGroup.setText("Time Stamp:"); - SelectTimeStampComposite timeStampComposite = new SelectTimeStampComposite(timeStampGroup, SWT.NONE) + SelectTimeStampComposite timeStampComposite = new SelectTimeStampComposite(timeStampGroup, SWT.NONE, + branchPoint.getBranch(), branchPoint.getTimeStamp()) { @Override protected void timeStampChanged(long timeStamp) diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java index d210d8d21a..11208b4f9d 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/SelectTimeStampComposite.java @@ -52,7 +52,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar private CDOBranch branch; - private long timeStamp = CDOBranchPoint.INVALID_DATE; + private long timeStamp; private Composite pointGroup; @@ -73,7 +73,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar */ public SelectTimeStampComposite(Composite parent, int style) { - this(parent, style, null, CDOBranchPoint.UNSPECIFIED_DATE); + this(parent, style, null, CDOBranchPoint.INVALID_DATE); } public SelectTimeStampComposite(Composite parent, int style, CDOBranch branch, long timeStamp) @@ -123,7 +123,7 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar timeText = new Text(pointGroup, SWT.BORDER); timeText.setLayoutData(createTimeGridData()); - timeText.setText(CDOCommonUtil.formatTimeStamp()); + timeText.setText(CDOCommonUtil.formatTimeStamp(timeStamp)); timeText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) @@ -174,8 +174,9 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar new Label(pointGroup, SWT.NONE); new Label(pointGroup, SWT.NONE); + this.timeStamp = timeStamp; setBranch(branch); - setTimeStamp(timeStamp); + // setTimeStamp(timeStamp); } public ValidationContext getValidationContext() @@ -222,13 +223,13 @@ public class SelectTimeStampComposite extends Composite implements ValidationPar else { selectRadio(timeRadio); - String text = CDOCommonUtil - .formatTimeStamp(timeStamp == CDOBranchPoint.INVALID_DATE || timeStamp == CDOBranchPoint.UNSPECIFIED_DATE - ? System.currentTimeMillis() : timeStamp); - if (!timeText.getText().equals(text)) - { - timeText.setText(text); - } + // String text = CDOCommonUtil + // .formatTimeStamp(timeStamp == CDOBranchPoint.INVALID_DATE || timeStamp == CDOBranchPoint.UNSPECIFIED_DATE + // ? System.currentTimeMillis() : timeStamp); + // if (!timeText.getText().equals(text)) + // { + // timeText.setText(text); + // } } if (oldTimeStamp != timeStamp) diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java index 203b2fc926..615cb9852a 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/widgets/TimeSlider.java @@ -11,10 +11,12 @@ package org.eclipse.emf.cdo.ui.widgets; import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.branch.CDOBranchPointRange; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.spi.common.branch.CDOBranchUtil; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.view.CDOStaleReferencePolicy; import org.eclipse.emf.cdo.view.CDOView; @@ -22,6 +24,8 @@ import org.eclipse.emf.cdo.view.CDOViewTargetChangedEvent; import org.eclipse.net4j.util.event.IEvent; import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycleEvent; +import org.eclipse.net4j.util.lifecycle.ILifecycleEvent.Kind; import org.eclipse.emf.ecore.EObject; @@ -31,6 +35,7 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Scale; import java.util.HashSet; @@ -83,8 +88,11 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener long timeStamp = startTimeStamp + Math.round(stepSize * value); setTimeStamp(timeStamp); - viewer.refresh(); - setExpandedStates(); + if (viewer != null) + { + viewer.refresh(); + setExpandedStates(); + } } protected void setExpandedStates() @@ -128,10 +136,28 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener if (this.timeStamp != timeStamp) { this.timeStamp = timeStamp; - int newSelection = (int)((timeStamp - startTimeStamp) / stepSize); - if (getSelection() != newSelection) + final int newSelection = (int)((timeStamp - startTimeStamp) / stepSize); + + Display display = getDisplay(); + if (display == Display.getCurrent()) + { + if (getSelection() != newSelection) + { + setSelection(newSelection); + } + } + else { - setSelection(newSelection); + display.asyncExec(new Runnable() + { + public void run() + { + if (getSelection() != newSelection) + { + setSelection(newSelection); + } + } + }); } timeStampChanged(timeStamp); @@ -140,54 +166,89 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener public void connect(CDOView view, TreeViewer viewer) { - disconnect(); - - this.view = view; - this.viewer = viewer; - - for (Object element : viewer.getExpandedElements()) + if (this.view != view) { - CDOID id = getID(element); - if (id != null) + disconnect(); + + if (view != null) { - expandedIDs.add(id); - } - } + this.view = view; + this.viewer = viewer; - viewer.addTreeListener(this); + CDOBranchPointRange lifetime = null; - CDOObject input = CDOUtil.getCDOObject((EObject)viewer.getInput()); - CDOBranchPointRange lifetime = CDOUtil.getLifetime(input); + if (this.viewer != null) + { + for (Object element : viewer.getExpandedElements()) + { + CDOID id = getID(element); + if (id != null) + { + expandedIDs.add(id); + } + } - startTimeStamp = lifetime.getStartPoint().getTimeStamp(); - endTimeStamp = lifetime.getEndPoint().getTimeStamp(); - if (endTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE) - { - CDOSession session = view.getSession(); - endTimeStamp = session.getLastUpdateTime(); - } + this.viewer.addTreeListener(this); + + Object input = viewer.getInput(); + if (input instanceof EObject) + { + lifetime = CDOUtil.getLifetime(CDOUtil.getCDOObject((EObject)input)); + } + } + + if (lifetime == null) + { + CDOSession session = view.getSession(); + CDOBranch branch = view.getBranch(); + + CDOBranchPoint firstPoint = branch.getPoint(session.getRepositoryInfo().getCreationTime()); + CDOBranchPoint lastPoint = branch.getHead(); + lifetime = CDOBranchUtil.createRange(firstPoint, lastPoint); + } - absoluteTimeWindowLength = endTimeStamp - startTimeStamp; - stepSize = absoluteTimeWindowLength / FACTOR; + startTimeStamp = lifetime.getStartPoint().getTimeStamp(); + endTimeStamp = lifetime.getEndPoint().getTimeStamp(); + if (endTimeStamp == CDOBranchPoint.UNSPECIFIED_DATE) + { + CDOSession session = view.getSession(); + endTimeStamp = session.getLastUpdateTime(); + } + + absoluteTimeWindowLength = endTimeStamp - startTimeStamp; + stepSize = absoluteTimeWindowLength / FACTOR; - setTimeStamp(view.getTimeStamp()); + setTimeStamp(view.getTimeStamp()); - staleReferencePolicy = new CDOStaleReferencePolicy.DynamicProxy.Enhanced(view); - view.addListener(this); + staleReferencePolicy = new CDOStaleReferencePolicy.DynamicProxy.Enhanced(view); + view.addListener(this); + setEnabled(true); + } + else + { + setEnabled(false); + } + } } public void disconnect() { - if (staleReferencePolicy != null) + if (view != null) { - view.removeListener(this); - staleReferencePolicy.dispose(); - staleReferencePolicy = null; + if (staleReferencePolicy != null) + { + view.removeListener(this); + staleReferencePolicy.dispose(); + staleReferencePolicy = null; - expandedIDs.clear(); - viewer.removeTreeListener(this); + if (viewer != null) + { + expandedIDs.clear(); + viewer.removeTreeListener(this); + viewer = null; + } + } - viewer = null; view = null; } } @@ -199,6 +260,14 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener CDOViewTargetChangedEvent e = (CDOViewTargetChangedEvent)event; setTimeStamp(e.getBranchPoint().getTimeStamp()); } + else if (event instanceof ILifecycleEvent) + { + ILifecycleEvent e = (ILifecycleEvent)event; + if (e.getKind() == Kind.ABOUT_TO_DEACTIVATE) + { + disconnect(); + } + } } public void treeExpanded(TreeExpansionEvent event) @@ -228,7 +297,10 @@ public class TimeSlider extends Scale implements IListener, ITreeViewerListener protected void timeStampChanged(long timeStamp) { - view.setTimeStamp(timeStamp); + if (view != null) + { + view.setTimeStamp(timeStamp); + } } @Override diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java index 987fb1f349..bf05242b1c 100644 --- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java +++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/FolderCDOWorkspaceBase.java @@ -96,6 +96,8 @@ public class FolderCDOWorkspaceBase extends AbstractCDOWorkspaceBase try { fileReader = new FileReader(addedAndDetachedFile); + + @SuppressWarnings("resource") BufferedReader lineReader = new BufferedReader(fileReader); String line; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java index a73b9cba72..7315972e7e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFactoryImpl.java @@ -55,8 +55,10 @@ public class CDOResourceFactoryImpl implements CDOResourceFactory public Resource createResource(URI uri) { + boolean existing = isGetResource(); + CDOResourceImpl resource = createCDOResource(uri); - resource.setExisting(isGetResource()); + resource.setExisting(existing); return resource; } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java index 187db1f85f..e1e98752bc 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java @@ -25,7 +25,6 @@ import org.eclipse.emf.cdo.util.CDOModificationTrackingAdapter; import org.eclipse.emf.cdo.util.CDOURIUtil; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.cdo.util.CommitException; -import org.eclipse.emf.cdo.util.ReadOnlyException; import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.emf.cdo.view.CDOViewProvider; import org.eclipse.emf.cdo.view.CDOViewProviderRegistry; @@ -61,10 +60,13 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.EcoreUtil.ContentTreeIterator; import org.eclipse.emf.ecore.util.EcoreUtil.ProperContentIterator; import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.emf.ecore.xmi.DOMHandler; +import org.eclipse.emf.ecore.xmi.DOMHelper; import org.eclipse.emf.ecore.xmi.XMIResource; import org.eclipse.emf.ecore.xmi.XMLHelper; import org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.emf.ecore.xml.type.AnyType; import org.eclipse.emf.spi.cdo.FSMUtil; import org.eclipse.emf.spi.cdo.InternalCDOObject; import org.eclipse.emf.spi.cdo.InternalCDOResource; @@ -74,9 +76,14 @@ import org.eclipse.emf.spi.cdo.InternalCDOViewSet; import org.eclipse.core.runtime.IProgressMonitor; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -130,6 +137,11 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, private URI initialURI; /** + * @ADDED + */ + private URI uri; + + /** * TODO Set to true in commit()? * * @ADDED @@ -308,6 +320,11 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, @Override public URI getURI() { + if (uri != null) + { + return uri; + } + if ((cdoID() == null || cdoView() == null || cdoView().isClosed()) && initialURI != null) { return initialURI; @@ -343,12 +360,15 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, */ public void setURI(URI newURI) { - URI uri = getURI(); + boolean notificationRequired = eNotificationRequired(); + URI oldURI = notificationRequired ? getURI() : null; + String newPath = CDOURIUtil.extractResourcePath(newURI); setPath(newPath); - if (eNotificationRequired()) + + if (notificationRequired) { - Notification notification = new NotificationImpl(Notification.SET, uri, newURI) + Notification notification = new NotificationImpl(Notification.SET, oldURI, newURI) { @Override public Object getNotifier() @@ -362,10 +382,21 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, return RESOURCE__URI; } }; + eNotify(notification); } } + /** + * @ADDED + */ + @Override + public void setPath(String newPath) + { + super.setPath(newPath); + uri = CDOURIUtil.createResourceURI(cdoView(), newPath); + } + @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { @@ -531,7 +562,7 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, { if (cdoView().isReadOnly()) { - throw new ReadOnlyException("Underlying view is read-only"); + return; } if (newTrackingModification == isTrackingModification()) @@ -1210,16 +1241,16 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, IProgressMonitor progressMonitor = options != null ? (IProgressMonitor)options.get(CDOResource.OPTION_SAVE_PROGRESS_MONITOR) : null; - try - { - transaction.commit(progressMonitor); - } - catch (CommitException ex) - { - throw new TransactionException(ex); - } + try + { + transaction.commit(progressMonitor); + } + catch (CommitException ex) + { + throw new TransactionException(ex); + } - setModified(false); + setModified(false); } /** @@ -1230,20 +1261,20 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, CDOTransaction transaction = options != null ? (CDOTransaction)options.get(CDOResource.OPTION_SAVE_OVERRIDE_TRANSACTION) : null; - if (transaction == null) - { - CDOView view = cdoView(); - if (view instanceof CDOTransaction) - { - transaction = (CDOTransaction)view; - } - else - { - throw new IllegalStateException("No transaction available"); - } - } + if (transaction == null) + { + CDOView view = cdoView(); + if (view instanceof CDOTransaction) + { + transaction = (CDOTransaction)view; + } + else + { + throw new IllegalStateException("No transaction available"); + } + } - return transaction; + return transaction; } /** @@ -1478,10 +1509,20 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, InternalCDOTransaction transaction = (InternalCDOTransaction)view; InternalCDOObject cdoObject = FSMUtil.adapt(object, transaction); - if (CDOUtil.isLegacyObject(cdoObject) && FSMUtil.isClean(cdoObject)) + if (CDOUtil.isLegacyObject(cdoObject)) { - // Bug 352204 - return; + if (FSMUtil.isClean(cdoObject)) + { + // Bug 352204 + return; + } + + int xxx; + // EReference containmentFeature = object.eContainmentFeature(); + // if (!EMFUtil.isPersistent(containmentFeature)) + // { + // return; + // } } attached(cdoObject, transaction); @@ -1698,6 +1739,178 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements CDOResource, // } // } + /* XML STUFF BEGIN */ + + /** + * @since 4.4 + */ + public String getID(EObject eObject) + { + return getURIFragment(eObject); + } + + /** + * @since 4.4 + */ + public void setID(EObject eObject, String id) + { + // Do nothing. + } + + /** + * @since 4.4 + */ + public boolean useZip() + { + return false; + } + + /** + * @since 4.4 + */ + public void setUseZip(boolean useZip) + { + // Do nothing. + } + + /** + * @since 4.4 + */ + public String getPublicId() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public String getSystemId() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public DOMHelper getDOMHelper() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public Map<Object, Object> getDefaultLoadOptions() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public Map<Object, Object> getDefaultSaveOptions() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public Map<EObject, AnyType> getEObjectToExtensionMap() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public String getEncoding() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public void setEncoding(String encoding) + { + // Do nothing. + } + + /** + * @since 4.4 + */ + public String getXMLVersion() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public void setXMLVersion(String version) + { + // Do nothing. + } + + /** + * @since 4.4 + */ + public void setDoctypeInfo(String publicId, String systemId) + { + // Do nothing. + } + + /** + * @since 4.4 + */ + public void load(Node node, Map<?, ?> options) throws IOException + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public void load(InputSource inputSource, Map<?, ?> options) throws IOException + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public void save(Writer writer, Map<?, ?> options) throws IOException + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + public Document save(Document document, Map<?, ?> options, DOMHandler handler) + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + @Deprecated + public Map<String, EObject> getIDToEObjectMap() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 4.4 + */ + @Deprecated + public Map<EObject, String> getEObjectToIDMap() + { + throw new UnsupportedOperationException(); + } + /** * An implementation of a CDO specific '<em><b>contents</b></em>' list. * diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java index 81693a5237..0bade87d33 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceNodeImpl.java @@ -325,7 +325,13 @@ public abstract class CDOResourceNodeImpl extends CDOObjectImpl implements CDORe InternalCDORevision revision = cdoRevision(); if (revision != null) { - string += "(\"" + revision.getResourceNodeName() + "\")"; + String name = revision.getResourceNodeName(); + if (name == null) + { + name = "/"; + } + + string += "(\"" + name + "\")"; } return string; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java index 7d832015d4..641f3a8a6d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java @@ -68,6 +68,7 @@ import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.Logger; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; @@ -368,15 +369,6 @@ public final class CDOUtil return (CDOViewSet)notifier; } - EList<Adapter> adapters = notifier.eAdapters(); - for (Adapter adapter : adapters) - { - if (adapter instanceof CDOViewSet) - { - return (CDOViewSet)adapter; - } - } - if (notifier instanceof Resource) { Resource resource = (Resource)notifier; @@ -391,6 +383,15 @@ public final class CDOUtil } } + EList<Adapter> adapters = notifier.eAdapters(); + for (Adapter adapter : adapters) + { + if (adapter instanceof CDOViewSet) + { + return (CDOViewSet)adapter; + } + } + if (notifier instanceof InternalEObject) { InternalEObject object = (InternalEObject)notifier; @@ -419,11 +420,40 @@ public final class CDOUtil } /** + * @since 4.4 + */ + public static CDOView getView(Notifier notifier) + { + CDOViewSet viewSet = getViewSet(notifier); + if (viewSet != null) + { + CDOView[] views = viewSet.getViews(); + if (views != null && views.length != 0) + { + return views[0]; + } + } + + return null; + } + + /** * @since 3.0 */ public static boolean isStaleObject(Object object) { - return object instanceof CDOStaleObject; + if (object instanceof CDOStaleObject) + { + return true; + } + + if (object instanceof Logger) + { + // See org.eclipse.emf.cdo.view.CDOStaleReferencePolicy.DynamicProxy + return true; + } + + return false; } /** diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/AbstractCDOViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/AbstractCDOViewProvider.java index bbd7f29ca4..d38c45f6fd 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/AbstractCDOViewProvider.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/AbstractCDOViewProvider.java @@ -11,6 +11,8 @@ */ package org.eclipse.emf.cdo.view; +import org.eclipse.emf.cdo.view.CDOViewProvider.CDOViewProvider2; + import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; import org.eclipse.emf.common.util.URI; @@ -25,7 +27,7 @@ import java.util.regex.Pattern; * @since 2.0 * @apiviz.exclude */ -public abstract class AbstractCDOViewProvider implements CDOViewProvider +public abstract class AbstractCDOViewProvider implements CDOViewProvider2 { private String regex; @@ -96,4 +98,14 @@ public abstract class AbstractCDOViewProvider implements CDOViewProvider { return null; } + + /** + * Must be overwritten for non-canonical URI formats! + * + * @since 4.4 + */ + public String getPath(URI uri) + { + return null; + } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java index fb1a807c89..2a8b28ba06 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOStaleReferencePolicy.java @@ -26,6 +26,8 @@ import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notifier; import org.eclipse.emf.common.notify.impl.BasicNotifierImpl.EAdapterList; import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.Logger; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; @@ -238,14 +240,30 @@ public interface CDOStaleReferencePolicy // Be sure to have only interface if (instanceClass.isInterface()) { - interfaces = new Class<?>[] { instanceClass, InternalEObject.class, CDOStaleObject.class }; + interfaces = new Class<?>[] { InternalEObject.class, CDOStaleObject.class, instanceClass }; } else { interfaces = new Class<?>[] { InternalEObject.class, CDOStaleObject.class }; } - return Proxy.newProxyInstance(instanceClass.getClassLoader(), interfaces, handler); + try + { + return Proxy.newProxyInstance(instanceClass.getClassLoader(), interfaces, handler); + } + catch (IllegalArgumentException ex) + { + String message = ex.getMessage(); + if (message != null && message.contains("CDOStaleObject")) + { + // Interface org.eclipse.emf.cdo.view.CDOStaleObject is not visible from class loader. + // Use org.eclipse.emf.common.util.Logger instead. + interfaces[1] = Logger.class; + return Proxy.newProxyInstance(instanceClass.getClassLoader(), interfaces, handler); + } + + throw ex; + } } protected EClassifier getType(EObject source, EStructuralFeature feature, int index, CDOID target) @@ -314,7 +332,12 @@ public interface CDOStaleReferencePolicy private void addType(CDOObject object) { - types.putIfAbsent(object.cdoID(), object.eClass()); + CDOID id = object.cdoID(); + EClass type = object.eClass(); + if (id != null && type != null) + { + types.putIfAbsent(id, type); + } } } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java index 20bd6adb7e..9ec86d0809 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/view/CDOViewProvider.java @@ -53,4 +53,13 @@ public interface CDOViewProvider * @since 4.0 */ public URI getResourceURI(CDOView view, String path); + + /** + * @author Eike Stepper + * @since 4.4 + */ + public interface CDOViewProvider2 extends CDOViewProvider + { + public String getPath(URI uri); + } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java index bb63b4b1a8..d02b7bb163 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java @@ -358,6 +358,15 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC } else { + if (this.revision != null) + { + CDOID objectID = this.revision.getID(); + if (objectID != null && objectID != revision.getID()) + { + throw new IllegalArgumentException("The revision " + revision + " does not match the object " + objectID); + } + } + this.revision = (InternalCDORevision)revision; } } @@ -760,7 +769,8 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC public final NotificationChain eBasicSetContainer(InternalEObject newContainer, int newContainerFeatureID, NotificationChain msgs) { - boolean isResourceRoot = this instanceof CDOResource && ((CDOResource)this).isRoot(); + boolean isResource = this instanceof CDOResource; + boolean isRootResource = isResource && ((CDOResource)this).isRoot(); InternalEObject oldContainer = eInternalContainer(); Resource.Internal oldResource = eDirectResource(); @@ -796,7 +806,7 @@ public class CDOObjectImpl extends MinimalEStoreEObjectImpl implements InternalC : null; boolean moved = oldView != null && oldView == newView; - if (!moved && oldResource != null && oldResource != newResource && !isResourceRoot) + if (!moved && oldResource != null && oldResource != newResource && !isRootResource) { oldResource.detached(this); } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties index 62439301db..82bcf62fe5 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties @@ -57,8 +57,8 @@ CDOViewImpl.5=Node {0} not found CDOViewImpl.7=No top level ResourceNode with the name {0} CDOViewImpl.8=Duplicate top-level ResourceNodes CDOViewImpl.9=Cannot find revision with ID {0} -CDOViewProviderRegistryImpl.4=class not defined for extension {0} -CDOViewProviderRegistryImpl.6=regex not defined for extension {0} +CDOViewProviderRegistryImpl.4=Class not defined for extension {0} +CDOViewProviderRegistryImpl.6=Regex not defined for extension {0} CDOViewSetImpl.0=Cannot find associated CDOView for repository {0} CDOViewSetImpl.1=Do not know which CDOView to take since no authority has been specified CDOViewSetImpl.2=Only one view per repository can be open for the same resource set diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java index c2ad3d0bd5..b6a09cfe65 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOLegacyWrapper.java @@ -574,11 +574,14 @@ public abstract class CDOLegacyWrapper extends CDOObjectWrapper if (revision != null) { CDOID resourceID = revision.getResourceID(); - InternalEObject resource = getEObjectFromPotentialID(viewAndState.view, null, resourceID); - setInstanceResource((Resource.Internal)resource); - if (resource != null) + if (!CDOIDUtil.isNull(resourceID)) { - viewAndState.view.registerObject((InternalCDOObject)resource); + InternalEObject resource = getEObjectFromPotentialID(viewAndState.view, null, resourceID); + setInstanceResource((Resource.Internal)resource); + if (resource != null) + { + viewAndState.view.registerObject((InternalCDOObject)resource); + } } } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java index 6d21152b63..5eea5e796e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java @@ -1292,6 +1292,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa { throw new OperationCanceledException("CDOTransactionImpl.7");//$NON-NLS-1$ } + throw new CommitException(t); } finally @@ -3193,8 +3194,11 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa ((InternalCDOPackageUnit)newPackageUnit).setState(CDOPackageUnit.State.LOADED); } - postCommit(getNewObjects(), result); - postCommit(getDirtyObjects(), result); + Map<CDOID, CDOObject> newObjects = getNewObjects(); + postCommit(newObjects, result); + + Map<CDOID, CDOObject> dirtyObjects = getDirtyObjects(); + postCommit(dirtyObjects, result); for (CDORevisionDelta delta : getRevisionDeltas().values()) { @@ -3220,12 +3224,12 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa CDOBranchPoint commitBranchPoint = CDOBranchUtil.copyBranchPoint(result); // Note: keyset() does not work because ID mappings are not applied there! - for (CDOObject object : getNewObjects().values()) + for (CDOObject object : newObjects.values()) { session.setCommittedSinceLastRefresh(object.cdoID(), commitBranchPoint); } - for (CDOID id : getDirtyObjects().keySet()) + for (CDOID id : dirtyObjects.keySet()) { session.setCommittedSinceLastRefresh(id, commitBranchPoint); } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java index 92877852f3..3291bcc6f4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java @@ -1172,6 +1172,13 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb CDOID id = object.cdoID(); InternalCDOObject contextified = getObject(id, true); + if (objectFromDifferentView instanceof CDOLegacyAdapter) + { + @SuppressWarnings("unchecked") + T cast = (T)contextified; + return cast; + } + @SuppressWarnings("unchecked") T cast = (T)CDOUtil.getEObject(contextified); return cast; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOURIHandler.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOURIHandler.java index 3d2e33cced..062654b853 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOURIHandler.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOURIHandler.java @@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.eresource.CDOResourceNode; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.util.CDOURIUtil; import org.eclipse.emf.cdo.view.CDOViewProvider; +import org.eclipse.emf.cdo.view.CDOViewProvider.CDOViewProvider2; import org.eclipse.emf.cdo.view.CDOViewProviderRegistry; import org.eclipse.net4j.util.io.IOUtil; @@ -68,7 +69,8 @@ public class CDOURIHandler implements URIHandler public boolean exists(URI uri, Map<?, ?> options) { - return view.hasResource(CDOURIUtil.extractResourcePath(uri)); + String path = getPath(uri); + return view.hasResource(path); } public void delete(URI uri, Map<?, ?> options) throws IOException @@ -146,4 +148,22 @@ public class CDOURIHandler implements URIHandler // ViK: We can't change any of the proposed attributes. Only TIME_STAMP, and I believe we are not // storing that attribute in the server. Due to CDOResouce distributed nature, changing it wouldn't make much sense. } + + private String getPath(URI uri) + { + if (CDO_URI_SCHEME.equals(uri.scheme())) + { + return CDOURIUtil.extractResourcePath(uri); + } + + for (CDOViewProvider viewProvider : CDOViewProviderRegistry.INSTANCE.getViewProviders(uri)) + { + if (viewProvider instanceof CDOViewProvider2) + { + return ((CDOViewProvider2)viewProvider).getPath(uri); + } + } + + return null; + } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java index 14f5847eb4..c8f32369f6 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewProviderRegistryImpl.java @@ -114,11 +114,15 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider>imple public CDOViewProvider[] getViewProviders(URI uri) { List<CDOViewProvider> result = new ArrayList<CDOViewProvider>(); - for (CDOViewProvider viewProvider : viewProviders) + + synchronized (viewProviders) { - if (viewProvider.matchesRegex(uri)) + for (CDOViewProvider viewProvider : viewProviders) { - result.add(viewProvider); + if (viewProvider.matchesRegex(uri)) + { + result.add(viewProvider); + } } } @@ -235,7 +239,7 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider>imple public CDOViewProviderDescriptor(IConfigurationElement element) { - super(element.getAttribute("regex"), Integer.parseInt(element.getAttribute("priority"))); //$NON-NLS-1$ //$NON-NLS-2$ + super(getRegex(element), getPriority(element)); this.element = element; if (StringUtil.isEmpty(element.getAttribute("class"))) //$NON-NLS-1$ @@ -243,12 +247,6 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider>imple throw new IllegalArgumentException( MessageFormat.format(Messages.getString("CDOViewProviderRegistryImpl.4"), element)); //$NON-NLS-1$ } - - if (StringUtil.isEmpty(element.getAttribute("regex"))) //$NON-NLS-1$ - { - throw new IllegalArgumentException( - MessageFormat.format(Messages.getString("CDOViewProviderRegistryImpl.6"), element)); //$NON-NLS-1$ - } } public CDOView getView(URI uri, ResourceSet resourceSet) @@ -262,6 +260,18 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider>imple return getViewProvider().getResourceURI(view, path); } + @Override + public String getPath(URI uri) + { + CDOViewProvider viewProvider = getViewProvider(); + if (viewProvider instanceof CDOViewProvider2) + { + return ((CDOViewProvider2)viewProvider).getPath(uri); + } + + return super.getPath(uri); + } + private CDOViewProvider getViewProvider() { try @@ -273,5 +283,30 @@ public class CDOViewProviderRegistryImpl extends Container<CDOViewProvider>imple throw WrappedException.wrap(ex); } } + + private static String getRegex(IConfigurationElement element) + { + String value = element.getAttribute("regex"); + if (StringUtil.isEmpty(value)) + { + throw new IllegalArgumentException( + MessageFormat.format(Messages.getString("CDOViewProviderRegistryImpl.6"), element)); //$NON-NLS-1$ + } + + return value; + } + + private static int getPriority(IConfigurationElement element) + { + try + { + String value = element.getAttribute("priority"); + return Integer.parseInt(value); + } + catch (Exception ex) + { + return DEFAULT_PRIORITY; + } + } } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java index 565afc67a2..d38c8af8c7 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewSetImpl.java @@ -30,7 +30,6 @@ import org.eclipse.emf.common.notify.impl.NotificationImpl; import org.eclipse.emf.common.notify.impl.NotifierImpl; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.Resource.Factory.Registry; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.spi.cdo.InternalCDOObject; import org.eclipse.emf.spi.cdo.InternalCDOView; @@ -58,7 +57,7 @@ public class CDOViewSetImpl extends NotifierImpl implements InternalCDOViewSet private Map<String, InternalCDOView> mapOfViews = new HashMap<String, InternalCDOView>(); - private CDOResourceFactory resourceFactory = CDOResourceFactory.INSTANCE; + private CDOResourceFactory resourceFactory; private CDOViewSetPackageRegistryImpl packageRegistry; @@ -244,9 +243,17 @@ public class CDOViewSetImpl extends NotifierImpl implements InternalCDOViewSet packageRegistry = new CDOViewSetPackageRegistryImpl(this, oldPackageRegistry); resourceSet.setPackageRegistry(packageRegistry); - Registry registry = resourceSet.getResourceFactoryRegistry(); - Map<String, Object> map = registry.getProtocolToFactoryMap(); - map.put(CDOProtocolConstants.PROTOCOL_NAME, getResourceFactory()); + Map<String, Object> map = resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap(); + Resource.Factory resourceFactory = (Resource.Factory)map.get(CDOProtocolConstants.PROTOCOL_NAME); + if (resourceFactory instanceof CDOResourceFactory) + { + this.resourceFactory = (CDOResourceFactory)resourceFactory; + } + else if (resourceFactory == null) + { + this.resourceFactory = CDOResourceFactory.INSTANCE; + map.put(CDOProtocolConstants.PROTOCOL_NAME, this.resourceFactory); + } } } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOResource.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOResource.java index 18f0ab1ce3..834401410d 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOResource.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOResource.java @@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.XMLResource; /** * Internal protocol for the {@link CDOResource}. @@ -22,7 +23,7 @@ import org.eclipse.emf.ecore.resource.Resource; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface InternalCDOResource extends CDOResource, Resource.Internal +public interface InternalCDOResource extends CDOResource, Resource.Internal, XMLResource { /** * Informs the resource that an {@code object} contained within it is being loaded. diff --git a/plugins/org.eclipse.net4j.db/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.net4j.db/.settings/org.eclipse.jdt.core.prefs index e8d729090c..41eeb49ad0 100644 --- a/plugins/org.eclipse.net4j.db/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/org.eclipse.net4j.db/.settings/org.eclipse.jdt.core.prefs @@ -17,6 +17,12 @@ org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve @@ -37,6 +43,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod= org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=warning org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore @@ -55,7 +62,9 @@ org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled @@ -71,21 +80,33 @@ org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warni org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning @@ -95,6 +116,7 @@ org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedImport=warning org.eclipse.jdt.core.compiler.problem.unusedLabel=warning org.eclipse.jdt.core.compiler.problem.unusedLocal=warning @@ -104,6 +126,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference= org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.5 diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java index 90a3f88899..835dcc756b 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/db/DBUtil.java @@ -14,6 +14,7 @@ import org.eclipse.net4j.db.ddl.IDBField; import org.eclipse.net4j.db.ddl.IDBNamedElement; import org.eclipse.net4j.db.ddl.IDBSchema; import org.eclipse.net4j.db.ddl.IDBTable; +import org.eclipse.net4j.internal.db.DBConnection; import org.eclipse.net4j.internal.db.DBDatabase; import org.eclipse.net4j.internal.db.DataSourceConnectionProvider; import org.eclipse.net4j.internal.db.bundle.OM; @@ -54,6 +55,7 @@ import java.util.Set; * * @author Eike Stepper */ +@SuppressWarnings("resource") public final class DBUtil { /** @@ -79,6 +81,18 @@ public final class DBUtil } /** + * @deprecated This method exists only to create a "resource leak" warning, so that DBUtil can safely SuppressWarnings("resource"). + */ + @Deprecated + @SuppressWarnings("unused") + private static void avoidResourceLeakWarning() throws SQLException + { + Connection connection = new DBConnection(null, null); + Statement statement = connection.createStatement(); + close(statement); + } + + /** * For debugging purposes ONLY! * * @deprecated Should only be used when debugging. @@ -376,6 +390,7 @@ public final class DBUtil } catch (Exception ignore) { + //$FALL-THROUGH$ } try @@ -388,6 +403,7 @@ public final class DBUtil { throw new DBException(ex); } + OM.LOG.error(ex); return ex; } @@ -410,6 +426,7 @@ public final class DBUtil { throw new DBException(ex); } + OM.LOG.error(ex); return ex; } @@ -439,6 +456,7 @@ public final class DBUtil { throw new DBException(ex); } + OM.LOG.error(ex); return ex; } @@ -934,7 +952,6 @@ public final class DBUtil return update(connection, sql); } - @SuppressWarnings("resource") public static int select(Connection connection, IDBRowHandler rowHandler, String where, IDBField... fields) throws DBException { diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java index ae939543af..5fbef5faed 100644 --- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java +++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/spi/db/DBAdapter.java @@ -59,38 +59,38 @@ public abstract class DBAdapter implements IDBAdapter private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SQL, DBAdapter.class); private static final String[] SQL92_RESERVED_WORDS = { "ABSOLUTE", "ACTION", "ADD", "AFTER", "ALL", "ALLOCATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "ALTER", "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "AUTHORIZATION", "AVG", "BEFORE", "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BIT", "BIT_LENGTH", "BLOB", "BOOLEAN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "BOTH", "BREADTH", "BY", "CALL", "CALLED", "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "CHARACTER_LENGTH", "CHAR_LENGTH", "CHECK", "CLOB", "CLOSE", "COALESCE", "COLLATE", "COLLATION", "COLUMN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "COMMIT", "CONDITION", "CONNECT", "CONNECTION", "CONSTRAINT", "CONSTRAINTS", "CONSTRUCTOR", "CONTAINS", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - "CONTINUE", "CONVERT", "CORRESPONDING", "COUNT", "CREATE", "CROSS", "CUBE", "CURRENT", "CURRENT_DATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "CURRENT_DEFAULT_TRANSFORM_GROUP", "CURRENT_PATH", "CURRENT_ROLE", "CURRENT_TIME", "CURRENT_TIMESTAMP", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "CURRENT_TRANSFORM_GROUP_FOR_TYPE", "CURRENT_USER", "CURSOR", "CYCLE", "DATA", "DATE", "DAY", "DEALLOCATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DEFERRABLE", "DEFERRED", "DELETE", "DEPTH", "DEREF", "DESC", "DESCRIBE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "DESCRIPTOR", "DETERMINISTIC", "DIAGNOSTICS", "DISCONNECT", "DISTINCT", "DO", "DOMAIN", "DOUBLE", "DROP", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "DYNAMIC", "EACH", "ELEMENT", "ELSE", "ELSEIF", "END", "EQUALS", "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "EXECUTE", "EXISTS", "EXIT", "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FILTER", "FIRST", "FLOAT", "FOR", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "FOREIGN", "FOUND", "FREE", "FROM", "FULL", "FUNCTION", "GENERAL", "GET", "GLOBAL", "GO", "GOTO", "GRANT", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "GROUP", "GROUPING", "HANDLER", "HAVING", "HOLD", "HOUR", "IDENTITY", "IF", "IMMEDIATE", "IN", "INDICATOR", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "INITIALLY", "INNER", "INOUT", "INPUT", "INSENSITIVE", "INSERT", "INT", "INTEGER", "INTERSECT", "INTERVAL", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "INTO", "IS", "ISOLATION", "ITERATE", "JOIN", "KEY", "LANGUAGE", "LARGE", "LAST", "LATERAL", "LEADING", "LEAVE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "LEFT", "LEVEL", "LIKE", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCATOR", "LOOP", "LOWER", "MAP", "MATCH", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "MAX", "MEMBER", "MERGE", "METHOD", "MIN", "MINUTE", "MODIFIES", "MODULE", "MONTH", "MULTISET", "NAMES", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "NATIONAL", "NATURAL", "NCHAR", "NCLOB", "NEW", "NEXT", "NO", "NONE", "NOT", "NULL", "NULLIF", "NUMERIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "OBJECT", "OCTET_LENGTH", "OF", "OLD", "ON", "ONLY", "OPEN", "OPTION", "OR", "ORDER", "ORDINALITY", "OUT", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "OUTER", "OUTPUT", "OVER", "OVERLAPS", "PAD", "PARAMETER", "PARTIAL", "PARTITION", "PATH", "POSITION", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "PRECISION", "PREPARE", "PRESERVE", "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "RANGE", "READ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "READS", "REAL", "RECURSIVE", "REF", "REFERENCES", "REFERENCING", "RELATIVE", "RELEASE", "REPEAT", "RESIGNAL", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "RESTRICT", "RESULT", "RETURN", "RETURNS", "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROLLUP", "ROUTINE", "ROW", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "ROWS", "SAVEPOINT", "SCHEMA", "SCOPE", "SCROLL", "SEARCH", "SECOND", "SECTION", "SELECT", "SENSITIVE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ - "SESSION", "SESSION_USER", "SET", "SETS", "SIGNAL", "SIMILAR", "SIZE", "SMALLINT", "SOME", "SPACE", "SPECIFIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "SPECIFICTYPE", "SQL", "SQLCODE", "SQLERROR", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "START", "STATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "STATIC", "SUBMULTISET", "SUBSTRING", "SUM", "SYMMETRIC", "SYSTEM", "SYSTEM_USER", "TABLE", "TABLESAMPLE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "TEMPORARY", "THEN", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ - "TRANSLATE", "TRANSLATION", "TREAT", "TRIGGER", "TRIM", "TRUE", "UNDER", "UNDO", "UNION", "UNIQUE", "UNKNOWN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ - "UNNEST", "UNTIL", "UPDATE", "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR", "VARYING", "VIEW", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ - "WHEN", "WHENEVER", "WHERE", "WHILE", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRITE", "YEAR", "ZONE" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "ALTER", "AND", "ANY", "ARE", "ARRAY", "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASYMMETRIC", "AT", "ATOMIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "AUTHORIZATION", "AVG", "BEFORE", "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BIT", "BIT_LENGTH", "BLOB", "BOOLEAN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "BOTH", "BREADTH", "BY", "CALL", "CALLED", "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CHAR", "CHARACTER", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "CHARACTER_LENGTH", "CHAR_LENGTH", "CHECK", "CLOB", "CLOSE", "COALESCE", "COLLATE", "COLLATION", "COLUMN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "COMMIT", "CONDITION", "CONNECT", "CONNECTION", "CONSTRAINT", "CONSTRAINTS", "CONSTRUCTOR", "CONTAINS", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ + "CONTINUE", "CONVERT", "CORRESPONDING", "COUNT", "CREATE", "CROSS", "CUBE", "CURRENT", "CURRENT_DATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "CURRENT_DEFAULT_TRANSFORM_GROUP", "CURRENT_PATH", "CURRENT_ROLE", "CURRENT_TIME", "CURRENT_TIMESTAMP", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + "CURRENT_TRANSFORM_GROUP_FOR_TYPE", "CURRENT_USER", "CURSOR", "CYCLE", "DATA", "DATE", "DAY", "DEALLOCATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ + "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DEFERRABLE", "DEFERRED", "DELETE", "DEPTH", "DEREF", "DESC", "DESCRIBE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "DESCRIPTOR", "DETERMINISTIC", "DIAGNOSTICS", "DISCONNECT", "DISTINCT", "DO", "DOMAIN", "DOUBLE", "DROP", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "DYNAMIC", "EACH", "ELEMENT", "ELSE", "ELSEIF", "END", "EQUALS", "ESCAPE", "EXCEPT", "EXCEPTION", "EXEC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "EXECUTE", "EXISTS", "EXIT", "EXTERNAL", "EXTRACT", "FALSE", "FETCH", "FILTER", "FIRST", "FLOAT", "FOR", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "FOREIGN", "FOUND", "FREE", "FROM", "FULL", "FUNCTION", "GENERAL", "GET", "GLOBAL", "GO", "GOTO", "GRANT", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "GROUP", "GROUPING", "HANDLER", "HAVING", "HOLD", "HOUR", "IDENTITY", "IF", "IMMEDIATE", "IN", "INDICATOR", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "INITIALLY", "INNER", "INOUT", "INPUT", "INSENSITIVE", "INSERT", "INT", "INTEGER", "INTERSECT", "INTERVAL", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "INTO", "IS", "ISOLATION", "ITERATE", "JOIN", "KEY", "LANGUAGE", "LARGE", "LAST", "LATERAL", "LEADING", "LEAVE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "LEFT", "LEVEL", "LIKE", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCATOR", "LOOP", "LOWER", "MAP", "MATCH", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "MAX", "MEMBER", "MERGE", "METHOD", "MIN", "MINUTE", "MODIFIES", "MODULE", "MONTH", "MULTISET", "NAMES", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "NATIONAL", "NATURAL", "NCHAR", "NCLOB", "NEW", "NEXT", "NO", "NONE", "NOT", "NULL", "NULLIF", "NUMERIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "OBJECT", "OCTET_LENGTH", "OF", "OLD", "ON", "ONLY", "OPEN", "OPTION", "OR", "ORDER", "ORDINALITY", "OUT", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "OUTER", "OUTPUT", "OVER", "OVERLAPS", "PAD", "PARAMETER", "PARTIAL", "PARTITION", "PATH", "POSITION", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "PRECISION", "PREPARE", "PRESERVE", "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURE", "PUBLIC", "RANGE", "READ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "READS", "REAL", "RECURSIVE", "REF", "REFERENCES", "REFERENCING", "RELATIVE", "RELEASE", "REPEAT", "RESIGNAL", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "RESTRICT", "RESULT", "RETURN", "RETURNS", "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROLLUP", "ROUTINE", "ROW", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "ROWS", "SAVEPOINT", "SCHEMA", "SCOPE", "SCROLL", "SEARCH", "SECOND", "SECTION", "SELECT", "SENSITIVE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ + "SESSION", "SESSION_USER", "SET", "SETS", "SIGNAL", "SIMILAR", "SIZE", "SMALLINT", "SOME", "SPACE", "SPECIFIC", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "SPECIFICTYPE", "SQL", "SQLCODE", "SQLERROR", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "START", "STATE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "STATIC", "SUBMULTISET", "SUBSTRING", "SUM", "SYMMETRIC", "SYSTEM", "SYSTEM_USER", "TABLE", "TABLESAMPLE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "TEMPORARY", "THEN", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TRAILING", "TRANSACTION", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ + "TRANSLATE", "TRANSLATION", "TREAT", "TRIGGER", "TRIM", "TRUE", "UNDER", "UNDO", "UNION", "UNIQUE", "UNKNOWN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ + "UNNEST", "UNTIL", "UPDATE", "UPPER", "USAGE", "USER", "USING", "VALUE", "VALUES", "VARCHAR", "VARYING", "VIEW", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ + "WHEN", "WHENEVER", "WHERE", "WHILE", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRITE", "YEAR", "ZONE" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ private String name; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/UUIDGenerator.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/UUIDGenerator.java index 6701e39043..ae0e7dc842 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/UUIDGenerator.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/UUIDGenerator.java @@ -134,7 +134,7 @@ public final class UUIDGenerator } private static final char[] BASE64_DIGITS = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' }; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceMonitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceMonitor.java new file mode 100644 index 0000000000..dadca8cb0f --- /dev/null +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ref/ReferenceMonitor.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004-2014 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.util.ref; + +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.WeakReference; + +/** + * @author Eike Stepper + * @since 3.5 + */ +public abstract class ReferenceMonitor<T> extends ReferenceQueueWorker<T> +{ + public ReferenceMonitor() + { + } + + public void monitor(T object) + { + ReferenceQueue<T> queue = getQueue(); + new WeakReference<T>(object, queue); + } + + @Override + protected void work(Reference<? extends T> reference) + { + T object = reference.get(); + if (object != null) + { + work(object); + } + } + + protected abstract void work(T object); +} |