Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.wst.common.emfworkbench.integration/src/org')
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/CompatibilityWorkbenchURIConverterImpl.java90
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/DynamicGrowthModel.java88
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchContext.java422
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchEditResourceHandler.java53
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EditModelLeastUsedCache.java113
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfPackagePropertyTester.java17
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfValidationHandler.java61
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/PassthruResourceSet.java144
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java531
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryDescriptor.java162
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryRegistry.java116
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ChildCommand.java103
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistry.java102
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistryException.java152
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EMFWorkbenchEditContextFactory.java102
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtension.java69
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtensionRegistry.java98
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java370
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelResource.java115
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRetriever.java48
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ExtendedComposedAdapterFactory.java103
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/InvertedCommand.java68
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ParentCommand.java156
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ReadOnlyClientAccessRegistry.java51
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/Snapshot.java45
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/WrappingCommandStack.java39
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/AbstractEditModelCommand.java58
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedAccessorKey.java56
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedEditModel.java279
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/CompoundingCommandStack.java152
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/DynamicAdapterFactory.java642
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin.java78
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java1610
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelCommand.java48
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelEvent.java122
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelFactory.java62
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelListener.java24
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelNature.java64
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/IEditModelFactory.java31
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/LooseComposedEditModel.java37
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModelModifier.java615
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelper.java363
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperChainer.java49
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperFactory.java34
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperRegistry.java273
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/OwnerProvider.java31
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ProjectResourceSetEditImpl.java53
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java453
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/IValidateEditContext.java30
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateInputProvider.java60
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidator.java57
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java446
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorPresenter.java50
-rw-r--r--plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ValidateEditHeadlessContext.java97
54 files changed, 0 insertions, 9292 deletions
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/CompatibilityWorkbenchURIConverterImpl.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/CompatibilityWorkbenchURIConverterImpl.java
deleted file mode 100644
index 8ae0cd127..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/CompatibilityWorkbenchURIConverterImpl.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 4, 2004
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverterImpl;
-import org.eclipse.wst.common.internal.emf.resource.CompatibilityURIConverter;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class CompatibilityWorkbenchURIConverterImpl extends WorkbenchURIConverterImpl implements CompatibilityURIConverter {
- /**
- *
- */
- public CompatibilityWorkbenchURIConverterImpl() {
- super();
- }
-
- /**
- * @param anInputContainer
- */
- public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer) {
- super(anInputContainer);
- }
-
- /**
- * @param aContainer
- * @param aSynchronizer
- */
- public CompatibilityWorkbenchURIConverterImpl(IContainer aContainer, ResourceSetWorkbenchSynchronizer aSynchronizer) {
- super(aContainer, aSynchronizer);
- }
-
- /**
- * @param anInputContainer
- * @param anOutputContainer
- */
- public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer, IContainer anOutputContainer) {
- super(anInputContainer, anOutputContainer);
- }
-
- /**
- * @param anInputContainer
- * @param anOutputContainer
- * @param aSynchronizer
- */
- public CompatibilityWorkbenchURIConverterImpl(IContainer anInputContainer, IContainer anOutputContainer, ResourceSetWorkbenchSynchronizer aSynchronizer) {
- super(anInputContainer, anOutputContainer, aSynchronizer);
- }
-
- /**
- * @see com.ibm.etools.xmi.helpers.CompatibilityURIConverter#deNormalize(URI)
- */
- public URI deNormalize(URI uri) {
- if (WorkbenchResourceHelperBase.isPlatformResourceURI(uri)) {
- IFile aFile = WorkbenchResourceHelper.getPlatformFile(uri);
- if (aFile != null) {
- IProject fileProject = aFile.getProject();
- //If it is not in the same project then just return the URI as is.
- if (resourceSetSynchronizer.getProject() == fileProject)
- return getContainerRelativeURI(aFile);
- }
- }
- return uri;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/DynamicGrowthModel.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/DynamicGrowthModel.java
deleted file mode 100644
index 8aed2eed1..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/DynamicGrowthModel.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IPath;
-
-
-public class DynamicGrowthModel {
-
- private static final int MINIMUM_OPTIMAL_SIZE = 10;
-
- private static final int MEMORY_THRESHHOLD = 100;
-
- private static final int NOTICEABLE_CHANGE = 5;
-
-
- /* Stores a FIFO list of the Key types (IPath)*/
- private final List queue = new LinkedList();
-
- /* We use an int[] as the value so we don't have to keep creating Integer objects */
- private final Map/* <IPath, int[]> */ uniquesMap = new HashMap();
-
-
- /**
- * Inject the key into the DynamicGrowthModel. May or may not affect the
- * dynamic size.
- *
- * @param key The key to inject into the model
- * @return True if the optimal size changed greather than {@value NOTICEABLE_CHANGE} as a result of the injection.
- */
- public synchronized boolean injectKey(IPath key) {
-
- int originalSize = getOptimalSize();
-
- int[] count = null;
- if( (count = (int[]) uniquesMap.get(key)) != null ) {
- /* increment the count */
- ++count[0];
- } else {
- /* insert the first count */
- uniquesMap.put(key, count = new int[] { 1 } );
- }
-
- if( queue.size() == MEMORY_THRESHHOLD ) {
-
- /* take the oldest value off the queue */
- IPath oldestKey = (IPath) queue.remove(0);
-
- /* determine if another instance of the oldest key is still in the queue */
- count = (int[]) uniquesMap.get(oldestKey);
- Assert.isNotNull(count);
-
- /* Reduce the count */
- count[0] -= 1;
-
- /* Count should never be negative */
- Assert.isTrue(count[0] >= 0);
-
-
- /* This unique key is no longer in the queue*/
- if(count[0] == 0) {
- uniquesMap.remove(oldestKey);
- }
-
-
-
- }
- /* Add the newKey to end of the list*/
- queue.add(key);
-
- return Math.abs( originalSize - getOptimalSize() ) > NOTICEABLE_CHANGE;
-
- }
-
- /**
- * The optimal size is an integer from [{@value #MINIMUM_OPTIMAL_SIZE}, {@value #MEMORY_THRESHHOLD}].
- *
- * @return the optimal size for the LRU Cache.
- */
- public int getOptimalSize() {
- return uniquesMap.size() > MINIMUM_OPTIMAL_SIZE ? uniquesMap.size() : MINIMUM_OPTIMAL_SIZE;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchContext.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchContext.java
deleted file mode 100644
index 378788b41..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchContext.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 3, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jem.util.emf.workbench.EMFWorkbenchContextBase;
-import org.eclipse.jem.util.emf.workbench.ISynchronizerExtender;
-import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
-import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverter;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.internal.emf.resource.CompatibilityXMIResource;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedXMIFactoryImpl;
-import org.eclipse.wst.common.internal.emf.utilities.DefaultOverridableResourceFactoryRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.edit.EditModelRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelEvent;
-import org.eclipse.wst.common.internal.emfworkbench.integration.ProjectResourceSetEditImpl;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class EMFWorkbenchContext extends EMFWorkbenchContextBase implements ISynchronizerExtender {
-
- private Map readOnlyModels = new HashMap();
- private Map editableModels = new HashMap();
-
- protected Adapter resourceSetListener;
-
- protected boolean defaultToMOF5Compatibility = false;
-
-
- /**
- * @param aProject
- */
- public EMFWorkbenchContext(IProject aProject) {
- super(aProject);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext#initializeResourceSet(org.eclipse.wst.common.internal.emfworkbench.ProjectResourceSet)
- */
- protected void initializeResourceSet(ProjectResourceSet aResourceSet) {
- super.initializeResourceSet(aResourceSet);
- Resource.Factory.Registry reg = new DefaultOverridableResourceFactoryRegistry();
- Resource.Factory factory = new ReferencedXMIFactoryImpl();
- reg.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, factory);
- // add xmi because other plugins are registering it globally
- reg.getExtensionToFactoryMap().put("xmi", factory); //$NON-NLS-1$
- aResourceSet.setResourceFactoryRegistry(reg);
- aResourceSet.getSynchronizer().addExtender(this); // added so we can be informed of closes
- // to the project.
- startListeningToResourceSet();
- }
-
- public static String getCacheID(String editModelID, Map params) {
- return EditModelRegistry.getInstance().getCacheID(editModelID, params);
- }
-
- /**
- * This is the API that clients should use when they have an intent to modify a particular
- * resource. You should only access the resources through the J2EEEditModel that is returned by
- * this method if you have the intent to modify.
- *
- * @see J2EEEditModel
- */
- public final EditModel getEditModelForWrite(String editModelID, Object accessorKey, Map params) {
- EditModel editModel = getExistingEditModel(editModelID, params, false);
- if (null == editModel) {
- editModel = createEditModelForWrite(editModelID, params);
- synchronized (editModel) {
- cacheEditModel(editModel, params);
- editModel.access(accessorKey);
- }
- } else {
- synchronized (editModel) {
- if (editModel.isDisposed() || editModel.isDisposing()) {
- editModel = createEditModelForWrite(editModelID, params);
- cacheEditModel(editModel, params);
- }
- editModel.access(accessorKey);
- }
- }
- return editModel;
- }
-
- /**
- * This is the API that clients should use when they want to read a group of resources that are
- * normally managed by the edit model with
- *
- * @aKey. You should only access the resources through the J2EEEditModel that is returned by
- * this method. You must call releaseEditModel(...) when you are finished with the edit
- * model.
- * @see J2EEEditModel
- */
- public final EditModel getEditModelForRead(String editModelID, Object accessorKey, Map params) {
- try {
- EditModel editModel = getExistingEditModel(editModelID, params, true);
- if (null == editModel) {
- editModel = createEditModelForRead(editModelID, params);
- synchronized (editModel) {
- cacheEditModel(editModel, params);
- EditModelLeastUsedCache.getInstance().access(editModel);
- editModel.access(accessorKey);
- }
- } else {
- synchronized (editModel) {
- if (editModel.isDisposed() || editModel.isDisposing()) {
- editModel = createEditModelForRead(editModelID, params);
- cacheEditModel(editModel, params);
- }
- EditModelLeastUsedCache.getInstance().access(editModel);
- editModel.access(accessorKey);
- }
- }
- return editModel;
- } finally {
- EditModelLeastUsedCache.getInstance().optimizeLRUSizeIfNecessary();
- }
- }
-
- /**
- * This is the API that clients should use when they have an intent to modify a particular
- * resource. You should only access the resources through the J2EEEditModel that is returned by
- * this method if you have the intent to modify.
- *
- * @see J2EEEditModel
- */
- public final EditModel getEditModelForWrite(String editModelID, Object accessorKey) {
- return getEditModelForWrite(editModelID, accessorKey, null);
- }
-
- /**
- * This is the API that clients should use when they want to read a group of resources that are
- * normally managed by the edit model with
- *
- * @aKey. You should only access the resources through the J2EEEditModel that is returned by
- * this method. You must call releaseEditModel(...) when you are finished with the edit
- * model.
- * @see J2EEEditModel
- */
- public final EditModel getEditModelForRead(String editModelID, Object accessorKey) {
- return getEditModelForRead(editModelID, accessorKey, null);
- }
-
-
-
- public EditModel getExistingEditModel(String editModelID, Map params, boolean isReadOnly) {
- EditModel editModel = null;
- synchronized (readOnlyModels) {
- if (isReadOnly) {
- editModel = (EditModel) readOnlyModels.get(getCacheID(editModelID, params));
- } else {
- synchronized (editableModels) {
- editModel = (EditModel) editableModels.get(getCacheID(editModelID, params));
- }
- }
- }
- return editModel;
- }
-
- /**
- * Subclasses may override to return the appropriate read-only J2EEEditModel.
- */
- protected EditModel createEditModelForRead(String editModelID, Map params) {
- return EditModelRegistry.getInstance().createEditModelForRead(editModelID, this, params);
- }
-
- /**
- * Subclasses may override to return the appropriate J2EEEditModel.
- */
- protected EditModel createEditModelForWrite(String editModelID, Map params) {
- return EditModelRegistry.getInstance().createEditModelForWrite(editModelID, this, params);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/16/2001 12:25:39 PM)
- *
- * @return java.util.List
- */
- public void cacheEditModel(EditModel editModel, Map params) {
- editModel.setParams(params);
- synchronized (readOnlyModels) {
- if (editModel.isReadOnly())
- readOnlyModels.put(getCacheID(editModel.getEditModelID(), params), editModel);
- else
- synchronized (editableModels) {
- editableModels.put(getCacheID(editModel.getEditModelID(), params), editModel);
- }
- }
- }
-
- protected void discardAllEditModels() {
- synchronized (readOnlyModels) {
- synchronized (editableModels) {
- Collection readOnly = readOnlyModels.values();
- EditModelLeastUsedCache.getInstance().removeAllCached(readOnly);
- discardModels(readOnly);
- discardModels(editableModels.values());
- }
- }
-
- }
-
- private void discardModels(Collection editModels) {
- if (editModels != null && !editModels.isEmpty()) {
- // Make a copy for safety against concurrent modification
- Iterator it = new ArrayList(editModels).iterator();
- while (it.hasNext()) {
- ((EditModel) it.next()).dispose();
- }
- }
- }
-
- public void removeEditModel(EditModel editModel, boolean readOnly) {
- // The best way would be to recompute the cache id, but we don't care
- // because the edit model should only be cached once anyway
- synchronized (readOnlyModels) {
- if (readOnly)
- readOnlyModels.values().remove(editModel);
- else
- synchronized (editableModels) {
- editableModels.values().remove(editModel);
- }
- }
- }
-
- /**
- * Notify all editModels of the change.
- */
- protected void notifyEditModels(EditModelEvent anEvent) {
- if (anEvent == null)
- return;
- List aList = new ArrayList();
- synchronized (readOnlyModels) {
- synchronized (editableModels) {
- aList.addAll(readOnlyModels.values());
- aList.addAll(editableModels.values());
- }
- }
- EditModel editModel;
- for (int i = 0; i < aList.size(); i++) {
- editModel = (EditModel) aList.get(i);
- try {
- editModel.resourceChanged(anEvent);
- } catch (Exception e) {
- Logger.getLogger().logError(e);
- }
- }
- }
-
- protected boolean shouldNotifyEditModels() {
- synchronized (readOnlyModels) {
- synchronized (editableModels) {
- return !this.readOnlyModels.isEmpty() || !this.editableModels.isEmpty();
- }
- }
- }
-
- protected Adapter getResourceSetListener() {
- if (resourceSetListener == null)
- resourceSetListener = new ResourceSetListener();
- return resourceSetListener;
- }
-
-
- protected class ResourceSetListener extends AdapterImpl {
- /*
- * @see Adapter#notifyChanged(new ENotificationImpl((InternalEObject)Notifier,
- * int,(EStructuralFeature) EObject, Object, Object, int))
- */
- public void notifyChanged(Notification notification) {
- switch (notification.getEventType()) {
- case Notification.ADD :
- addedResource((Resource) notification.getNewValue());
- break;
- case Notification.REMOVE :
- removedResource((Resource) notification.getOldValue());
- break;
- case Notification.REMOVE_MANY :
- removedResources((List) notification.getOldValue());
- break;
- }
- }
- }
-
- /**
- * Notify all editModels of the change.
- */
- public void addedResource(Resource addedResource) {
- if (defaultToMOF5Compatibility && (addedResource != null) && (addedResource instanceof CompatibilityXMIResource))
- ((CompatibilityXMIResource) addedResource).setFormat(CompatibilityXMIResource.FORMAT_MOF5);
- if (shouldNotifyEditModels()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.ADDED_RESOURCE, null);
- event.addResource(addedResource);
- notifyEditModels(event);
- }
- }
-
- /**
- * Notify all editModels of the change.
- */
- public void removedResource(Resource removedResource) {
- if (shouldNotifyEditModels()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.REMOVED_RESOURCE, null);
- event.addResource(removedResource);
- notifyEditModels(event);
- }
- }
-
- /**
- * Notify all editModels of the change.
- */
- public void removedResources(List removedResources) {
- if (shouldNotifyEditModels()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.REMOVED_RESOURCE, null);
- event.addResources(removedResources);
- notifyEditModels(event);
- }
- }
-
- protected void startListeningToResourceSet() {
- ResourceSet set = getResourceSet();
- if (set != null)
- set.eAdapters().add(getResourceSetListener());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.ISynchronizerExtender#projectChanged(org.eclipse.core.resources.IResourceDelta)
- */
- public void projectChanged(IResourceDelta delta) {
- // default nothing
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.ISynchronizerExtender#projectClosed()
- */
- public void projectClosed() {
- discardAllEditModels();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContextBase#createURIConverter(org.eclipse.wst.common.internal.emfworkbench.ProjectResourceSet)
- */
- protected WorkbenchURIConverter createURIConverter(ProjectResourceSet aResourceSet) {
- return new CompatibilityWorkbenchURIConverterImpl(getProject(), aResourceSet.getSynchronizer());
- }
-
- protected ProjectResourceSet createResourceSet() {
- if (project == null)
- throw new IllegalStateException("Attempt to create resource set with null project"); //$NON-NLS-1$
- return new ProjectResourceSetEditImpl(project);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContextBase#deleteFile(org.eclipse.emf.ecore.resource.Resource)
- */
- public void deleteFile(Resource resource) {
- try {
- WorkbenchResourceHelper.deleteResource(resource);
- } catch (CoreException ex) {
- Logger.getLogger().logError(ex);
- }
-
- }
-
- /**
- * @return Returns the defaultToMOF5Compatibility.
- */
- public boolean isDefaultToMOF5Compatibility() {
- return defaultToMOF5Compatibility;
- }
-
- /**
- * @param defaultToMOF5Compatibility
- * The defaultToMOF5Compatibility to set.
- */
- public void setDefaultToMOF5Compatibility(boolean defaultToMOF5Compatibility) {
- this.defaultToMOF5Compatibility = defaultToMOF5Compatibility;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchEditResourceHandler.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchEditResourceHandler.java
deleted file mode 100644
index 8bd107368..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EMFWorkbenchEditResourceHandler.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on May 25, 2004
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * @author vijayb
- *
- * TODO To change the template for this generated type comment go to Window - Preferences - Java -
- * Code Style - Code Templates
- */
-public class EMFWorkbenchEditResourceHandler extends NLS {
- private static final String BUNDLE_NAME = "emfworkbenchedit";//$NON-NLS-1$
-
- private EMFWorkbenchEditResourceHandler() {
- // Do not instantiate
- }
-
- public static String ClientAccessRegistryException_UI_1;
- public static String ClientAccessRegistryException_UI_0;
- public static String Snapshot_ERROR_0;
- public static String EditModelRegistry_ERROR_2;
- public static String EditModelRegistry_ERROR_1;
- public static String EditModelRegistry_ERROR_0;
- public static String AdapterFactoryDescriptor_ERROR_1;
- public static String AdapterFactoryDescriptor_ERROR_0;
- public static String DynamicAdapterFactory_ERROR_0;
- public static String ClientAccessRegistry_ERROR_1;
- public static String ClientAccessRegistry_ERROR_0;
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, EMFWorkbenchEditResourceHandler.class);
- }
-
- public static String getString(String key, Object[] args) {
- return NLS.bind(key, args);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EditModelLeastUsedCache.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EditModelLeastUsedCache.java
deleted file mode 100644
index 45590836c..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EditModelLeastUsedCache.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-
-/**
- * This class will be used to cache the recently used edit models. Loading and unloading of edit models can be
- * costly, especially if operations and/or post operations have a need to reload the same edit model repeatedly.
- * This will allow those repeatedly used edit models to be cached, thereby improving performance. By design, the
- * edit models load resources and these resources are stored in memory, so we don't want to cache every edit
- * model accessed, so this is a least used cache mechanism, where the max size is 10. If an edit model is used
- * it is put to the back of the stack, and new edit models accessed are put to the back of the stack, so that the
- * top of the stack is the first edit model disposed when the cache is higher than the threshhold.
- *
- */
-public class EditModelLeastUsedCache {
-
- /**
- * Provide a singleton instance.
- */
- private static EditModelLeastUsedCache INSTANCE = new EditModelLeastUsedCache();
-
- /**
- * The threshold, or most edit models we will keep open at a time is 10. This is low enough to not
- * overwhelm workbench memory and high enough to aid in operations which continually reload 3-4
- * edit models.
- */
- private final static int threshhold = 10;
-
- /**
- * A LHS is required to ensure the order of the items is maintained. Other
- * Set implementations (HashSet, TreeSet) do not preserve the order. This
- * is critical to the implementation. DO NOT CHANGE THIS.
- */
- private LinkedHashSet lru = new LinkedHashSet(threshhold);
-
- /**
- * Accessor for the EditModelLeastUsedCache INSTANCE
- *
- * @return the EditModelLeastUsedCache INSTANCE
- */
- public static EditModelLeastUsedCache getInstance() {
- return INSTANCE;
- }
-
- /**
- * Remove the all elements from the lru that are contained
- * in <code>aCollection</code>. This method assumes the
- * EditModels in the aCollection will be discarded and it
- * will not attempt to decrememt its reference count.
- * @param aCollection - A {@link Collection} of {@link EditModel}.
- */
- public void removeAllCached(Collection aCollection) {
- if (aCollection != null) {
- lru.removeAll(aCollection);
- }
- }
-
- /**
- * An {@link EditModel} is being accessed so we will want
- * to update the lru and access the editModel which will hold
- * a reference count.
- * @param editModel - The {@link EditModel} that we want to place
- * in the least used cache.
- */
- public void access(EditModel editModel) {
- boolean shouldAccess = true;
- synchronized (lru) {
- if (lru.contains(editModel)) {
- moveToEnd(editModel);
- shouldAccess = false;
- }
- }
- if (shouldAccess) {
- editModel.access(this);
- synchronized (lru) {
- lru.add(editModel);
- }
- }
- }
-
- /**
- * If we hit the capacity of the lru then remove the first one
- * and release access.
- */
- public void optimizeLRUSizeIfNecessary() {
- EditModel model = null;
- synchronized (lru) {
- if (lru.size() > threshhold) {
- // remove oldest element and release the edit model.
- Iterator iterator = lru.iterator();
- model = (EditModel) iterator.next();
- if (model != null) {
- lru.remove(model);
- }
- }
- }
- if (model != null)
- model.releaseAccess(this);
- }
-
- /**
- * Move the editModel to the end of the list
- * @param editModel -- EditModel to be moved
- */
- private void moveToEnd(EditModel editModel) {
- lru.remove(editModel);
- lru.add(editModel);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfPackagePropertyTester.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfPackagePropertyTester.java
deleted file mode 100644
index c68519975..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfPackagePropertyTester.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.emf.ecore.EObject;
-
-public class EmfPackagePropertyTester extends PropertyTester {
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if (receiver == null || !(receiver instanceof EObject) || expectedValue == null || !(expectedValue instanceof String))
- return false;
-
- EObject eObject = (EObject) receiver;
- String emfPackage = (String)expectedValue;
- return emfPackage.equals(eObject.eClass().getEPackage().getNsURI());
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfValidationHandler.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfValidationHandler.java
deleted file mode 100644
index 29f42c799..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/EmfValidationHandler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.wst.validation.internal.IValidationSelectionHandler;
-
-
-/**
- * Emf validation extension for valaditemenuaction
- */
-public class EmfValidationHandler implements IValidationSelectionHandler {
-
- private String validationType = null;
-
- /**
- * Default constructor
- */
- public EmfValidationHandler() {
- super();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#getBaseValidationType(java.lang.Object)
- */
- public IResource getBaseValidationType(Object selection) {
- if (selection instanceof EObject) {
- EObject eObject = (EObject) selection;
- Resource resource = eObject.eResource();
- IProject project = ProjectUtilities.getProject(resource);
- return project;
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#getValidationTypeString()
- */
- public String getValidationTypeString() {
- return validationType;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#setValidationTypeString(java.lang.String)
- */
- public void setValidationTypeString(String validationType) {
- this.validationType = validationType;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/PassthruResourceSet.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/PassthruResourceSet.java
deleted file mode 100644
index 71b536f55..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/PassthruResourceSet.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench;
-
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-
-/**
- * This ResourceSet is to be used by plugins that are currently loading to a cached ResourceSet that
- * always loads relative to the Workbench. This ResourceSet will direct the loads to the appropriate
- * Project ResourceSet. It will only load in this ResourceSet if it was unable to load via the
- * Workspace.
- *
- * If you set want to used this ResourceSet so that the loaded resources are isolated from everyone
- * else, you should use the
- *
- * @link PassthruResourceSet(IProject) constructor. This will load all resources locally and it will
- * not delegate to another ProjectResourceSet. This would be equivalent to creating a
- * ProjectResourceSet without setting any handlers.
- *
- */
-public class PassthruResourceSet extends ProjectResourceSetImpl {
- protected boolean isIsolated = false;
-
- public class PassthruResourcesEList extends ResourceSetImpl.ResourcesEList {
- public boolean add(Object object) {
- if (object == null)
- return false;
- ResourceSet set = WorkbenchResourceHelperBase.getResourceSet(((Resource) object).getURI());
- if (set != null)
- return set.getResources().add((Resource)object);
-
- return super.add(object);
- }
-
-
- public boolean addAll(Collection collection) {
- if (collection.isEmpty())
- return false;
- Iterator it = collection.iterator();
- Resource res;
- while (it.hasNext()) {
- res = (Resource) it.next();
- if (!WorkbenchResourceHelperBase.cacheResource(res))
- super.add(res);
- }
- return true;
- }
- }
-
- public PassthruResourceSet() {
- isIsolated = false;
- }
-
- /**
- * This constructor should only be used if you want to use this ResourceSet isolated from the
- * actual cached ProjectResourcSet for the passed IProject.
- */
- public PassthruResourceSet(IProject project) {
- setProject(project);
- isIsolated = true;
- }
-
- public boolean isIsolated() {
- return isIsolated;
- }
-
- public Resource createResource(URI uri) {
- Resource result = WorkbenchResourceHelperBase.getExistingOrCreateResource(uri);
- if (result == null)
- return super.createResource(uri);
- return result;
- }
-
- /**
- * @see org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#demandCreateResource(URI)
- */
- protected Resource demandCreateResource(URI uri) {
- Resource result = WorkbenchResourceHelperBase.createResource(uri);
- if (result == null)
- return super.createResource(uri); //We do want to call super.createResource and not
- // demandCreateResource
- return result;
- }
-
- /*
- * Javadoc copied from interface.
- */
- public EList getResources() {
- if (isIsolated)
- return super.getResources();
- if (resources == null) {
- resources = new PassthruResourcesEList();
- }
- return resources;
- }
-
- /**
- * @see org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl#createResourceFromHandlers(URI)
- */
- protected Resource createResourceFromHandlers(URI uri) {
- if (!isIsolated)
- return super.createResourceFromHandlers(uri);
- return null;
- }
-
- /**
- * @see org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl#getResourceFromHandlers(URI)
- */
- protected Resource getResourceFromHandlers(URI uri) {
- if (!isIsolated)
- return super.getResourceFromHandlers(uri);
- return null;
- }
-
- /**
- * @see com.ibm.etools.emf.workbench.ProjectResourceSetImpl#getEObjectFromHandlers(URI, boolean)
- */
- protected EObject getEObjectFromHandlers(URI uri, boolean loadOnDemand) {
- if (!isIsolated)
- return super.getEObjectFromHandlers(uri, loadOnDemand);
- return null;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java
deleted file mode 100644
index fd8d58737..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/WorkbenchResourceHelper.java
+++ /dev/null
@@ -1,531 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 3, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench;
-
-import java.io.OutputStream;
-import java.util.Map;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.jobs.ILock;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.common.util.WrappedException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-import org.eclipse.jem.util.emf.workbench.WorkbenchURIConverter;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.jem.util.plugin.JEMUtilPlugin;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedXMIFactoryImpl;
-import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class WorkbenchResourceHelper extends WorkbenchResourceHelperBase {
- protected static Class REFERENCED_RES_CLASS = ReferencedResource.class;
- private static boolean fileAdapterFactoryInitialized = false;
-
- private static class FileAdapterFactory extends AdapterFactoryImpl {
-
- public Adapter adaptNew(Notifier target, Object type) {
- FileAdapter adapter = new FileAdapter();
- adapter.setTarget(target);
- return adapter;
- }
-
- }
-
- /**
- * This class is internal and is used to store state on the resource, specifically, a cached
- * reference to the IFile
- */
- private static class FileAdapter extends AdapterImpl {
- public static final Object ADAPTER_KEY = FileAdapter.class.getName();
- private static final long delay = 30;
- private IFile file;
- private long synchronizationStamp;
- protected ResourceSet previousResourceSet;
- private ILock saveLock;
- public static final int FILE_NOT_LOADED = 0;
- public static final int FILE_INACCESSIBLE = -1;
-
- public boolean isAdapterForType(Object type) {
- return ADAPTER_KEY.equals(type);
- }
-
- /*
- * Update the synchronization stamp where appropriate
- */
- public void notifyChanged(Notification msg) {
- switch (msg.getFeatureID(null)) {
- case Resource.RESOURCE__IS_LOADED :
- if (getResource().isLoaded())
- handleLoaded();
- else
- handleUnloaded();
- break;
- case ReferencedResource.RESOURCE_ABOUT_TO_SAVE:
- handleAboutToSave();
- break;
- case ReferencedResource.RESOURCE_WAS_SAVED:
- handleSaved();
- break;
- case ReferencedResource.RESOURCE_SAVE_FAILED:
- handleSaveFailed();
- break;
- case Resource.RESOURCE__URI :
- handleURIChanged();
- }
- }
-
- private void handleSaveFailed() {
- releaseSaveLock();
-
- }
-
- private void handleAboutToSave() {
- aquireSaveLock();
- }
-
- private void aquireSaveLock() {
-// System.out.println("FileName: " + getFile().getName() + " " +getFile());
-// System.out.println("aquiredSaveLock: " + Thread.currentThread().getName());
-// System.out.println("Depth" + getSaveLock().getDepth());
-// System.out.println("Instance:"+getSaveLock().hashCode());
-// new Exception().printStackTrace(System.out);
- getSaveLock().acquire();
-
- }
-
- private boolean aquireSaveLock(long delay) throws InterruptedException {
-// System.out.println("FileName: " + getFile().getName() + " " +getFile());
-// System.out.println("aquiredSaveLock with delay: " + Thread.currentThread().getName());
-// System.out.println("Depth" + getSaveLock().getDepth());
-// System.out.println("Instance:"+getSaveLock().hashCode());
-// new Exception().printStackTrace(System.out);
-
- return getSaveLock().acquire(delay);
-
- }
-
- private void releaseSaveLock() {
-// System.out.println("FileName: " + getFile().getName() + " " +getFile());
-// System.out.println("releasedSaveLock: " + Thread.currentThread().getName());
-// System.out.println("Depth" + getSaveLock().getDepth());
-// System.out.println("Instance:"+getSaveLock().hashCode());
-// new Exception().printStackTrace(System.out);
- getSaveLock().release();
-
- }
-
- private ILock getSaveLock() {
- if (saveLock == null)
- saveLock = Platform.getJobManager().newLock();
- return saveLock;
- }
-
- /**
- *
- */
- private void handleURIChanged() {
- file = null;
- synchronizationStamp = FILE_NOT_LOADED;
- }
-
- public IFile getFile() {
- //First test to see if we should reset the file.
- if (file != null && (!file.isAccessible() || previousResourceSet != getResourceSet())) {
- file = null;
- synchronizationStamp = FILE_NOT_LOADED;
- }
- if (file == null) {
- if (isPlatformResourceURI(getURI())) {
- file = getPlatformFile(getURI());
- } else {
- //we should not be here anymore.
- file = internalGetFile(getResource());
- }
- if(null!= file && !file.isAccessible()){
- synchronizationStamp = FILE_INACCESSIBLE;
- }
- previousResourceSet = getResourceSet();
- }
- return file;
- }
-
- /**
- * @return
- */
- public long getSynchronizationStamp() {
- return synchronizationStamp;
- }
-
- /**
- * @param file
- */
- public void setFile(IFile file) {
- this.file = file;
- }
-
- /**
- * @param l
- */
- public void setSynchronizationStamp(long l) {
- synchronizationStamp = l;
- }
-
- /**
- * @see ReferencedResource#isConsistent()
- */
- public boolean isConsistent() {
- //This checks for the case where the resource hasn't finished saving fo the first time
- if(!getResource().isLoaded())
- return true;
- boolean hasLocked = false;
- try {
- hasLocked = aquireSaveLock(delay);
- } catch (InterruptedException e) {
- Logger.getLogger().write(e);
- }
- boolean result = false;
- try {
-
- if (getFile() == null || !getFile().isAccessible())
- result = true;
- else {
- if (!getFile().isSynchronized(IFile.DEPTH_ZERO))
- result = false;
- else {
- result = synchronizationStamp == computeModificationStamp(getFile());
- }
- }
- } catch (Exception e) {
- Logger.getLogger().write(e);
- } finally {
- if (hasLocked)
- releaseSaveLock();
- }
- return result;
- }
-
- public void cacheSynchronizationStamp() {
- setSynchronizationStamp(computeModificationStamp(getFile()));
- }
-
- public ReferencedResource getResource() {
- return (ReferencedResource) target;
- }
-
- public URI getURI() {
- return target == null ? null : getResource().getURI();
- }
-
- public ResourceSet getResourceSet() {
- return target == null ? null : getResource().getResourceSet();
- }
-
- public void handleUnloaded() {
- file = null;
- synchronizationStamp = FILE_NOT_LOADED;
- }
-
- public void handleLoaded() {
- cacheSynchronizationStamp();
- }
-
- public void handleSaved() {
- cacheSynchronizationStamp();
- releaseSaveLock();
- }
- }
-
- /**
- * This is an internal method to be used by the plugin only
- */
- public static synchronized void initializeFileAdapterFactory() {
- if (!fileAdapterFactoryInitialized) {
- ReferencedXMIFactoryImpl.addGlobalAdapterFactory(new FileAdapterFactory());
- fileAdapterFactoryInitialized = true;
- }
- }
-
-
- private static FileAdapter getFileAdapter(ReferencedResource res) {
- FileAdapter adapter = (FileAdapter) EcoreUtil.getExistingAdapter(res, FileAdapter.ADAPTER_KEY);
- return adapter == null ? createFileAdapter(res) : adapter;
- }
-
- private static FileAdapter createFileAdapter(ReferencedResource res) {
- FileAdapter adapter = new FileAdapter();
- adapter.setTarget(res);
- res.eAdapters().add(adapter);
- return adapter;
- }
-
- /**
- * Return the underlying IFile for the resource if one exists. This may return null if the
- * resource does not belong to a ProjectResourceSet.
- */
- public static IFile getFile(ReferencedResource res) {
- FileAdapter adapter = getFileAdapter(res);
- return adapter == null ? null : adapter.getFile();
- }
-
- public static long getSynchronizationStamp(ReferencedResource res) {
- FileAdapter adapter = getFileAdapter(res);
- return adapter == null ? FileAdapter.FILE_NOT_LOADED : adapter.getSynchronizationStamp();
- }
-
- public static void setSynhronizationStamp(ReferencedResource res, long stamp) {
- FileAdapter adapter = getFileAdapter(res);
- if (adapter != null)
- adapter.setSynchronizationStamp(stamp);
- }
-
- public static boolean isConsistent(ReferencedResource res) {
- FileAdapter adapter = getFileAdapter(res);
- return adapter != null && adapter.isConsistent();
- }
-
- /**
- * Method cacheSynchronizationStamp.
- *
- * @param r
- */
- public static void cacheSynchronizationStamp(ReferencedResource refResource) {
- if (refResource != null) {
- FileAdapter adapter = getFileAdapter(refResource);
- if (adapter != null && adapter.getSynchronizationStamp() <= FileAdapter.FILE_NOT_LOADED)
- adapter.setSynchronizationStamp(computeModificationStamp(refResource));
- }
- }
-
- public static boolean isReferencedResource(Resource aResource) {
- return REFERENCED_RES_CLASS.isInstance(aResource);
- }
-
- public static long computeModificationStamp(ReferencedResource resource) {
- FileAdapter adapter = getFileAdapter(resource);
- return adapter == null ? FileAdapter.FILE_NOT_LOADED : computeModificationStamp(adapter.getFile());
- }
-
- public static long computeModificationStamp(IFile file) {
- if (file == null)
- return FileAdapter.FILE_NOT_LOADED;
- if(!file.isAccessible()){
- return FileAdapter.FILE_INACCESSIBLE;
- }
- long currentStamp = file.getModificationStamp();
- IPath path = file.getLocation();
- if (path != null)
- return path.toFile().lastModified();
- return currentStamp;
- }
-
- /**
- * Return the IFile that currently corresponds to <code>aResource</code>.
- */
- public static IFile getFile(Resource aResource) {
- if (aResource != null) {
- if (isReferencedResource(aResource))
- return getFile((ReferencedResource) aResource);
- return internalGetFile(aResource);
- }
- return null;
- }
-
- public static IFile getFile(EObject obj) {
- if (obj == null)
- return null;
-
- Resource mofResource = obj.eResource();
- if (mofResource == null)
- return null;
- return getFile(mofResource);
- }
-
- /**
- * Get or load a cached Resource or create one if it is not found. A WrappedException will only
- * be thrown if the corresponding file exists but it failed to load.
- */
- public static Resource getOrCreateResource(URI uri, ResourceSet set) throws WrappedException {
- try {
- return set.getResource(uri, true); //this will create the resource no matter what
- } catch (WrappedException e) {
- if (ExtendedEcoreUtil.getFileNotFoundDetector().isFileNotFound(e))
- return set.getResource(uri, false);
- throw e;
- }
- }
-
- protected static boolean isSameProject(Resource resourceA, Resource resourceB) {
- IProject pA, pB;
- pA = getProject(resourceA);
- pB = getProject(resourceB);
- if (pA != null && pB != null)
- return pA.equals(pB);
- //otherwise we do not have enough info to determine false so we must return true
- return true;
- }
-
- public static IProject getProject(Resource res) {
- IProject proj = getProject(res.getResourceSet());
- if (proj == null) {
- IFile file = getFile(res);
- if (file != null)
- proj = file.getProject();
- }
- return proj;
- }
-
- /*
- * This method should not be called by clients. It is used internally by clients that also call
- * getFile(...). This is to avoid endless loops.
- *
- * @see getFile(Resource)
- */
- protected static IFile internalGetFile(Resource aResource) {
- if (aResource != null)
- return getFile(aResource.getResourceSet(), aResource.getURI());
-
- return null;
- }
-
- protected static IFile getFile(ResourceSet set, URI uri) {
- IFile file = getPlatformFile(uri);
- if (file == null) {
- if (set != null) {
- URIConverter converter = set.getURIConverter();
- URI convertedUri = converter.normalize(uri);
- if (!uri.equals(convertedUri))
- return getPlatformFile(convertedUri);
- }
- }
- return file;
- }
-
- /**
- * Return the IFile for the <code>uri</code> within the Workspace. This URI is assumed to be
- * absolute in the following format: platform:/resource/....
- */
- public static IFile getPlatformFile(URI uri) {
- if (isPlatformResourceURI(uri)) {
- String fileString = URI.decode(uri.path());
- fileString = fileString.substring(JEMUtilPlugin.PLATFORM_RESOURCE.length() + 1);
- return getWorkspace().getRoot().getFile(new Path(fileString));
- }
- return null;
- }
-
-
-
- public static IFile getFile(IProject project, URI uri) {
- ResourceSet set = getResourceSet(project);
- return getFile(set, uri);
- }
-
- /**
- * This should only be used if you want to save <code>aResource</code> within the IProject
- * that it is currently residing but you do not want to save it in the default output location.
- * You should not use this api to save a Resource to an existing file.
- *
- * @deprecated This api is no longer required. You should create a resource with the absolute
- * path (platform:/resource/...). Upon save, the file will be saved to this
- * location.
- */
- public static boolean saveResourceToFile(Resource aResource, IFile aFile) throws Exception {
- return saveResourceToFile(aResource, aFile, null);
- }
-
- /**
- * This should only be used if you want to save <code>aResource</code> within the IProject
- * that it is currently residing but you do not want to save it in the default output location.
- * You should not use this api to save a Resource to an existing file.
- *
- * @deprecated This api is no longer required. You should create a resource with the absolute
- * path (platform:/resource/...). Upon save, the file will be saved to this
- * location.
- */
- public static boolean saveResourceToFile(Resource aResource, IFile aFile, Map saveOptions) throws Exception {
- if (aResource != null && aFile != null && !aFile.exists()) {
- ResourceSet set = aResource.getResourceSet();
- if (set != null) {
- URIConverter conv = set.getURIConverter();
- if (conv != null && conv instanceof WorkbenchURIConverter) {
- WorkbenchURIConverter wbConv = (WorkbenchURIConverter) conv;
- String uri = aResource.getURI().toString();
- IPath resPath, filePath;
- resPath = new Path(uri);
- filePath = aFile.getProjectRelativePath();
- int resCount, fileCount;
- resCount = resPath.segmentCount();
- fileCount = filePath.segmentCount();
- if (resCount <= fileCount) {
- filePath = filePath.removeFirstSegments(fileCount - resCount);
- if (resPath.equals(filePath)) {
- OutputStream os = wbConv.createOutputStream(URI.createPlatformResourceURI(aFile.toString()));
- if (os != null) {
- try {
- aResource.save(os, saveOptions);
- } finally {
- os.close();
- }
- return true;
- }
- }
- }
- }
- }
- }
- return false;
- }
-
- protected static void deleteFile(IFile aFile) throws CoreException {
- if (aFile != null && aFile.exists())
- aFile.delete(true, null);
- }
-
- /**
- * Delete
- *
- * @aResource in the Workbench.
- */
- public static void deleteResource(Resource aResource) throws CoreException {
- if (aResource != null)
- deleteFile(getFile(aResource));
- }
-
-
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryDescriptor.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryDescriptor.java
deleted file mode 100644
index bf2c38c64..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryDescriptor.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Feb 26, 2004
- *
- * To change the template for this generated file go to Window&gt;Preferences&gt;Java&gt;Code
- * Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.jem.util.plugin.JEMUtilPlugin;
-import org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor;
-import org.eclipse.wst.common.internal.emf.utilities.Assert;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-
-
-public class AdapterFactoryDescriptor extends AbstractRegistryDescriptor implements Comparable {
-
- private String packageURI = null;
- private String id = null;
- private Set viewIDs = null;
- private final int loadOrder;
- private static int loadOrderCounter = 0;
-
- public AdapterFactoryDescriptor(IConfigurationElement element) {
- super(element);
-
- packageURI = element.getAttribute(AdapterFactoryRegistry.PACKAGE_URI);
- id = element.getAttribute(AdapterFactoryRegistry.ID);
- Assert.isNotNull(packageURI, EMFWorkbenchEditResourceHandler.AdapterFactoryDescriptor_ERROR_0);
- Assert.isNotNull(id, EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.AdapterFactoryDescriptor_ERROR_1, new Object[]{element.getDeclaringExtension().getNamespace()}));
-
- readViewIDs();
- this.loadOrder = loadOrderCounter++;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("AdapterFactoryDescriptor"); //$NON-NLS-1$
- sb.append('[');
- sb.append(packageURI);
- sb.append(",p"); //$NON-NLS-1$
- sb.append(getPriority());
- if (viewIDs != null && !viewIDs.isEmpty()) {
- sb.append(':');
- boolean first = true;
- Iterator iter = viewIDs.iterator();
- while (iter.hasNext()) {
- if (!first)
- sb.append(',');
- first = false;
- sb.append(iter.next());
- }
- }
- sb.append(']');
- return sb.toString();
- }
-
- private void readViewIDs() {
- viewIDs = new HashSet(3);
- IConfigurationElement[] children = element.getChildren(AdapterFactoryRegistry.VIEW);
- if (children == null || children.length == 0)
- return;
-
- String viewID = null;
- for (int i = 0; i < children.length; i++) {
- viewID = children[i].getAttribute(AdapterFactoryRegistry.ID);
- if (viewID != null)
- viewIDs.add(viewID);
- }
- }
-
- public AdapterFactory createInstance() {
- if (element == null)
- return null;
-
- AdapterFactory factory = null;
- try {
- factory = (AdapterFactory) element.createExecutableExtension(AdapterFactoryRegistry.CLASS_NAME);
- } catch (CoreException e) {
- JEMUtilPlugin.getLogger().logError(e);
- factory = null;
- }
- return factory;
- }
-
-
- public String getPackageURI() {
- return packageURI;
- }
-
- public Set getViewIDs() {
- return viewIDs;
- }
-
- public boolean appliesTo(String viewID) {
- return viewIDs.isEmpty() || viewIDs.contains(viewID);
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object o) {
- if (this == o)
- return 0;
- if (!(o instanceof AdapterFactoryDescriptor))
- return 1;
- AdapterFactoryDescriptor desc = (AdapterFactoryDescriptor) o;
-
- int pCompare = getPriority() - desc.getPriority();
- if (pCompare != 0)
- //We have reverse the sorting of the priority for the adapter factories
- return -pCompare;
-
- //The group is the same - in this case the one for a specific view has precedence over
- //a generic one
- else if (viewIDs != null && !viewIDs.isEmpty())
- return -1;
- else
- return 1;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor#getID()
- */
- public String getID() {
- return id;
- }
-
-
- /**
- * @return Returns the loadOrder.
- */
- public int getLoadOrder() {
- return loadOrder;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryRegistry.java
deleted file mode 100644
index e98696291..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/AdapterFactoryRegistry.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeSet;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.jem.util.RegistryReader;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin;
-
-/**
- * @author mdelder
- */
-public class AdapterFactoryRegistry extends RegistryReader {
-
- public static final String ADAPTER_FACTORY = "adapterFactory"; //$NON-NLS-1$
-
- public static final String PACKAGE_URI = "packageURI"; //$NON-NLS-1$
-
- public static final String CLASS_NAME = "className"; //$NON-NLS-1$
-
- public static final String VIEW = "view"; //$NON-NLS-1$
-
- public static final String ID = "id"; //$NON-NLS-1$
-
- private Map descriptorMap = null;
-
- private static AdapterFactoryRegistry instance;
-
- private AdapterFactoryRegistry() {
- super(EMFWorkbenchEditPlugin.ID, EMFWorkbenchEditPlugin.ADAPTER_FACTORY_REGISTRY_EXTENSION_POINT);
- }
-
- public List getDescriptors(EPackage pkg, String viewID) {
- Collection all = getDescriptors(pkg);
- if (all == null)
- return null;
-
- Iterator iter = all.iterator();
- AdapterFactoryDescriptor desc = null;
- List result = new ArrayList(all.size());
- while (iter.hasNext()) {
- desc = (AdapterFactoryDescriptor) iter.next();
- if (desc.appliesTo(viewID))
- result.add(desc);
- }
- return result;
- }
-
- public Collection getDescriptors(EPackage registeredPackage) {
- return (Collection) getDescriptorMap().get(registeredPackage.getNsURI());
- }
-
- private Map getDescriptorMap() {
- if (descriptorMap == null)
- descriptorMap = new HashMap();
- return descriptorMap;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
- */
- public boolean readElement(IConfigurationElement element) {
- try {
- if (element.getName().equals(ADAPTER_FACTORY)) {
- AdapterFactoryDescriptor descriptor = new AdapterFactoryDescriptor(element);
- mapDescriptor(descriptor);
- return true;
- }
- } catch (RuntimeException re) {
- Logger.getLogger().logError(re);
- }
- return false;
- }
-
- private void mapDescriptor(AdapterFactoryDescriptor descriptor) {
- String uri = descriptor.getPackageURI();
- Collection descriptors = (Collection) getDescriptorMap().get(uri);
- if (descriptors == null) {
- descriptors = new TreeSet();
- getDescriptorMap().put(uri, descriptors);
- }
- descriptors.add(descriptor);
- }
-
- /**
- * @return Returns the instance.
- */
- public static AdapterFactoryRegistry instance() {
- if (instance == null) {
- instance = new AdapterFactoryRegistry();
- instance.readRegistry();
- }
- return instance;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ChildCommand.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ChildCommand.java
deleted file mode 100644
index 6dec40e44..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ChildCommand.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.wst.common.internal.emfworkbench.integration.AbstractEditModelCommand;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelCommand;
-
-/**
- * Insert the type's description here. Creation date: (05/22/01 8:57:56 AM)
- *
- * @author: Administrator
- */
-public class ChildCommand extends EditModelCommand {
- private ParentCommand parent;
- private EditModelRetriever modelRetriever;
-
- public ChildCommand(ParentCommand parentCmd, Command targetCmd, EditModelRetriever retriever) {
- super(targetCmd);
- parent = parentCmd;
- modelRetriever = retriever;
- }
-
- public boolean canExecute() {
- return true;
- }
-
- /**
- * Does nothing
- */
- public void execute() {
- //does nothing
- }
-
- protected void executeInModel(AbstractEditModelCommand cmd) {
- EditModel model = modelRetriever.getEditModelForWrite(this);
- try {
- model.getCommandStack().execute(cmd);
- model.saveIfNecessary(this);
- } finally {
- model.releaseAccess(this);
- }
- }
-
- /**
- * Insert the method's description here. Creation date: (05/22/01 9:35:36 AM)
- *
- * @return java.lang.Object
- */
- public java.lang.Object getEditModelKey() {
- return modelRetriever.getEditModelID();
- }
-
- /**
- * Insert the method's description here. Creation date: (05/22/01 9:35:36 AM)
- *
- * @return com.ibm.etools.j2ee.workbench.ParentCommand
- */
- public ParentCommand getParent() {
- return parent;
- }
-
- public void redo() {
- redoInModel();
- getParent().redoFrom(this);
- }
-
- protected void redoInModel() {
- EditModel model = modelRetriever.getEditModelForWrite(this);
- try {
- getTarget().redo();
- model.saveIfNecessary(this);
- } finally {
- model.releaseAccess(this);
- }
- }
-
- public void undo() {
- undoInModel();
- getParent().undoFrom(this);
- }
-
- protected void undoInModel() {
- EditModel model = modelRetriever.getEditModelForWrite(this);
- try {
- getTarget().undo();
- model.saveIfNecessary(this);
- } finally {
- model.releaseAccess(this);
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistry.java
deleted file mode 100644
index 9fae4644f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistry.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Oct 6, 2003
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import org.eclipse.jem.internal.util.emf.workbench.nls.EMFWorkbenchResourceHandler;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-
-/**
- * @author mdelder
- */
-public class ClientAccessRegistry {
-
- protected final WeakHashMap registry = new WeakHashMap();
- protected final Set baseSet = new HashSet();
-
- public synchronized void access(Object accessorKey) {
- if (isStable()) {
- if (!registry.containsKey(accessorKey)) {
- Snapshot snapshot = new Snapshot();
- this.registry.put(accessorKey, snapshot);
- this.baseSet.add(snapshot);
-
- } else
- throw new ClientAccessRegistryException(EMFWorkbenchEditResourceHandler.ClientAccessRegistry_ERROR_0, accessorKey);
-
- } else
- complain();
- }
-
- public synchronized void release(Object accessorKey) {
-
- /*
- * Error condition: Some one has been naughty and not released the resource
- */
- if (this.registry.containsKey(accessorKey) && isStable()) {
- Snapshot snapshot = (Snapshot) this.registry.remove(accessorKey);
- this.baseSet.remove(snapshot);
- } else
- complain(accessorKey);
- }
-
- public synchronized void assertAccess(Object accessorKey) {
- if (!isClientAccessing(accessorKey))
- throw new ClientAccessRegistryException(EMFWorkbenchResourceHandler.getString("ClientAccessRegistry_ERROR_1"), accessorKey); //$NON-NLS-1$
- }
-
- public synchronized boolean isClientAccessing(Object client) {
- boolean result = this.registry.containsKey(client);
- if (!isStable())
- complain();
- return result;
- }
-
- public synchronized boolean isAnyClientAccessing() {
- boolean result = this.registry.size() > 0;
- if (!isStable())
- complain();
- return result;
- }
-
- public synchronized boolean isStable() {
- return this.baseSet.size() == this.registry.size();
- }
-
- public void complain() {
- complain(null);
- }
-
- public void complain(Object accessorKey) {
- if (!isStable())
- throw new ClientAccessRegistryException(this.registry, this.baseSet);
- throw new ClientAccessRegistryException(EMFWorkbenchResourceHandler.getString("ClientAccessRegistry_ERROR_1"), accessorKey); //$NON-NLS-1$
- }
-
- public String toString() {
- StringBuffer result = new StringBuffer("ClientAccessRegistry: ["); //$NON-NLS-1$
- result.append((isStable()) ? "STABLE" : "OUT OF SYNC"); //$NON-NLS-1$ //$NON-NLS-2$
- result.append("]: Reference Count = "); //$NON-NLS-1$
- result.append(this.size());
- return result.toString();
- }
-
- public synchronized int size() {
- return this.registry.size();
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistryException.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistryException.java
deleted file mode 100644
index a49c8a06b..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ClientAccessRegistryException.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Oct 2, 2003
- *
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-
-
-/**
- * The ClientAccessRegistryException accepts a WeakHashSet registry and a Set of all Snapshots that
- * should be contained in the registry. It will perform the necessary set difference in order to
- * determine which Snapshots exist in the baseSet but not in the registry.
- *
- * @author mdelder
- */
-public class ClientAccessRegistryException extends RuntimeException {
-
- public static final int UNKNOWN = 0;
- public static final int DANGLING_REFERENCE = 1;
- public static final int INVALID_ACCESS_KEY = 2;
- private WeakHashMap registry = null;
- private Set baseSet = null;
- private boolean processed = false;
- private int type = UNKNOWN;
-
- public ClientAccessRegistryException(WeakHashMap registry, Set baseSet) {
- this.registry = registry;
- this.baseSet = new HashSet();
- this.baseSet.addAll(baseSet);
- this.type = DANGLING_REFERENCE;
- }
-
- public ClientAccessRegistryException(String msg, Object key) {
- super(msg + " : " + key); //$NON-NLS-1$
- this.type = INVALID_ACCESS_KEY;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
- */
- public void printStackTrace(PrintStream s) {
-
- s.println(toString());
- super.printStackTrace(s);
-
- if (this.registry != null) {
- Snapshot snapshot = null;
- if (!processed) {
- Object key = null;
- Iterator keyIterator = this.registry.keySet().iterator();
- while (keyIterator.hasNext()) {
- key = keyIterator.next();
- snapshot = (Snapshot) this.registry.get(key);
- this.baseSet.remove(snapshot);
- }
- processed = true;
- }
- s.println(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.ClientAccessRegistryException_UI_0, new Object[]{new Integer(baseSet.size()).toString()}));
-
- for (Iterator possibleCulpritsItr = baseSet.iterator(); possibleCulpritsItr.hasNext();) {
- snapshot = (Snapshot) possibleCulpritsItr.next();
- snapshot.printStackTrace(s);
- }
-
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
- */
- public void printStackTrace(PrintWriter s) {
-
- s.println(toString());
- super.printStackTrace(s);
- if (this.registry != null) {
- Snapshot snapshot = null;
- if (!processed) {
- Object key = null;
- Iterator keyIterator = this.registry.keySet().iterator();
- while (keyIterator.hasNext()) {
- key = keyIterator.next();
- snapshot = (Snapshot) this.registry.get(key);
- this.baseSet.remove(snapshot);
- }
- processed = true;
- }
- s.println(EMFWorkbenchEditResourceHandler.getString("", new Object[]{new Integer(baseSet.size()).toString()})); //$NON-NLS-1$
-
- for (Iterator possibleCulpritsItr = baseSet.iterator(); possibleCulpritsItr.hasNext();) {
- snapshot = (Snapshot) possibleCulpritsItr.next();
- snapshot.printStackTrace(s);
- }
-
- }
- }
-
- public String getType() {
- switch (type) {
- case DANGLING_REFERENCE :
- return "DANGLING_REFERENCE"; //$NON-NLS-1$
- case INVALID_ACCESS_KEY :
- return "INVALID_ACCESS_KEY"; //$NON-NLS-1$
- default :
- return "UNKNOWN"; //$NON-NLS-1$
- }
- }
-
- public String toString() {
- StringBuffer result = new StringBuffer(super.toString()).append("\r\n"); //$NON-NLS-1$
- result.append(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.ClientAccessRegistryException_UI_1, new Object[]{getType()}));
- // if (this.badReferenceLocation != null) {
- // result.append("The invalid access occurred somewhere in the following stack
- // trace.").append("\n");
- // result.append(this.badReferenceLocation.getStackTraceString());
- // }
- return result.toString();
- }
-
- public static void main(String[] args) {
- System.out.println(new ClientAccessRegistryException("test message", "-somekeyobj-").toString()); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("LINEBREAK"); //$NON-NLS-1$
- System.out.println(new ClientAccessRegistryException(new WeakHashMap(), new HashSet()).toString());
- System.out.println("LINEBREAK"); //$NON-NLS-1$
- new ClientAccessRegistryException("test message", "-somekeyobj-").printStackTrace(); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println("LINEBREAK"); //$NON-NLS-1$
- new ClientAccessRegistryException(new WeakHashMap(), new HashSet()).printStackTrace();
-
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EMFWorkbenchEditContextFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EMFWorkbenchEditContextFactory.java
deleted file mode 100644
index 41108734f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EMFWorkbenchEditContextFactory.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 3, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.eclipse.core.internal.jobs.LockManager;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.jobs.ILock;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jem.internal.util.emf.workbench.EMFWorkbenchContextFactory;
-import org.eclipse.jem.util.emf.workbench.EMFWorkbenchContextBase;
-import org.eclipse.jem.util.emf.workbench.IEMFContextContributor;
-import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-import org.eclipse.wst.common.internal.emfworkbench.integration.ResourceSetWorkbenchEditSynchronizer;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class EMFWorkbenchEditContextFactory extends EMFWorkbenchContextFactory {
-
-
- /**
- *
- */
- public EMFWorkbenchEditContextFactory() {
- super();
- }
-
- protected EMFWorkbenchContextBase primCreateEMFContext(IProject aProject) {
- return new EMFWorkbenchContext(aProject);
- }
-
- public ResourceSetWorkbenchSynchronizer createSynchronizer(ResourceSet aResourceSet, IProject aProject) {
- return new ResourceSetWorkbenchEditSynchronizer(aResourceSet, aProject);
- }
-
- protected static LockManager lockManager = new LockManager();
- protected static Map projectLocks = new Hashtable();
-
- public static ILock getProjectLockObject(IProject aProject){
- if(null == aProject){
- return null;
- }
- Integer hashCode = new Integer(aProject.hashCode());
- synchronized (projectLocks) {
- ILock lock = (ILock)projectLocks.get(hashCode);
- if(lock == null){
- lock = lockManager.newLock();
- projectLocks.put(hashCode, lock);
- }
- return lock;
- }
- }
-
- public EMFWorkbenchContextBase createEMFContext(IProject aProject, IEMFContextContributor contributor) {
- ILock lock = getProjectLockObject(aProject);
- try{
- if(null != lock){
- lock.acquire();
- }
- return super.createEMFContext(aProject, contributor);
- } finally{
- if(null != lock){
- lock.release();
- }
- }
- }
-
- protected EMFWorkbenchContextBase getCachedEMFContext(IProject aProject) {
- ILock lock = getProjectLockObject(aProject);
- try{
- if(null != lock){
- lock.acquire();
- }
- return super.getCachedEMFContext(aProject);
- } finally{
- if(null != lock){
- lock.release();
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtension.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtension.java
deleted file mode 100644
index 6041defe8..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtension.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Feb 18, 2004
- *
- * To change the template for this generated file go to Window&gt;Preferences&gt;Java&gt;Code
- * Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.frameworks.internal.ConfigurationElementWrapper;
-
-
-public class EditModelExtension extends ConfigurationElementWrapper {
- public static final String ID_ATTR = "id"; //$NON-NLS-1$
-
- private String editModelID = null;
- private Collection resources = null;
- private String id = null;
-
-
- public EditModelExtension(IConfigurationElement element) {
- super(element);
- init();
- }
-
- private void init() {
- id = element.getAttribute(ID_ATTR);
- if (id == null) {
- Logger.getLogger().logError("Incorrect usage of editModelExtension extension point. Element must contain id attribute. Plugin: " + getPluginId()); //$NON-NLS-1$
- return;
- }
-
- editModelID = element.getAttribute(EditModelExtensionRegistry.EDIT_MODEL_ID_ATTR);
- resources = new ArrayList();
- IConfigurationElement[] editModelResources = element.getChildren(EditModelResource.EDIT_MODEL_RESOURCE_ELEMENT);
- for (int j = 0; j < editModelResources.length; j++)
- resources.add(new EditModelResource(editModelResources[j], id));
- }
-
- /**
- * @return
- */
- public String getEditModelID() {
- return editModelID;
- }
-
-
- /**
- * @return
- */
- public Collection getResources() {
- return resources;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtensionRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtensionRegistry.java
deleted file mode 100644
index 47bc51b0f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelExtensionRegistry.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.jem.util.RegistryReader;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin;
-
-
-/**
- * @author mdelder
- */
-class EditModelExtensionRegistry extends RegistryReader {
-
- private static EditModelExtensionRegistry INSTANCE = null;
-
- public static final String EDIT_MODEL_EXT_ELEMENT = "editModelExtension"; //$NON-NLS-1$
- public static final String EDIT_MODEL_ID_ATTR = "editModelID"; //$NON-NLS-1$
- public static final String GROUP_ID_ATTR = "functionGroupID"; //$NON-NLS-1$
-
-
- private Map extensions = null;
-
- protected EditModelExtensionRegistry() {
- super(EMFWorkbenchEditPlugin.ID, EMFWorkbenchEditPlugin.EDIT_MODEL_EXTENSION_REGISTRY_EXTENSION_POINT);
- }
-
- public static EditModelExtensionRegistry getInstance() {
- if (INSTANCE == null) {
- INSTANCE = new EditModelExtensionRegistry();
- INSTANCE.readRegistry();
- }
- return INSTANCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
- */
- public boolean readElement(IConfigurationElement element) {
-
- boolean result = false;
- Collection extensionsByID = null;
- EditModelExtension editModelExtension = null;
- if (element.getName().equals(EDIT_MODEL_EXT_ELEMENT)) {
- editModelExtension = new EditModelExtension(element);
- extensionsByID = (Collection) getExtensions().get(editModelExtension.getEditModelID());
- if (extensionsByID == null) {
- extensionsByID = new ArrayList();
- getExtensions().put(editModelExtension.getEditModelID(), extensionsByID);
- }
- extensionsByID.add(editModelExtension);
- result = true;
- }
- return result;
- }
-
- protected Map getExtensions() {
- if (extensions == null)
- extensions = new HashMap();
- return extensions;
- }
-
- /**
- * @return
- */
- public Collection getEditModelResources(Object editModelID) {
- //TODO - Cache the resources
- Collection editModelResources = new ArrayList();
- Collection editModelExtensions = (Collection) getExtensions().get(editModelID);
-
- if (editModelExtensions == null || editModelExtensions.size() == 0)
- return Collections.EMPTY_LIST;
- Iterator itr = editModelExtensions.iterator();
- while (itr.hasNext()) {
- EditModelExtension ext = (EditModelExtension) itr.next();
- editModelResources.addAll(ext.getResources());
- }
- return (!editModelExtensions.isEmpty()) ? editModelResources : Collections.EMPTY_LIST;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java
deleted file mode 100644
index 0733b3260..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRegistry.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeSet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.jem.util.RegistryReader;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EMFWorkbenchEditPlugin;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-import org.eclipse.wst.common.internal.emfworkbench.integration.IEditModelFactory;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-
-/**
- * @author mdelder
- */
-public class EditModelRegistry extends RegistryReader {
-
- private final static EditModelRegistry INSTANCE = new EditModelRegistry();
-
- private final Map factoryConfigurations = new HashMap();
- private static boolean initialized = false;
-
-
- public static final String EDIT_MODEL_ELEMENT = "editModel"; //$NON-NLS-1$
- public static final String EDIT_MODEL_RESOURCE_EXTENSION = "resourceExtension"; //$NON-NLS-1$
- public static final String EDIT_MODEL_RESOURCE_EXTENSION_NAME = "name"; //$NON-NLS-1$
- public static final String EDIT_MODEL_ID_ATTR = "editModelID"; //$NON-NLS-1$
- public static final String FACTORY_CLASS_ATTR = "factoryClass"; //$NON-NLS-1$
- public static final String PARENT_MODEL_ATTR = "parentModelID"; //$NON-NLS-1$
-
-
-
- public static final String LOAD_UNKNOWN_RESOURCES_ATTR = "loadUnknownResourcesAsReadOnly"; //$NON-NLS-1$
-
- protected EditModelRegistry() {
- super(EMFWorkbenchEditPlugin.ID, EMFWorkbenchEditPlugin.EDIT_MODEL_FACTORIES_EXTENSION_POINT);
- }
-
- public static EditModelRegistry getInstance() {
- if(isInitialized())
- return INSTANCE;
- synchronized(INSTANCE) {
- if(!isInitialized()) {
- INSTANCE.readRegistry();
- initialized = true;
- }
- }
- return INSTANCE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
- */
- public boolean readElement(IConfigurationElement element) {
- /*
- * The EditModel Extension Point defines Configuration elements named "editModel" with
- * attributes "editModelID" and "factoryClass"
- */
- boolean result = false;
- if (element.getName().equals(EDIT_MODEL_ELEMENT)) {
- String editModelID = element.getAttribute(EDIT_MODEL_ID_ATTR);
- if (editModelID != null) {
- this.factoryConfigurations.put(editModelID, new EditModelInfo(editModelID, element));
- result = true;
- }
- }
- return result;
- }
-
- public String getCacheID(String editModelID, Map params) {
- IEditModelFactory factory = getEditModelFactoryByKey(editModelID);
- return factory.getCacheID(editModelID, params);
- }
-
- public EditModel createEditModelForRead(String editModelID, EMFWorkbenchContext context, Map params) {
- return getEditModelFactoryByKey(editModelID).createEditModelForRead(editModelID, context, params);
- }
-
- public EditModel createEditModelForWrite(String editModelID, EMFWorkbenchContext context, Map params) {
- return getEditModelFactoryByKey(editModelID).createEditModelForWrite(editModelID, context, params);
- }
-
- public Collection getEditModelResources(String editModelID) {
- Collection resources = new TreeSet();
-
- EditModelInfo nextEditModelInfo = getEditModelInfoById(editModelID);
-
- String parentModelID = null;
- Map visitedEditModels = new HashMap();
- /* collect the resources from the parents */
- while (nextEditModelInfo != null && (parentModelID = nextEditModelInfo.getParentModelID()) != null) {
- if (visitedEditModels.containsKey(parentModelID))
- throw new IllegalStateException(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_0, new Object[]{editModelID}));
- visitedEditModels.put(parentModelID, null);
- resources.addAll(getAllEditModelResources(parentModelID));
- nextEditModelInfo = getEditModelInfoById(parentModelID);
- }
-
- /* Get the resources for the actual edit model id */
- resources.addAll(getAllEditModelResources(editModelID));
-
- return resources;
- }
-
- public Collection getEditModelExtensions(String editModelID) {
- Collection extensions = new TreeSet();
-
- EditModelInfo nextEditModelInfo = getEditModelInfoById(editModelID);
-
- String parentModelID = null;
- Map visitedEditModels = new HashMap();
- /* collect the resources from the parents */
- while(nextEditModelInfo != null && (parentModelID = nextEditModelInfo.getParentModelID()) != null) {
- if(visitedEditModels.containsKey(parentModelID))
- throw new IllegalStateException(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_0,new Object [] {editModelID}));
- else
- visitedEditModels.put(parentModelID, null);
-
- extensions.addAll(getAllEditModelExtensions(parentModelID));
- nextEditModelInfo = getEditModelInfoById(parentModelID);
- }
-
- /* Get the resources for the actual edit model id */
- extensions.addAll(getAllEditModelExtensions(editModelID));
-
- return extensions;
- }
-
- public IEditModelFactory findEditModelFactoryByKey(Object editModelID) {
- IEditModelFactory factory = null;
- EditModelInfo editMdlInfo = (EditModelInfo) factoryConfigurations.get(editModelID);
- if (editMdlInfo != null)
- factory = editMdlInfo.getEditModelFactory();
- return factory;
- }
-
- public IEditModelFactory findEditModelFactoryByProject(IProject project) {
- IFacetedProject facetedProject = null;
- try {
- facetedProject = ProjectFacetsManager.create(project);
- } catch (Exception e) {
- return null;
- }
- if (facetedProject == null) return null;
- Iterator keys = factoryConfigurations.keySet().iterator();
- while (keys.hasNext()) {
- Object key = keys.next();
- if (key instanceof String) {
- try {
- IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet((String)key);
- if (projectFacet != null && facetedProject.hasProjectFacet(projectFacet))
- return findEditModelFactoryByKey(key);
- } catch (Exception e) {
- continue;
- }
-
- }
- }
-
- return null;
- }
-
- protected Collection getAllEditModelResources(String editModelID) {
- Collection resources = new ArrayList();
- resources.addAll(getLocalEditModelResources(editModelID));
- resources.addAll(getExtendedEditModelResources(editModelID));
- return resources;
- }
-
- protected Collection getAllEditModelExtensions(String editModelID) {
- Collection resources = new ArrayList();
- resources.addAll(getLocalEditModelExtensions(editModelID));
- return resources;
- }
-
- protected Collection getLocalEditModelResources(String editModelID) {
- EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
- return (editMdlInfo != null) ? editMdlInfo.getEditModelResources() : Collections.EMPTY_LIST;
- }
- protected Collection getLocalEditModelExtensions(String editModelID) {
- EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
- return (editMdlInfo != null) ? editMdlInfo.getEditModelExtensions() : Collections.EMPTY_LIST;
- }
-
- protected Collection getExtendedEditModelResources(String editModelID) {
- return EditModelExtensionRegistry.getInstance().getEditModelResources(editModelID);
- }
-
- /**
- * @param editModelKey
- * the editModelID of a given EditModelFactory defined in the Extension Point
- * @throws IllegalArgumentException
- * if a IEditModelFactory cannot be found for the given ID.
- * @return the EditModelFactory associated with a given EditModelID
- */
- protected IEditModelFactory getEditModelFactoryByKey(Object editModelID) {
- IEditModelFactory factory = null;
- EditModelInfo editMdlInfo = getEditModelInfoById(editModelID);
- if (editMdlInfo != null)
- factory = editMdlInfo.getEditModelFactory();
- else
- throw new IllegalArgumentException(EMFWorkbenchEditResourceHandler.getString(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_2, new Object[]{editModelID}));
-
- return factory;
- }
-
- /**
- * @param editModelID
- * @return
- */
- protected EditModelInfo getEditModelInfoById(Object editModelID) {
- waitForInitializationIfNecessary();
- return (EditModelInfo) factoryConfigurations.get(editModelID);
- }
-
- /**
- * If we are not initialized, block until the INSTANCE is released ( from getInstance())
- */
- private void waitForInitializationIfNecessary() {
- /* We only need to acquire the semaphore (INSTANCE), we do not need
- * to execute anything in this block. If the Registry is not initailized,
- * then it will block until the semaphore is released (from getInstance()),
- * and then release it and return immediately.
- */
- if(!isInitialized())
- synchronized(INSTANCE) { }
- }
-
- public class EditModelInfo {
-
- private String editModelID = null;
- private IConfigurationElement configurationElement = null;
-
- private IEditModelFactory factory = null;
- private List editModelResources = null;
- private List editModelExtensions = null;
-
- private String parentModelID = null;
-
- private String tostringCache = null;
-
- public EditModelInfo(String editModelID, IConfigurationElement configurationElement) {
-
- this.configurationElement = configurationElement;
- this.editModelID = editModelID;
- this.parentModelID = this.configurationElement.getAttribute(PARENT_MODEL_ATTR);
- }
-
-
- public List getEditModelResources() {
- /* this method is guarded */
- initializeResources();
- return editModelResources;
- }
-
- public IEditModelFactory getEditModelFactory() {
-// Do not block if the factory is not null
- if (this.factory == null) {
- synchronized (this) {
- // another thread could have already initialized the factory
- // while this thread was waiting to enter the sync block
- if(this.factory == null) {
- if (this.configurationElement != null) {
- try {
- this.factory = (IEditModelFactory) this.configurationElement.createExecutableExtension(FACTORY_CLASS_ATTR);
- Boolean value = Boolean.valueOf(this.configurationElement.getAttribute(LOAD_UNKNOWN_RESOURCES_ATTR));
- this.factory.setLoadKnownResourcesAsReadOnly(value.booleanValue());
- discardConfigurationElementIfNecessary();
- } catch (CoreException e) {
- Logger.getLogger(EMFWorkbenchEditPlugin.ID).logError(e);
- }
- } else {
- Logger.getLogger().logError(EMFWorkbenchEditResourceHandler.EditModelRegistry_ERROR_1);
- }
- }
- }
- }
- return this.factory;
- }
-
- private void initializeResources() {
-
- if (editModelResources == null) {
- if (configurationElement != null) {
-
- editModelResources = new ArrayList();
-
- IConfigurationElement[] resources = configurationElement.getChildren(EditModelResource.EDIT_MODEL_RESOURCE_ELEMENT);
- for (int j = 0; j < resources.length; j++) {
- editModelResources.add(new EditModelResource(resources[j]));
- }
- IConfigurationElement[] resExtensions = configurationElement.getChildren(EDIT_MODEL_RESOURCE_EXTENSION);
- if (resExtensions == null || resExtensions.length == 0) {
- editModelExtensions = Collections.EMPTY_LIST;
- } else {
- editModelExtensions = new ArrayList();
- for (int i = 0; i < resExtensions.length; i++) {
- String extension = resExtensions[i].getAttribute(EDIT_MODEL_RESOURCE_EXTENSION_NAME);
- editModelExtensions.add(extension);
- }
- }
- discardConfigurationElementIfNecessary();
- } else {
- editModelResources = Collections.EMPTY_LIST;
- }
- }
- }
-
- private void discardConfigurationElementIfNecessary() {
- if (this.editModelResources != null && this.factory != null)
- this.configurationElement = null;
- }
-
- public String toString() {
- if (tostringCache == null)
- tostringCache = "EditModelID: {" + this.editModelID + "}, Parent Model ID {" + this.parentModelID + "}, Configuration Element: [" + this.configurationElement + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
- return tostringCache;
- }
-
- /**
- * @return Returns the parentModelID.
- */
- public String getParentModelID() {
- return parentModelID;
- }
-
- public List getEditModelExtensions() {
- /* this method is guarded */
- initializeResources();
- return editModelExtensions;
- }
-
- }
- /**
- * @return Returns the initialized.
- */
- protected static boolean isInitialized() {
- return initialized;
- }
-
- public String[] getRegisteredEditModelIDs() {
- return (String[]) factoryConfigurations.keySet().toArray(new String[factoryConfigurations.keySet().size()]);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelResource.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelResource.java
deleted file mode 100644
index b5543ace6..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelResource.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-/*
- * Created on Feb 5, 2004
- *
- * To change the template for this generated file go to Window&gt;Preferences&gt;Java&gt;Code
- * Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor;
-
-
-
-public class EditModelResource extends AbstractRegistryDescriptor implements Comparable {
- public static final String EDIT_MODEL_URI_ATTR = "URI"; //$NON-NLS-1$
- public static final String AUTO_LOAD_ATTR = "autoload"; //$NON-NLS-1$
- public static final String EDIT_MODEL_RESOURCE_ELEMENT = "editModelResource"; //$NON-NLS-1$
-
- private static int loadOrderCounter = 1;
- private URI uri;
- private boolean autoload = false;
- //Indicates if this was defined as part of the edit model,
- //as opposed to an extension
- private boolean isCore = true;
-
- private String extensionID;
-
- private int loadOrder;
-
- public EditModelResource(IConfigurationElement element) {
- super(element);
- String strUri = element.getAttribute(EDIT_MODEL_URI_ATTR);
- if (strUri != null)
- EditModelResource.this.uri = URI.createURI(strUri);
-
- String strLoad = element.getAttribute(AUTO_LOAD_ATTR);
- if (strLoad != null)
- autoload = Boolean.valueOf(strLoad).booleanValue();
- loadOrder = loadOrderCounter++;
- }
-
- public EditModelResource(IConfigurationElement element, String extensionID) {
- this(element);
- this.extensionID = extensionID;
- isCore = false;
- }
-
- public URI getURI() {
- return uri;
- }
-
- public boolean isAutoLoad() {
- return autoload;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor#getID()
- */
- public String getID() {
- return extensionID;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.AbstractRegistryDescriptor#getPriority()
- */
- public int getPriority() {
- if (isCore)
- return 0;
- return super.getPriority();
- }
-
- /**
- * return whether this resource is defined as part of the edit model definition as opposed to an
- * extension
- */
- public boolean isCore() {
- return isCore;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object o) {
- if (!(o instanceof EditModelResource))
- return 1;
- EditModelResource res = (EditModelResource) o;
- int value = getPriority() - res.getPriority();
- if (value == 0)
- return loadOrder - res.loadOrder;
- return value;
- }
-
- /**
- * @return Returns the loadOrder.
- */
- public int getLoadOrder() {
- return loadOrder;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRetriever.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRetriever.java
deleted file mode 100644
index 8efb8c15f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/EditModelRetriever.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.Map;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-
-
-
-public class EditModelRetriever {
- private EMFWorkbenchContext context;
- private String editModelID;
- private Map editModelParms;
-
- /**
- * EditModelRetriever constructor comment.
- */
- public EditModelRetriever(EMFWorkbenchContext context, String editModelKey, Map parms) {
- super();
- this.context = context;
- editModelID = editModelKey;
- editModelParms = parms;
- }
-
- public EditModel getEditModelForRead(Object accessorKey) {
- return context.getEditModelForRead(getEditModelID(), accessorKey, editModelParms);
- }
-
- public EditModel getEditModelForWrite(Object accessorKey) {
- return context.getEditModelForWrite(getEditModelID(), accessorKey, editModelParms);
- }
-
- public String getEditModelID() {
- return editModelID;
- }
-
- public EMFWorkbenchContext context() {
- return context;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ExtendedComposedAdapterFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ExtendedComposedAdapterFactory.java
deleted file mode 100644
index 8f26cf3bf..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ExtendedComposedAdapterFactory.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Dec 3, 2003
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
-import org.eclipse.jem.util.logger.proxy.Logger;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class ExtendedComposedAdapterFactory extends ComposedAdapterFactory {
-
- /**
- * @param adapterFactory
- */
- public ExtendedComposedAdapterFactory(AdapterFactory adapterFactory) {
- super(adapterFactory);
- }
-
- /**
- * @param adapterFactories
- */
- public ExtendedComposedAdapterFactory(AdapterFactory[] adapterFactories) {
- super(adapterFactories);
- }
-
- /**
- * @param adapterFactories
- */
- public ExtendedComposedAdapterFactory(Collection adapterFactories) {
- super(adapterFactories);
- }
-
- /*
- * overrode from the super class, changed not to check supertypes of the EObject, because that
- * will be handled by the DynamicAdapterFactory
- *
- * @see org.eclipse.emf.common.notify.AdapterFactory#adapt(org.eclipse.emf.common.notify.Notifier,
- * java.lang.Object)
- */
- public Adapter adapt(Notifier target, Object type) {
- Adapter result = null;
-
- if (target instanceof EObject) {
- EObject eObject = (EObject) target;
- EClass eClass = eObject.eClass();
- if (eClass != null) {
- EPackage ePackage = eClass.getEPackage();
- Collection types = new ArrayList();
- types.add(ePackage);
- if (type != null) {
- types.add(type);
- }
- /* when an error occurs, remove the delegate and try again */
- boolean attemptAdaptAgain = true;
- while (result == null && attemptAdaptAgain) {
- attemptAdaptAgain = false;
- AdapterFactory delegateAdapterFactory = getFactoryForTypes(types);
- if (delegateAdapterFactory != null) {
- try {
- result = delegateAdapterFactory.adapt(target, type);
- } catch (RuntimeException re) {
- Logger.getLogger().logError(re);
- adapterFactories.remove(delegateAdapterFactory);
- attemptAdaptAgain = true;
- }
- }
- }
- }
- } else {
- result = adapt(target, type, new HashSet(), target.getClass());
- }
-
- return result;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/InvertedCommand.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/InvertedCommand.java
deleted file mode 100644
index 2bbcb111d..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/InvertedCommand.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.wst.common.internal.emfworkbench.integration.AbstractEditModelCommand;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelCommand;
-
-/**
- * Insert the type's description here. Creation date: (05/22/01 8:58:24 AM)
- *
- * @author: Administrator
- */
-public class InvertedCommand extends AbstractEditModelCommand {
- public InvertedCommand(Command targetCommand) {
- super(targetCommand);
- }
-
- public boolean canExecute() {
- return getTarget().canUndo();
- }
-
- public boolean canUndo() {
- return getTarget().canExecute();
- }
-
- /**
- * Does nothing
- */
- public void execute() {
- //does nothing
- }
-
- /**
- * getEditModelCommand method comment.
- */
- public EditModelCommand getEditModelCommand() {
- return ((AbstractEditModelCommand) getTarget()).getEditModelCommand();
- }
-
- protected int inversionDepth() {
- if (getEditModelCommand() == getTarget())
- return 1;
- return ((InvertedCommand) getTarget()).inversionDepth() + 1;
- }
-
- protected String labelPrefix() {
- return inversionDepth() % 2 == 1 ? "Undo " : "Redo ";//$NON-NLS-2$//$NON-NLS-1$
- }
-
- public void redo() {
- getTarget().undo();
- }
-
- public void undo() {
- getTarget().redo();
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ParentCommand.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ParentCommand.java
deleted file mode 100644
index 9c7dc906b..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ParentCommand.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.wst.common.internal.emfworkbench.integration.AbstractEditModelCommand;
-import org.eclipse.wst.common.internal.emfworkbench.integration.ComposedEditModel;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelCommand;
-
-/**
- * Insert the type's description here. Creation date: (05/22/01 8:57:38 AM)
- *
- * @author: Administrator
- */
-public class ParentCommand extends EditModelCommand {
- private List children;
- private ComposedEditModel editModel;
- private List affectedModels;
-
- public ParentCommand(Command targetCommand, ComposedEditModel anEditModel) {
- super(targetCommand);
- editModel = anEditModel;
- children = new ArrayList(1);
- }
-
- public boolean canExecute() {
- return getTarget().canExecute();
- }
-
- protected void computeAffectedModels() {
- ResourceSet set = null;
- List editModels = getEditModel().getChildren();
- Iterator it = computeAffectedResourceSets().iterator();
- while (it.hasNext()) {
- set = (ResourceSet) it.next();
- for (int i = 0; i < editModels.size(); i++) {
- EditModel model = (EditModel) editModels.get(i);
- if (model.getResourceSet() == set) {
- getAffectedModels().add(new EditModelRetriever(model.getEmfContext(), model.getEditModelID(), model.getParams()));
- continue;
- }
- }
- }
- }
-
- protected Set computeAffectedResourceSets() {
- Iterator objects = getTarget().getAffectedObjects().iterator();
- Set resourceSets = new HashSet();
- Object o = null;
- EObject ref = null;
- ResourceSet set = null;
- while (objects.hasNext()) {
- o = objects.next();
- if (!(o instanceof EObject))
- continue;
- ref = (EObject) o;
- if (ref.eResource() != null) {
- set = ref.eResource().getResourceSet();
- if (set != null)
- resourceSets.add(set);
- }
- }
- return resourceSets;
- }
-
- protected ChildCommand createChildCommand(EditModelRetriever retriever) {
- return new ChildCommand(this, getTarget(), retriever);
- }
-
- public void execute() {
- getTarget().execute();
- computeAffectedModels();
- pushChildrenForExecute();
- }
-
- protected void executeInModel(AbstractEditModelCommand cmd) {
- getEditModel().getCommandStack().execute(cmd);
- }
-
- protected List getAffectedModels() {
- if (affectedModels == null)
- affectedModels = new ArrayList(1);
- return affectedModels;
- }
-
- protected List getChildren() {
- return children;
- }
-
- protected ComposedEditModel getEditModel() {
- return editModel;
- }
-
- protected void invertChildren() {
- invertChildrenExcept((ChildCommand) null);
- }
-
- protected void invertChildrenExcept(ChildCommand caller) {
- for (int i = 0; i < children.size(); i++) {
- ChildCommand childCmd = (ChildCommand) children.get(i);
- if (caller == null || childCmd != caller)
- childCmd.invertAndPush();
- }
- }
-
- protected void invertFrom(ChildCommand caller) {
- invertAndPush();
- invertChildrenExcept(caller);
- }
-
- protected void pushChildrenForExecute() {
- for (int i = 0; i < getAffectedModels().size(); i++) {
- EditModelRetriever retriever = (EditModelRetriever) getAffectedModels().get(i);
- ChildCommand command = createChildCommand(retriever);
- getChildren().add(command);
- command.executeInModel(command);
- }
- }
-
- public void redo() {
- getTarget().redo();
- invertChildren();
- }
-
- public void redoFrom(ChildCommand child) {
- invertFrom(child);
- }
-
- public void undo() {
- getTarget().undo();
- invertChildren();
- }
-
- public void undoFrom(ChildCommand child) {
- invertFrom(child);
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ReadOnlyClientAccessRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ReadOnlyClientAccessRegistry.java
deleted file mode 100644
index dc8f9c824..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/ReadOnlyClientAccessRegistry.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import org.eclipse.jem.internal.util.emf.workbench.nls.EMFWorkbenchResourceHandler;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-
-/**
- * This is a readonly version of the editmodel access registry, only uses a weak hash dictionary,
- * and because the access is read only, is less concerned with timing of access/release, and will be
- * cleaned up on garbage collection if needed.
- *
- */
-public class ReadOnlyClientAccessRegistry extends ClientAccessRegistry {
-
- public ReadOnlyClientAccessRegistry() {
- super();
- }
-
- public synchronized void access(Object accessorKey) {
- if (!registry.containsKey(accessorKey)) {
- this.registry.put(accessorKey, null);
- } else
- throw new ClientAccessRegistryException(EMFWorkbenchEditResourceHandler.ClientAccessRegistry_ERROR_0, accessorKey);
- }
-
- public synchronized void release(Object accessorKey) {
-
- /*
- * Error condition: Some one has been naughty and not released the resource
- */
- if (this.registry.containsKey(accessorKey)) {
- this.registry.remove(accessorKey);
- } else
- complain(accessorKey);
- }
-
- public void complain(Object accessorKey) {
-
- throw new ClientAccessRegistryException(EMFWorkbenchResourceHandler.getString("ClientAccessRegistry_ERROR_1"), accessorKey); //$NON-NLS-1$
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/Snapshot.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/Snapshot.java
deleted file mode 100644
index 91e6f2d8d..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/Snapshot.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Oct 3, 2003
- *
- */
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-
-
-/**
- * The Snapshot is used to remember the call stack trace of any method that accesses a Resource.
- *
- * @author mdelder
- */
-public class Snapshot extends RuntimeException {
-
- public Snapshot() {
- super(EMFWorkbenchEditResourceHandler.Snapshot_ERROR_0);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Throwable#printStackTrace()
- */
- public String getStackTraceString() {
- StringWriter writer = new StringWriter();
- PrintWriter printWriter = new PrintWriter(writer);
- super.printStackTrace(printWriter);
- return writer.toString();
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/WrappingCommandStack.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/WrappingCommandStack.java
deleted file mode 100644
index bf15371b3..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/edit/WrappingCommandStack.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.edit;
-
-
-
-import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.wst.common.internal.emfworkbench.integration.ComposedEditModel;
-
-/**
- * Insert the type's description here. Creation date: (05/21/01 9:31:02 PM)
- *
- * @author: Administrator
- */
-public class WrappingCommandStack extends BasicCommandStack {
- private ComposedEditModel editModel;
-
- /**
- * WrappingCommandStack constructor comment.
- */
- public WrappingCommandStack(ComposedEditModel anEditModel) {
- super();
- editModel = anEditModel;
- }
-
- public void execute(Command command) {
- ParentCommand parent = new ParentCommand(command, editModel);
- super.execute(parent);
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/AbstractEditModelCommand.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/AbstractEditModelCommand.java
deleted file mode 100644
index 7061e7d1d..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/AbstractEditModelCommand.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.wst.common.internal.emfworkbench.edit.InvertedCommand;
-
-
-public abstract class AbstractEditModelCommand extends AbstractCommand {
- private Command target;
- private AbstractEditModelCommand owner;
-
- protected AbstractEditModelCommand() {
- super();
- }
-
- public AbstractEditModelCommand(Command targetCommand) {
- super();
- target = targetCommand;
- }
-
- public abstract EditModelCommand getEditModelCommand();
-
- protected AbstractEditModelCommand getOutermostCommand() {
- return owner == null ? this : owner.getOutermostCommand();
- }
-
- protected Command getOwner() {
- return owner;
- }
-
- public Command getTarget() {
- return target;
- }
-
- /**
- * Creates a new inverted command on the outermost command
- */
- public InvertedCommand inverted() {
- AbstractEditModelCommand outer = getOutermostCommand();
- InvertedCommand cmd = new InvertedCommand(outer);
- outer.setOwner(cmd);
- return cmd;
- }
-
- protected void setOwner(AbstractEditModelCommand ownerCommand) {
- owner = ownerCommand;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedAccessorKey.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedAccessorKey.java
deleted file mode 100644
index 70cac1e0f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedAccessorKey.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-
-/**
- * @author Administrator
- *
- *
- */
-public class ComposedAccessorKey {
-
- private Object accessorKey = null;
- private Object addonKey = null;
-
-
- public static ComposedAccessorKey getComposedAccessorKey(Object accessorKey, ComposedEditModel editModel) {
- ComposedAccessorKey newKey = new ComposedAccessorKey(accessorKey, editModel);
- editModel.cacheAccessorKey(newKey);
- return newKey;
- }
-
-
- private ComposedAccessorKey(Object accessorKey, Object addonKey) {
- this.accessorKey = accessorKey;
- this.addonKey = addonKey;
- }
-
- public boolean equals(Object other) {
- if (other == null || !(other instanceof ComposedAccessorKey))
- return false;
- ComposedAccessorKey otherKey = (ComposedAccessorKey) other;
-
- return accessorKey.equals(otherKey.accessorKey) && addonKey.equals(otherKey.addonKey);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return accessorKey.hashCode() ^ addonKey.hashCode();
- }
-
-
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedEditModel.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedEditModel.java
deleted file mode 100644
index b17f88c75..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ComposedEditModel.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-import org.eclipse.wst.common.internal.emfworkbench.edit.WrappingCommandStack;
-
-/**
- * Insert the type's description here. Creation date: (05/21/01 8:26:32 PM)
- *
- * @author: Administrator
- */
-public class ComposedEditModel extends EditModel implements EditModelListener {
-
- private List children = null;
- private Map childrenMap = null;
- private List cachedKeys = new ArrayList();
-
- /**
- * ComposedEditModel constructor comment.
- */
- public ComposedEditModel(String editModelID, EMFWorkbenchContext context) {
- super(editModelID, context, false);
- }
-
-
- public void createChildrenIfNecessary(ComposedAccessorKey composedAccessorKey) {
- //do nothing
- }
-
- /**
- * @param newKey
- */
- public void cacheAccessorKey(ComposedAccessorKey newKey) {
- if (!cachedKeys.contains(newKey))
- cachedKeys.add(newKey);
- }
-
- // Is this necessary anymore? The only diff seems to be it doesn't release resources
-// public void dispose() {
-// disposing = true;
-// if (commandStack != null)
-// commandStack.removeCommandStackListener(this);
-// if (hasListeners())
-// notifyListeners(new EditModelEvent(EditModelEvent.PRE_DISPOSE, this));
-// releasePreloadResources();
-// releaseIdentifiers();
-// emfContext = null;
-// resources = null;
-// disposing = false;
-// project = null;
-// cachedKeys = new ArrayList();
-// }
-
- public EditModel.Reference addChild(String editModelID, Map params, Object accessorKey) {
- return addChild(editModelID, params, ComposedAccessorKey.getComposedAccessorKey(accessorKey, this));
- }
-
- public EditModel.Reference addChild(String editModelID, Map params, ComposedAccessorKey composedAccessorKey) {
-
- EditModel editModel = getEmfContext().getEditModelForWrite(editModelID, composedAccessorKey, params);
- editModel.addListener(this);
-
- getChildrenMap().put(editModel.getReference(), editModel);
- getChildren().add(editModel);
-
- return editModel.getReference();
- }
-
- public void removeChild(EditModel.Reference reference, Object accessorKey) {
- ComposedAccessorKey composedAccessorKey = ComposedAccessorKey.getComposedAccessorKey(accessorKey, this);
- EditModel editModel = (EditModel) getChildrenMap().remove(reference);
- if (editModel != null) {
- editModel.releaseAccess(composedAccessorKey);
- editModel.removeListener(this);
- getChildren().remove(editModel);
- }
- }
-
- public Iterator getContainedReferences() {
- return getChildrenMap().keySet().iterator();
- }
-
- public EditModel getContainedEditModel(EditModel.Reference reference) {
- return (EditModel) getChildrenMap().get(reference);
- }
-
- /**
- * Return the CommandStack.
- */
- protected BasicCommandStack createCommandStack() {
- return new WrappingCommandStack(this);
- }
-
- /**
- * Forward all events to the listeners for this model
- */
- public void editModelChanged(EditModelEvent anEvent) {
- if (hasListeners())
- notifyListeners(anEvent);
- }
-
- public Set getAffectedFiles() {
- Set aSet = new HashSet();
- List models = getChildren();
- for (int i = 0; i < models.size(); i++) {
- EditModel child = (EditModel) models.get(i);
- aSet.addAll(child.getAffectedFiles());
- }
- return aSet;
- }
-
- public List getChildren() {
- if (children == null)
- children = new ArrayList();
- return children;
- }
-
- protected Map getChildrenMap() {
- if (childrenMap == null)
- childrenMap = new HashMap();
- return childrenMap;
- }
-
- /**
- * Pass along to children.
- */
- protected void handleSaveIfNecessaryDidNotSave(IProgressMonitor monitor) {
- List list = getChildren();
- EditModel editModel;
- for (int i = 0; i < list.size(); i++) {
- editModel = (EditModel) list.get(i);
- editModel.handleSaveIfNecessaryDidNotSave(monitor);
- }
- }
-
- /**
- * Return whether a save is needed on the CommandStack
- */
- public boolean isDirty() {
- Iterator editModels = getChildren().iterator();
- while (editModels.hasNext()) {
- EditModel editModel = (EditModel) editModels.next();
- if (editModel.isDirty())
- return true;
- }
- return false;
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- /**
- * Return whether a save is needed on the CommandStack
- */
- public boolean isInterrestedInResource(Resource aResource) {
- Iterator editModels = getChildren().iterator();
- while (editModels.hasNext()) {
- EditModel editModel = (EditModel) editModels.next();
- if (editModel.isInterrestedInResource(aResource))
- return true;
- }
- return false;
- }
-
- public void primSave(IProgressMonitor monitor) {
- List list = getChildren();
- for (int i = 0; i < list.size(); i++)
- ((EditModel) list.get(i)).primSave(monitor);
- }
-
- /**
- * This only increments the reference count of the children and should only be called if you
- * know what you are doing.
- */
- public void access(Object accessorKey) {
- ComposedAccessorKey composedAccessorKey = ComposedAccessorKey.getComposedAccessorKey(accessorKey, this);
- if (getChildren().size() == 0) {
- createChildrenIfNecessary(composedAccessorKey);
- } else {
-
- List tempchildren = getChildren();
- for (int i = 0; i < tempchildren.size(); i++) {
- EditModel model = (EditModel) tempchildren.get(i);
- model.access(composedAccessorKey);
- }
- }
- // removing for defect 1978, children should do all the accessing
- super.access(accessorKey);
-
- }
-
- /**
- * This method should be called from each client when they are finished working with the
- * EditModel.
- */
- public void releaseAccess(Object accessorKey) {
- List tempchildren = getChildren();
- ComposedAccessorKey composedAccessorKey = ComposedAccessorKey.getComposedAccessorKey(accessorKey, this);
- for (int i = 0; i < tempchildren.size(); i++) {
- EditModel model = (EditModel) tempchildren.get(i);
- model.releaseAccess(composedAccessorKey);
- }
- removeKeyFromCache(composedAccessorKey);
- // Removing this call... Children should be able to handle all releasing defect 1978
- super.releaseAccess(accessorKey);
- }
-
- public void removeKeyFromCache(ComposedAccessorKey key) {
- cachedKeys.remove(key);
- }
-
- /**
- * If one should save, they all should save.
- */
- protected boolean shouldSave() {
- List list = getChildren();
- EditModel editModel;
- for (int i = 0; i < list.size(); i++) {
- editModel = (EditModel) list.get(i);
- if (editModel.shouldSave())
- return true;
- }
- return false;
- }
-
- /**
- * If one should save, they all should save.
- */
- protected boolean shouldSave(IOperationHandler operationHandler) {
- List list = getChildren();
- EditModel editModel;
- for (int i = 0; i < list.size(); i++) {
- editModel = (EditModel) list.get(i);
- if (editModel.shouldSave(operationHandler))
- return true;
- }
- return false;
- }
-
- /**
- * @see com.ibm.etools.j2ee.workbench.EditModel#getNonResourceFiles()
- */
- public List getNonResourceFiles() {
- List list = getChildren();
- List result = new ArrayList();
- EditModel editModel;
- for (int i = 0; i < list.size(); i++) {
- editModel = (EditModel) list.get(i);
- List files = editModel.getNonResourceFiles();
- if (files != null && !files.isEmpty())
- result.addAll(files);
- }
- return result;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/CompoundingCommandStack.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/CompoundingCommandStack.java
deleted file mode 100644
index 188a889c5..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/CompoundingCommandStack.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Nov 26, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.command.CommandStackListener;
-
-
-/**
- * @author DABERG
- *
- * This class does not actually execute any commands. It merely gathers the commands to be executed
- * and compounds them so that they can be executed against the actualCommandStack.
- */
-public class CompoundingCommandStack implements CommandStack {
- private CommandStack actualCommandStack;
- private Command compoundCommand;
-
- /**
- *
- */
- public CompoundingCommandStack(CommandStack actualCommandStack) {
- this.actualCommandStack = actualCommandStack;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#execute(org.eclipse.emf.common.command.Command)
- */
- public void execute(Command command) {
- if (compoundCommand == null)
- compoundCommand = command;
- else
- compoundCommand = compoundCommand.chain(command);
- }
-
- public void performExecution() {
- if (compoundCommand != null) {
- try {
- actualCommandStack.execute(compoundCommand);
- } finally {
- compoundCommand = null;
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#canUndo()
- */
- public boolean canUndo() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#undo()
- */
- public void undo() {
- //default
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#canRedo()
- */
- public boolean canRedo() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#getUndoCommand()
- */
- public Command getUndoCommand() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#getRedoCommand()
- */
- public Command getRedoCommand() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#getMostRecentCommand()
- */
- public Command getMostRecentCommand() {
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#redo()
- */
- public void redo() {
- //redo
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#flush()
- */
- public void flush() {
- //flush
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#addCommandStackListener(org.eclipse.emf.common.command.CommandStackListener)
- */
- public void addCommandStackListener(CommandStackListener listener) {
- //default
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.command.CommandStack#removeCommandStackListener(org.eclipse.emf.common.command.CommandStackListener)
- */
- public void removeCommandStackListener(CommandStackListener listener) {
- //default
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/DynamicAdapterFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/DynamicAdapterFactory.java
deleted file mode 100644
index 5e40cb913..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/DynamicAdapterFactory.java
+++ /dev/null
@@ -1,642 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Dec 1, 2003
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.edit.provider.ChangeNotifier;
-import org.eclipse.emf.edit.provider.IChangeNotifier;
-import org.eclipse.emf.edit.provider.IDisposable;
-import org.eclipse.emf.edit.provider.INotifyChangedListener;
-import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
-import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifier;
-import org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent;
-import org.eclipse.wst.common.frameworks.internal.enablement.EnablementManager;
-import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifier;
-import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener;
-import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementManager;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchEditResourceHandler;
-import org.eclipse.wst.common.internal.emfworkbench.edit.AdapterFactoryDescriptor;
-import org.eclipse.wst.common.internal.emfworkbench.edit.AdapterFactoryRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.edit.ExtendedComposedAdapterFactory;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class DynamicAdapterFactory implements AdapterFactory, IChangeNotifier, IDisposable, INotifyChangedListener, IEnablementIdentifierListener {
-
- private static final AdapterFactory NULL_FACTORY = new AdapterFactoryImpl();
-
- private ResourceItemProviderAdapterFactory resourceItemProviderAdapterFactory = null;
-
- private String viewID;
-
- //Each of the two maps below are keyed by the project
- private Map adapterFactoriesByPackage;
-
- private Map adapterFactoriesByType;
-
- private Set allFactories;
-
- /**
- * This is used to implement {@link IChangeNotifier}
- */
- protected ChangeNotifier changeNotifier = new ChangeNotifier();
-
- private boolean respectingActivities = false;
-
- protected static final Object NO_PROJECT = "NO_PROJECT"; //$NON-NLS-1$
-
- /**
- */
- public DynamicAdapterFactory(String viewID, boolean respectActivies) {
- this.viewID = viewID;
- this.respectingActivities = respectActivies;
- initialize();
- }
-
- /**
- */
- public DynamicAdapterFactory(String viewID) {
- this.viewID = viewID;
- initialize();
- }
-
- private void initialize() {
- adapterFactoriesByPackage = new HashMap();
- adapterFactoriesByType = new HashMap();
- allFactories = new HashSet();
- }
-
- public boolean isFactoryForType(Object type) {
- return getFactoryForType(type) != null;
- }
-
- private AdapterFactory getFactoryForType(Object type) {
-
- if (type == null)
- return null;
-
- if (type instanceof EObject)
- return getFactoryForType((EObject) type);
-
- Object aProject = ProjectUtilities.getProject(type);
- if (aProject == null)
- aProject = NO_PROJECT;
- AdapterFactory factory = getExistingFactoryForType(aProject, type);
- if (factory == NULL_FACTORY)
- return null;
- else if (factory == null) {
- factory = findFactoryForType(aProject, type);
-
- if (factory == null)
- addAdapterFactory(aProject, type, NULL_FACTORY);
- else
- addAdapterFactory(aProject, type, factory);
- }
- return factory;
- }
-
- private AdapterFactory getExistingFactoryForType(Object p, Object type) {
- if (p == null)
- return null;
- Map aMap = (Map) adapterFactoriesByType.get(p);
- if (aMap == null)
- return null;
- return (AdapterFactory) adapterFactoriesByType.get(type);
- }
-
- /*
- * The factory was not cached by type, so we will search the cache of factories for the project
- * and see if it can be found there
- */
- private AdapterFactory findFactoryForType(Object project, Object type) {
- if (project == null)
- return null;
- Map aMap = (Map) adapterFactoriesByPackage.get(project);
- if (aMap == null)
- return null;
- Iterator iter = aMap.values().iterator();
- AdapterFactory factory = null;
- while (iter.hasNext()) {
- factory = (AdapterFactory) iter.next();
- if (factory.isFactoryForType(type))
- return factory;
- }
-
- // adapt the resource to its contents
- if (getResourceItemProviderAdapterFactory().isFactoryForType(type))
- return getResourceItemProviderAdapterFactory();
- return null;
- }
-
- private AdapterFactory getFactoryForType(EObject obj) {
- EClass eClass = obj.eClass();
- if (eClass == null)
- return null;
-
- EPackage ePackage = eClass.getEPackage();
- Object aProject = ProjectUtilities.getProject(obj);
- if (aProject == null)
- aProject = NO_PROJECT;
- AdapterFactory result = getFactoryForPackage(aProject, ePackage);
-
- if (result == null) {
- Set failedPackageSet = new HashSet();
- failedPackageSet.add(ePackage);
- Iterator supertypes = eClass.getEAllSuperTypes().iterator();
- while (supertypes.hasNext()) {
- eClass = (EClass) supertypes.next();
- if (eClass != null) {
- ePackage = eClass.getEPackage();
- if (failedPackageSet.add(ePackage)) {
- result = getFactoryForPackage(aProject, ePackage);
- if (result != null)
- break;
- }
- }
- }
- }
- return result;
- }
-
- private AdapterFactory getFactoryForPackage(Object aProject, EPackage aPackage) {
- if (aProject == null || aPackage == null)
- return null;
- AdapterFactory factory = getExistingFactoryForPackage(aProject, aPackage);
- if (factory == NULL_FACTORY)
- return null;
- else if (factory == null) {
- try {
- factory = createAdapterFactory(aProject, aPackage);
-
- if (factory == null)
- addAdapterFactory(aProject, aPackage, NULL_FACTORY);
- else
- addAdapterFactory(aProject, aPackage, factory);
- } catch (RuntimeException re) {
- Logger.getLogger().logError(re);
- }
- }
- return factory;
- }
-
- private AdapterFactory getFactoryForTypes(Object p, List types) {
- Map aMap = (Map) adapterFactoriesByPackage.get(p);
- if (aMap == null)
- return adaptResourceTypes(types);
-
- Iterator factories = aMap.values().iterator();
- AdapterFactory factory = null;
- while (factories.hasNext()) {
- factory = (AdapterFactory) factories.next();
- if (isFactoryForAllTypes(factory, types)) {
- return factory;
- }
- }
-
-
- return null;
- }
-
- private AdapterFactory adaptResourceTypes(List types) {
- // adapt the resource to its contents
- if (isFactoryForAllTypes(getResourceItemProviderAdapterFactory(), types))
- return getResourceItemProviderAdapterFactory();
- return null;
- }
-
- private void removeFactoryForTypes(Object p, List types) {
- Map aMap = (Map) adapterFactoriesByPackage.get(p);
- if (aMap == null)
- return;
- Iterator factories = aMap.values().iterator();
- AdapterFactory factory = null;
- while (factories.hasNext()) {
- factory = (AdapterFactory) factories.next();
- if (isFactoryForAllTypes(factory, types)) {
- aMap.remove(factory);
- }
- }
-
- }
-
- private boolean isFactoryForAllTypes(AdapterFactory factory, List types) {
- for (int i = 0; i < types.size(); i++) {
- if (!factory.isFactoryForType(types.get(i))) {
- return false;
- }
- }
- return true;
-
- }
-
- private AdapterFactory getExistingFactoryForPackage(Object p, EPackage aPackage) {
- if (p == null)
- return null;
- Map aMap = (Map) adapterFactoriesByPackage.get(p);
- if (aMap == null)
- return null;
- return (AdapterFactory) aMap.get(aPackage);
- }
-
- private void addAdapterFactory(Object p, EPackage aPackage, AdapterFactory adapterFactory) {
- Map aMap = getOrCreateMap(p, adapterFactoriesByPackage);
-
- aMap.put(aPackage, adapterFactory);
-
- if (adapterFactory == NULL_FACTORY)
- return;
-
- if (adapterFactory instanceof IChangeNotifier) {
- ((IChangeNotifier) adapterFactory).addListener(this);
- }
- allFactories.add(adapterFactory);
- }
-
- private Map getOrCreateMap(Object p, Map container) {
- Map aMap = (Map) container.get(p);
- if (aMap == null) {
- aMap = new HashMap(10);
- container.put(p, aMap);
- }
- return aMap;
- }
-
- private void addAdapterFactory(Object p, Object type, AdapterFactory adapterFactory) {
- Map aMap = getOrCreateMap(p, adapterFactoriesByType);
- aMap.put(type, adapterFactory);
-
- if (adapterFactory == NULL_FACTORY)
- return;
-
- if (adapterFactory instanceof IChangeNotifier) {
- ((IChangeNotifier) adapterFactory).addListener(this);
- }
- allFactories.add(adapterFactory);
- }
-
- public Object adapt(Object target, Object type) {
- Object adapter = target;
- if (target instanceof Notifier) {
- adapter = adapt((Notifier) target, type);
- }
-
- if (!(type instanceof Class) || (((Class) type).isInstance(adapter))) {
- return adapter;
- }
-
- return null;
- }
-
- public Adapter adapt(Notifier target, Object type) {
- Adapter result = null;
-
- if (target instanceof EObject)
- result = adapt((EObject) target, type);
- else {
- Object p = ProjectUtilities.getProject(target);
- if (p == null)
- p = NO_PROJECT;
- result = adapt(p, target, type, new HashSet(), target.getClass());
-
- }
-
- return result;
- }
-
- public Adapter adapt(EObject target, Object type) {
-
- EClass eClass = target.eClass();
- if (eClass == null)
- return null;
-
- EPackage ePackage = eClass.getEPackage();
- Adapter result = adapt(target, ePackage, type);
-
- if (result == null) {
- Set failedPackageSet = new HashSet();
- failedPackageSet.add(ePackage);
- Iterator supertypes = eClass.getEAllSuperTypes().iterator();
- while (supertypes.hasNext()) {
- eClass = (EClass) supertypes.next();
- if (eClass != null) {
- ePackage = eClass.getEPackage();
- if (failedPackageSet.add(ePackage)) {
- result = adapt(target, ePackage, type);
- if (result != null)
- break;
- }
- }
- }
- }
- return result;
- }
-
- private Adapter adapt(EObject target, EPackage ePackage, Object type) {
- Object aProject = ProjectUtilities.getProject(target);
- if (aProject == null)
- aProject = NO_PROJECT;
- AdapterFactory delegate = getFactoryForPackage(aProject, ePackage);
- if (delegate != null && delegate.isFactoryForType(type)) {
- return delegate.adapt(target, type);
- }
-
- return null;
- }
-
- /*
- * Code borrowed from {@link ComposedAdapterFactory}
- *
- */
- private Adapter adapt(Object p, Notifier target, Object type, Collection failedPackages, Class javaClass) {
- if (p == null)
- return null;
-
- Adapter result = null;
-
- Package javaPackage = javaClass.getPackage();
- if (failedPackages.add(javaPackage)) {
- List types = new ArrayList(2);
- types.add(javaPackage);
- if (type != null) {
- types.add(type);
- }
-
- /* when an error occurs, remove the delegate and try again */
- boolean attemptAdaptAgain = true;
- while (result == null && attemptAdaptAgain) {
- attemptAdaptAgain = false;
-
- AdapterFactory delegateAdapterFactory = getFactoryForTypes(p, types);
- if (delegateAdapterFactory != null) {
- try {
- result = delegateAdapterFactory.adapt(target, type);
- } catch (RuntimeException re) {
- Logger.getLogger().logError(re);
- removeFactoryForTypes(p, types);
- attemptAdaptAgain = true;
- }
- }
- }
- }
-
- if (result == null) {
- Class superclass = javaClass.getSuperclass();
- if (superclass != null) {
- result = adapt(p, target, type, failedPackages, javaClass.getSuperclass());
- }
- if (result == null) {
- Class[] interfaces = javaClass.getInterfaces();
- for (int i = 0; i < interfaces.length; ++i) {
- result = adapt(p, target, type, failedPackages, interfaces[i]);
- if (result != null) {
- break;
- }
- }
- }
- }
-
- return result;
- }
-
- public Adapter adaptNew(Notifier target, Object type) {
-
- AdapterFactory factory = getFactoryForType(target);
-
- if (factory != null)
- return factory.adaptNew(target, type);
- return null;
- }
-
- public void adaptAllNew(Notifier target) {
-
- AdapterFactory factory = getFactoryForType(target);
-
- if (factory != null)
- factory.adaptAllNew(target);
-
- }
-
- public void addListener(INotifyChangedListener notifyChangedListener) {
- changeNotifier.add(notifyChangedListener);
- }
-
- public void removeListener(INotifyChangedListener notifyChangedListener) {
- changeNotifier.remove(notifyChangedListener);
- }
-
- public void fireNotifyChanged(Notification notification) {
- if (changeNotifier == null || changeNotifier.isEmpty() || changeNotifier.get(0) == null)
- return;
- changeNotifier.fireNotifyChanged(notification);
- }
-
- public void dispose() {
- Iterator iter = allFactories.iterator();
- Object factory = null;
- while (iter.hasNext()) {
- factory = iter.next();
- disposeFactory(factory);
- }
- for (Iterator itr = getEnablementIdentifiers().iterator(); itr.hasNext();) {
- ((IEnablementIdentifier) itr.next()).removeIdentifierListener(this);
- }
- if (resourceItemProviderAdapterFactory != null)
- resourceItemProviderAdapterFactory.removeListener(this);
- }
-
- private void disposeFactory(Object factory) {
- if (factory instanceof IDisposable) {
- ((IDisposable) factory).dispose();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.edit.provider.INotifyChangedListener#notifyChanged(org.eclipse.emf.common.notify.Notification)
- */
- public void notifyChanged(Notification notification) {
- //Foward the notification on to all my listeners
- fireNotifyChanged(notification);
- }
-
- /**
- * @param project
- */
- private void removeAdapterFactories(Object project) {
- adapterFactoriesByType.remove(project);
- Map aMap = (Map) adapterFactoriesByPackage.remove(project);
- if (aMap == null)
- return;
-
- Iterator factories = aMap.values().iterator();
- Object adapterFactory;
- while (factories.hasNext()) {
- adapterFactory = factories.next();
- allFactories.remove(adapterFactory);
- disposeFactory(adapterFactory);
- }
- }
-
- private AdapterFactory createAdapterFactory(Object project, EPackage ePackage) {
- if (ePackage == null)
- throw new IllegalArgumentException(EMFWorkbenchEditResourceHandler.DynamicAdapterFactory_ERROR_0);
-
- return createAdapterFactory(project, AdapterFactoryRegistry.instance().getDescriptors(ePackage, viewID));
-
- }
-
- private AdapterFactory createAdapterFactory(Object project, List descriptors) {
- if (descriptors == null || descriptors.isEmpty())
- return null;
-
- AdapterFactory fact = null;
- IEnablementIdentifier identifier = null;
- AdapterFactoryDescriptor desc = null;
- if (descriptors.size() == 1) {
- desc = (AdapterFactoryDescriptor) descriptors.get(0);
- identifier = getIdentifier(project, desc);
- addListenerIfNecessary(identifier);
- if (project.equals(NO_PROJECT) || (identifier != null && identifier.isEnabled()))
- return desc.createInstance();
- return null;
- }
- List factories = new ArrayList(descriptors.size());
- for (int i = 0; i < descriptors.size(); i++) {
- desc = (AdapterFactoryDescriptor) descriptors.get(i);
- identifier = getIdentifier(project, desc);
- addListenerIfNecessary(identifier);
- if (project.equals(NO_PROJECT) || (identifier != null && identifier.isEnabled())) {
- fact = desc.createInstance();
- if (fact != null)
- factories.add(fact);
- }
- }
- if (factories.isEmpty())
- return null;
-
- return new ExtendedComposedAdapterFactory(factories);
- }
-
- /**
- * @param project
- * @param desc
- * @return
- */
- private IEnablementIdentifier getIdentifier(Object project, AdapterFactoryDescriptor desc) {
- IEnablementIdentifier identifier = null;
- if (isRespectingActivities() && project instanceof IProject)
- identifier = IEnablementManager.INSTANCE.getIdentifier(desc.getID(), (IProject) project);
- else if (project instanceof IProject)
- identifier = EnablementManager.INSTANCE.getIdentifier(desc.getID(), (IProject) project);
- return identifier;
- }
-
- /**
- * @return
- */
- private boolean isRespectingActivities() {
- return respectingActivities;
- }
-
- protected void addListenerIfNecessary(IEnablementIdentifier identifier) {
- if (identifier == null)
- return;
- identifier.addIdentifierListener(this);
- getEnablementIdentifiers().add(identifier);
- }
-
- protected boolean isListeningTo(IEnablementIdentifier identifier) {
- return getEnablementIdentifiers().contains(identifier);
- }
-
- /**
- * @return Returns the enablementIdentifiers.
- */
- protected Set getEnablementIdentifiers() {
- if (enablementIdentifiers == null)
- enablementIdentifiers = new HashSet();
- return enablementIdentifiers;
- }
-
- private Set enablementIdentifiers;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener#identifierChanged(org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent)
- */
- public void identifierChanged(EnablementIdentifierEvent identifierEvent) {
- if (identifierEvent.hasEnabledChanged() || identifierEvent.hasFunctionGroupIdsChanged()) {
- Object project = ((EnablementIdentifier) identifierEvent.getIdentifier()).getProject();
- if (project != null) {
- removeAdapterFactories(project);
- /*
- * final Notifier notifier = (Notifier) getCachedRoots().get(project);
- */
- /* force a viewer refresh */
- notifyChanged(new NotificationImpl(Notification.ADD, null, null) {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.common.notify.impl.NotificationImpl#getNotifier()
- */
- public Object getNotifier() {
- return null; // notifier;
- }
- });
- }
- /* else replace entire structure */
- }
- }
-
- /**
- * @return Returns the resourceItemProviderAdapterFactory.
- */
- public ResourceItemProviderAdapterFactory getResourceItemProviderAdapterFactory() {
- if (resourceItemProviderAdapterFactory == null) {
- resourceItemProviderAdapterFactory = new ResourceItemProviderAdapterFactory();
- resourceItemProviderAdapterFactory.addListener(this);
- }
- return resourceItemProviderAdapterFactory;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin.java
deleted file mode 100644
index 234fe1d27..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EMFWorkbenchEditPlugin.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.io.FileNotFoundException;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.emf.common.util.WrappedException;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil;
-import org.eclipse.wst.common.internal.emfworkbench.PassthruResourceSet;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-import org.osgi.framework.BundleContext;
-
-/**
- * The main plugin class to be used in the desktop.
- */
-public class EMFWorkbenchEditPlugin extends Plugin {
- public static final String ID = "org.eclipse.wst.common.emfworkbench.integration"; //$NON-NLS-1$
-
- public static final String EDIT_MODEL_FACTORIES_EXTENSION_POINT = "editModel"; //$NON-NLS-1$
- public static final String EDIT_MODEL_EXTENSION_REGISTRY_EXTENSION_POINT = "editModelExtension"; //$NON-NLS-1$
- public static final String ADAPTER_FACTORY_REGISTRY_EXTENSION_POINT = "adapterFactory"; //$NON-NLS-1$
-
-
- //The shared instance.
- private static EMFWorkbenchEditPlugin plugin;
-
- /**
- * The constructor.
- */
- public EMFWorkbenchEditPlugin() {
- super();
- plugin = this;
- }
-
- /**
- * Returns the shared instance.
- */
- public static EMFWorkbenchEditPlugin getDefault() {
- return plugin;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.Plugin#startup()
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- ExtendedEcoreUtil.setFileNotFoundDetector(new ExtendedEcoreUtil.FileNotFoundDetector() {
- public boolean isFileNotFound(WrappedException wrappedEx) {
- return WorkbenchResourceHelperBase.isResourceNotFound(wrappedEx) || wrappedEx.exception() instanceof FileNotFoundException;
- }
- });
- WorkbenchResourceHelper.initializeFileAdapterFactory();
- }
-
- public static ResourceSet createIsolatedResourceSet(IProject project) {
- return new PassthruResourceSet(project);
- }
-
- public static ResourceSet createWorkspacePassthruResourceSet() {
- return new PassthruResourceSet();
- }
-
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java
deleted file mode 100644
index 0b0a6cb0a..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModel.java
+++ /dev/null
@@ -1,1610 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.command.BasicCommandStack;
-import org.eclipse.emf.common.command.CommandStackListener;
-import org.eclipse.emf.common.notify.Notification;
-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.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jem.internal.util.emf.workbench.nls.EMFWorkbenchResourceHandler;
-import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.frameworks.internal.ISaveHandler;
-import org.eclipse.wst.common.frameworks.internal.SaveFailedException;
-import org.eclipse.wst.common.frameworks.internal.SaveHandlerHeadless;
-import org.eclipse.wst.common.frameworks.internal.SaveHandlerRegister;
-import org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent;
-import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifier;
-import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener;
-import org.eclipse.wst.common.frameworks.internal.enablement.nonui.IWFTWrappedException;
-import org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler;
-import org.eclipse.wst.common.internal.emf.resource.CompatibilityXMIResource;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
-import org.eclipse.wst.common.internal.emf.resource.TranslatorResource;
-import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil;
-import org.eclipse.wst.common.internal.emf.utilities.PleaseMigrateYourCodeError;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-import org.eclipse.wst.common.internal.emfworkbench.edit.ClientAccessRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.edit.EditModelRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.edit.EditModelResource;
-import org.eclipse.wst.common.internal.emfworkbench.edit.ReadOnlyClientAccessRegistry;
-import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateInputProvider;
-import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidator;
-import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorImpl;
-import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter;
-
-
-public class EditModel implements CommandStackListener, ResourceStateInputProvider, ResourceStateValidator, IEnablementIdentifierListener {
-
- protected BasicCommandStack commandStack;
- protected final ListenerList listeners = new ListenerList();
-
- private Map params;
- private final String editModelID;
- private final boolean readOnly;
- // These are the current resource uris we need to track
- protected List knownResourceUris;
- // These are the current resource extensions to track
- protected List knownResourceExtensions;
- // This is a subset of the known resource uris, which we have requested be autoloaded
- protected List preloadResourceUris;
- // This is a map of identifiers to resources that we need to listen to in order to listen for
- // updates to the edit model resources
- protected Map resourceIdentifiers;
-
- protected EditModelEvent dirtyModelEvent;
- protected boolean isNotifing = false;
- protected boolean disposing = false;
- private boolean disposed = false;
- protected ResourceStateValidator stateValidator;
- protected boolean accessAsReadForUnKnownURIs;
- protected ResourceAdapter resourceAdapter = new ResourceAdapter();
- protected boolean isReverting = false;
- protected List resources;
- private ClientAccessRegistry registry;
- protected EMFWorkbenchContext emfContext = null;
- protected IProject project = null;
-
- private Reference reference;
- private List resourcesTargetedForTermination;
-
- protected class ResourceAdapter extends AdapterImpl {
- public void notifyChanged(Notification notification) {
- if (!isDisposing() && notification.getEventType() == Notification.SET && notification.getFeatureID(null) == Resource.RESOURCE__IS_LOADED) {
- resourceIsLoadedChanged((Resource) notification.getNotifier(), notification.getOldBooleanValue(), notification.getNewBooleanValue());
- }
- }
- }
-
- public EditModel(String editModelID, EMFWorkbenchContext context, boolean readOnly) {
- if (context == null)
- throw new IllegalStateException("EMF context can't be null"); //$NON-NLS-1$
- this.editModelID = editModelID;
- this.readOnly = readOnly;
- if (readOnly)
- this.registry = new ReadOnlyClientAccessRegistry();
- else
- this.registry = new ClientAccessRegistry();
- this.emfContext = context;
- this.project = context.getProject();
- initializeKnownResourceUris();
- processLoadedResources();
- processPreloadResources();
- }
-
- public EditModel(String editModelID, EMFWorkbenchContext context, boolean readOnly, boolean accessUnknownResourcesAsReadOnly) {
- this(editModelID, context, readOnly);
- this.accessAsReadForUnKnownURIs = accessUnknownResourcesAsReadOnly;
- }
-
- /**
- * @return editModelID
- */
- public String getEditModelID() {
- return editModelID;
- }
-
- public boolean isDisposing() {
- return disposing;
- }
-
-
- /**
- * Subclasses should not override this method. This method will be made
- * final in the next release. Subclasses should override doDispose() as
- * necessary to dispose any additional artifacts.
- */
- public void dispose() {
- try {
- if (disposing || disposed)
- return;
- disposing = true;
-
- if (hasListeners())
- notifyListeners(new EditModelEvent(EditModelEvent.PRE_DISPOSE, this));
-
- releaseResources();
-
- if (commandStack != null)
- commandStack.removeCommandStackListener(this);
- if (getEmfContext() != null)
- getEmfContext().removeEditModel(this, isReadOnly());
- releasePreloadResources();
- releaseIdentifiers();
- doDispose();
- } catch (RuntimeException re) {
- Logger.getLogger().logError(re);
- } finally {
- emfContext = null;
- resources = null;
- project = null;
- disposed = true;
- disposing = false;
- }
- }
-
- /**
- * Subclasses should override as necessary
- */
- protected void doDispose() {
- }
-
- protected void releaseIdentifiers() {
- if (resourceIdentifiers == null)
- return;
- Iterator iter = resourceIdentifiers.keySet().iterator();
- IEnablementIdentifier identifier = null;
- while (iter.hasNext()) {
- identifier = (IEnablementIdentifier) iter.next();
- identifier.removeIdentifierListener(this);
- }
- }
-
- private ResourceSetWorkbenchSynchronizer getResourceSetSynchronizer() {
- if (emfContext == null || !emfContext.hasResourceSet())
- return null;
- return getEmfContext().getResourceSet().getSynchronizer();
- }
-
- protected void releasePreloadResources() {
- ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getResourceSetSynchronizer();
- if (sync != null) {
- for (int i = 0; i < preloadResourceUris.size(); i++) {
- URI uri = (URI) preloadResourceUris.get(i);
- sync.disableAutoload(uri);
- }
- for (int i = 0; i < knownResourceExtensions.size(); i++) {
- String ext = (String) knownResourceExtensions.get(i);
- sync.disableAutoload(ext);
- }
- }
- }
-
-
- /** ** BEGIN Command Stack Manipulation *** */
-
- /**
- * Return the CommandStack.
- */
- protected BasicCommandStack createCommandStack() {
- BasicCommandStack stack = new BasicCommandStack();
- return stack;
- }
-
- /**
- * This is called with the {@linkorg.eclipse.emf.common.command.CommandStack}'s state has changed.
- */
- public void commandStackChanged(java.util.EventObject event) {
- if (dirtyModelEvent == null)
- dirtyModelEvent = new EditModelEvent(EditModelEvent.DIRTY, this);
- if (hasListeners())
- notifyListeners(dirtyModelEvent);
- }
-
- /**
- * Flush the Commands from the CommandStack.
- */
- protected void flushCommandStack() {
- getCommandStack().flush();
- getCommandStack().saveIsDone();
- }
-
- /**
- * Return the CommandStack.
- */
- public BasicCommandStack getCommandStack() {
- if (commandStack == null) {
- commandStack = createCommandStack();
- commandStack.addCommandStackListener(this);
- }
- return commandStack;
- }
-
- /**
- * Returns true if there are any listeners
- */
- public boolean hasListeners() {
- return !listeners.isEmpty();
- }
-
- /** ** END Command Stack Manipulation *** */
-
- /** ** BEGIN Listeners *** */
-
- /**
- * Add
- *
- * @aListener to the list of listeners.
- */
- public void addListener(EditModelListener aListener) {
- if (aListener != null)
- listeners.add(aListener);
- }
-
- /**
- * Notify listeners of
- *
- * @anEvent.
- */
- protected void notifyListeners(final EditModelEvent anEvent) {
-
- NotifyRunner notifier = new NotifyRunner(anEvent);
-
- Object[] notifyList = listeners.getListeners();
- for (int i = 0; i < notifyList.length; i++) {
- notifier.setListener( (EditModelListener) notifyList[i] );
- SafeRunner.run(notifier);
- }
- }
-
- /**
- * Remove
- *
- * @aListener from the list of listeners.
- */
- public boolean removeListener(EditModelListener aListener) {
- listeners.remove(aListener);
- return true;
- }
-
- /** ** END Listeners *** */
-
- protected void makeFileEditable(IFile aFile) {
- if (aFile == null)
- return;
- aFile.getResourceAttributes().setReadOnly(false);
- }
-
- /**
- * @return java.util.List of IFile; any read-only files that will be touched if this edit model
- * saves
- */
- public List getReadOnlyAffectedFiles() {
- Iterator affected = getAffectedFiles().iterator();
- List result = new ArrayList();
- while (affected.hasNext()) {
- IFile aFile = (IFile) affected.next();
- if (aFile.isReadOnly())
- result.add(aFile);
- }
- return result;
- }
-
- /** ** BEGIN Save Handlers *** */
-
- protected ISaveHandler getSaveHandler() {
- return SaveHandlerRegister.getSaveHandler();
- }
-
- /**
- * Default is to do nothing. This method is called if a saveIfNecessary or
- * saveIfNecessaryWithPrompt determines not to save. This provides subclasses with an
- * opportunity to do some other action.
- */
- protected void handleSaveIfNecessaryDidNotSave(IProgressMonitor monitor) {
- // do nothing
- }
-
- /**
- * This will force all of the referenced Resources to be saved.
- */
- public void save(Object accessorKey) {
- save(null, accessorKey);
- }
-
- /**
- * This will force all of the referenced Resources to be saved.
- */
- public void save(IProgressMonitor monitor) throws PleaseMigrateYourCodeError {
- // save
- }
-
- /**
- * Subclasses may override {@link #primSave}
- */
- public final void save(IProgressMonitor monitor, Object accessorKey) {
- assertPermissionToSave(accessorKey);
- getSaveHandler().access();
- try {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor aMonitor) {
- primSave(aMonitor);
- }
- };
- runSaveOperation(runnable, monitor);
- } catch (SaveFailedException ex) {
- getSaveHandler().handleSaveFailed(ex, monitor);
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- getSaveHandler().release();
- }
- }
-
- /**
- * Save only resources that need to be saved (i.e., no other references).
- */
- public void saveIfNecessary(Object accessorKey) {
- saveIfNecessary(null, accessorKey);
- }
-
- /**
- * Save only resources that need to be saved (i.e., no other references).
- */
- public void saveIfNecessary(IProgressMonitor monitor, Object accessorKey) {
- if (shouldSave())
- save(monitor, accessorKey);
- else
- handleSaveIfNecessaryDidNotSave(monitor);
- }
-
- /**
- * Save only if necessary. If typically a save would not occur because this edit model is
- * shared, the user will be prompted using the
- *
- * @operationHandler. If the prompt returns true (the user wants to save) the entire edit model
- * will be saved.
- */
- public void saveIfNecessaryWithPrompt(IOperationHandler operationHandler, Object accessorKey) {
- saveIfNecessaryWithPrompt(null, operationHandler, accessorKey);
- }
-
- /**
- * Save only if necessary. If typically a save would not occur because this edit model is
- * shared, the user will be prompted using the
- *
- * @operationHandler. If the prompt returns true (the user wants to save) the entire edit model
- * will be saved. You may pass in a boolean <code>wasDirty</code> to
- * indicate whether this edit model was dirty prior to making any changes and
- * calling this method. {@link EditModel#isDirty()}
- */
- public void saveIfNecessaryWithPrompt(IOperationHandler operationHandler, boolean wasDirty, Object accessorKey) {
- saveIfNecessaryWithPrompt(null, operationHandler, wasDirty, accessorKey);
- }
-
- /**
- * Save only if necessary. If typically a save would not occur because this edit model is
- * shared, the user will be prompted using the
- *
- * @operationHandler. If the prompt returns true (the user wants to save) the entire edit model
- * will be saved.
- */
- public void saveIfNecessaryWithPrompt(IProgressMonitor monitor, IOperationHandler operationHandler, Object accessorKey) {
- saveIfNecessaryWithPrompt(monitor, operationHandler, true, accessorKey);
- }
-
- /**
- * Save only if necessary. If typically a save would not occur because this edit model is
- * shared, the user will be prompted using the
- *
- * @operationHandler. If the prompt returns true (the user wants to save) the entire edit model
- * will be saved. You may pass in a boolean <code>wasDirty</code> to
- * indicate whether this edit model was dirty prior to making any changes and
- * calling this method. {@link EditModel#isDirty()}
- */
- public void saveIfNecessaryWithPrompt(IProgressMonitor monitor, IOperationHandler operationHandler, boolean wasDirty, Object accessorKey) {
-
- if (shouldSave(operationHandler, wasDirty))
- save(monitor, accessorKey);
- else
- handleSaveIfNecessaryDidNotSave(monitor);
- }
-
- protected void assertPermissionToSave(Object accessorKey) {
- if (registry != null)
- registry.assertAccess(accessorKey);
- }
-
- protected void runSaveOperation(IWorkspaceRunnable runnable, IProgressMonitor monitor) throws SaveFailedException {
- try {
- ResourcesPlugin.getWorkspace().run(runnable, ResourcesPlugin.getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, monitor);
- } catch (CoreException e) {
- throw new SaveFailedException(e);
- }
- }
-
- /**
- * Should the resources be saved.
- */
- protected boolean shouldSave(IOperationHandler operationHandler, boolean wasDirty) {
- return !wasDirty ? shouldSave() : shouldSave(operationHandler);
- }
-
- /**
- * Return true if the uri for
- *
- * @aResource is one of the known resource uris.
- */
- public boolean isInterrestedInResource(Resource aResource) {
- return isInterrestedInResourceUri(aResource.getURI());
- }
-
- protected boolean isInterrestedInResourceUri(URI resURI) {
- URI uri;
- List uriStrings = getKnownResourceUris();
- for (int i = 0; i < uriStrings.size(); i++) {
- uri = (URI) uriStrings.get(i);
- if (ExtendedEcoreUtil.endsWith(resURI, uri))
- return true;
- }
- return false;
- }
-
-
- /**
- * Subclasses should override and add URIs (type URI) of known resources. You must add resources
- * that have references to other known resources first so they will be released first.
- */
- protected void initializeKnownResourceUris() {
- knownResourceUris = new ArrayList();
- preloadResourceUris = new ArrayList();
- EditModelResource res = null;
- Collection editModelResources = EditModelRegistry.getInstance().getEditModelResources(getEditModelID());
- Iterator iter = editModelResources.iterator();
- while (iter.hasNext()) {
- res = (EditModelResource) iter.next();
- addEditModelResource(res);
- }
- Collection resourceExtensions = EditModelRegistry.getInstance().getEditModelExtensions(getEditModelID());
- /* bug 170690 - initialize knownResourceExtensions if necessary, and change reference from iter to it */
- if (knownResourceExtensions == null)
- {
- knownResourceExtensions = new ArrayList();
- }
- if (!resourceExtensions.isEmpty())
- {
- knownResourceExtensions.addAll(resourceExtensions);
- Iterator it = resourceExtensions.iterator();
- ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getEmfContext().getResourceSet().getSynchronizer();
- while (it.hasNext()) {
- sync.enableAutoload(it.next().toString());
- }
- }
- }
-
- private void addEditModelResource(EditModelResource res) {
- boolean enabled = false;
- try {
- if (res.isCore()) {
- enabled = true;
- } else {
- IEnablementIdentifier identifier = res.getEnablementIdentifier(getProject());
- registerInterest(identifier, res);
- enabled = identifier.isEnabled();
- }
- } catch (RuntimeException re) {
- Logger.getLogger().logWarning(re);
- }
- if (enabled) {
- URI uri = res.getURI();
- knownResourceUris.add(uri);
- if (res.isAutoLoad()) {
- ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getEmfContext().getResourceSet().getSynchronizer();
- sync.enableAutoload(uri);
- preloadResourceUris.add(uri);
- }
- }
- }
-
- /**
- * @param res
- */
- private void registerInterest(IEnablementIdentifier identifier, EditModelResource res) {
- getEditModelResources(identifier).add(res);
- }
-
- private List getEditModelResources(IEnablementIdentifier identifier) {
- if (resourceIdentifiers == null)
- resourceIdentifiers = new HashMap();
- List tResources = (List) resourceIdentifiers.get(identifier);
- if (tResources == null) {
- tResources = new ArrayList(3);
- resourceIdentifiers.put(identifier, tResources);
- identifier.addIdentifierListener(this);
- }
- return tResources;
- }
-
-
-
- public java.util.List getKnownResourceUris() {
- if (knownResourceUris == null)
- initializeKnownResourceUris();
-
- return knownResourceUris;
- }
-
- public boolean isShared() {
- return registry.size() > 1;
- }
-
- /**
- * @see ResourceStateInputProvider#cacheNonResourceValidateState(List)
- */
- public void cacheNonResourceValidateState(List roNonResourceFiles) {
- // do nothing
- }
-
- /**
- * @see ResourceStateInputProvider#getNonResourceFiles()
- */
- public List getNonResourceFiles() {
- return null;
- }
-
- /**
- * @see ResourceStateInputProvider#getNonResourceInconsistentFiles()
- */
- public List getNonResourceInconsistentFiles() {
- return null;
- }
-
- /**
- * Gets the stateValidator.
- *
- * @return Returns a ResourceStateValidator
- */
- public ResourceStateValidator getStateValidator() {
- if (stateValidator == null)
- stateValidator = createStateValidator();
- return stateValidator;
- }
-
- /**
- * Method createStateValidator.
- *
- * @return ResourceStateValidator
- */
- private ResourceStateValidator createStateValidator() {
- return new ResourceStateValidatorImpl(this);
- }
-
- /**
- * @see ResourceStateValidator#checkActivation(ResourceStateValidatorPresenter)
- */
- public void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
- getStateValidator().checkActivation(presenter);
- }
-
- /**
- * @see ResourceStateValidator#lostActivation(ResourceStateValidatorPresenter)
- */
- public void lostActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
- getStateValidator().lostActivation(presenter);
- }
-
- /**
- * @see ResourceStateValidator#validateState(ResourceStateValidatorPresenter)
- */
- public IStatus validateState(ResourceStateValidatorPresenter presenter) throws CoreException {
- if (presenter == null)
- return Status.OK_STATUS;
- return getStateValidator().validateState(presenter);
- }
-
- /**
- * @see ResourceStateValidator#checkSave(ResourceStateValidatorPresenter)
- */
- public boolean checkSave(ResourceStateValidatorPresenter presenter) throws CoreException {
- return getStateValidator().checkSave(presenter);
- }
-
- /**
- * @see ResourceStateValidator#checkReadOnly()
- */
- public boolean checkReadOnly() {
- return getStateValidator().checkReadOnly();
- }
-
- /**
- * Return the ResourceSet from the Nature.
- *
- * @return org.eclipse.emf.ecore.resource.ResourceSet
- */
- public ResourceSet getResourceSet() {
- ResourceSet resourceSet = null;
- if (getEmfContext() != null)
- resourceSet = getEmfContext().getResourceSet();
- return resourceSet;
- }
-
- protected void resourceIsLoadedChanged(Resource aResource, boolean oldValue, boolean newValue) {
- if (!isReverting && !disposing && hasListeners()) {
- int eventCode = newValue ? EditModelEvent.LOADED_RESOURCE : EditModelEvent.UNLOADED_RESOURCE;
- EditModelEvent evt = new EditModelEvent(eventCode, this);
- evt.addResource(aResource);
- notifyListeners(evt);
- }
- }
-
- public Resource getResource(URI aUri) {
- Resource res = getAndLoadLocalResource(aUri);
- if (res == null)
- res = WorkbenchResourceHelper.getOrCreateResource(aUri, getResourceSet());
- if (res != null)
- processResource(res);
- return res;
- }
-
- protected void processResource(Resource aResource) {
- if (aResource != null && !getResources().contains(aResource)) {
- if (aResource instanceof ReferencedResource) {
- access((ReferencedResource) aResource);
- // We need a better way to pass this through the save options instead.
- // We also need to make this dynamic based on the project target
- ((ReferencedResource) aResource).setFormat(CompatibilityXMIResource.FORMAT_MOF5);
- } else if (aResource instanceof CompatibilityXMIResource) {
- ((CompatibilityXMIResource) aResource).setFormat(CompatibilityXMIResource.FORMAT_MOF5);
- }
-
- addResource(aResource);
- }
- }
-
- protected void addResource(Resource aResource) {
- getResources().add(aResource);
- aResource.eAdapters().add(resourceAdapter);
- }
-
- /**
- * Return a Resource for
- *
- * @aUri.
- */
- // TODO The following method will only use the last segment when looking for a resource.
- protected Resource getResource(List tResources, URI aUri) {
- Resource resource;
- for (int i = 0; i < tResources.size(); i++) {
- resource = (Resource) tResources.get(i);
- if (ExtendedEcoreUtil.endsWith(resource.getURI(), aUri))
- return resource;
- }
- return null;
- }
-
- public Resource createResource(URI uri) {
- Resource resource = getExistingOrCreateResource(uri);
- processResource(resource);
- return resource;
- }
-
- /**
- * Get a cached Resource, either local or in the ResourceSet, before creating a Resource. This
- * api handles the case that the Resource may be created during a demand load that failed.
- */
- public Resource getExistingOrCreateResource(URI uri) {
- Resource res = getAndLoadLocalResource(uri);
- if (res == null)
- res = WorkbenchResourceHelperBase.getExistingOrCreateResource(uri, getResourceSet());
- return res;
- }
-
- /**
- * Return a Resource for
- *
- * @aUri.
- */
- protected Resource getAndLoadLocalResource(URI aUri) {
- Resource resource = getLocalResource(aUri);
- if (null != resource && !resource.isLoaded()) {
- try {
- resource.load(Collections.EMPTY_MAP); // reload it
- } catch (IOException e) {
- // Ignore
- }
- }
- return resource;
- }
-
- /**
- * Return a Resource for
- *
- * @aUri.
- */
- protected Resource getLocalResource(URI aUri) {
- return getResource(getResources(), aUri);
- }
-
- /*
- * Return true if this is a ReadOnly EditModel or if we should only access unknown URIs as
- * ReadOnly.
- */
- protected boolean shouldAccessForRead(ReferencedResource aResource) {
- return isReadOnly() || (accessAsReadForUnKnownURIs && !isInterrestedInResource(aResource));
- }
-
- /**
- * Save only resources that need to be saved (i.e., no other references).
- */
- public void resourceChanged(EditModelEvent anEvent) {
- int code = anEvent.getEventCode();
- switch (code) {
- case EditModelEvent.REMOVED_RESOURCE : {
- if (!isReverting && hasResourceReference(anEvent.getChangedResources()))
- removeResources(anEvent.getChangedResources());
- else
- return;
- break;
- }
- case EditModelEvent.ADDED_RESOURCE :
- if (!processResourcesIfInterrested(anEvent.getChangedResources()))
- return;
- }
- if (hasListeners()) {
- anEvent.setEditModel(this);
- notifyListeners(anEvent);
- }
- }
-
- /**
- * Return true if aResource is referenced by me.
- */
- protected boolean hasResourceReference(Resource aResource) {
- if (aResource != null)
- return getResources().contains(aResource);
- return false;
- }
-
- /**
- * Return true if any Resource in the list of
- *
- * @resources is referenced by me.
- */
- protected boolean hasResourceReference(List tResources) {
- for (int i = 0; i < tResources.size(); i++) {
- if (hasResourceReference((Resource) tResources.get(i)))
- return true;
- }
- return false;
- }
-
- /**
- * Remove reference to the Resource objects in
- *
- * @aList. This should be called when one or more Resource objects are removed from the
- * ResourceSet without the reference count going to zero.
- */
- protected void removeResources(List aList) {
- Resource res;
- for (int i = 0; i < aList.size(); i++) {
- res = (Resource) aList.get(i);
- if (removeResource(res) && res instanceof ReferencedResource)
- removedResource((ReferencedResource) res);
- }
- }
-
- private final void removedResource(ReferencedResource referencedResource) {
- if (!isReadOnly() && referencedResource.wasReverted()) {
- isReverting = true;
- try {
- reverted(referencedResource);
- } finally {
- isReverting = false;
- }
- }
- }
-
- protected boolean removeResource(URI uri) {
- Resource res = getLocalResource(uri);
- return removeResource(res);
- }
-
- /**
- * Remove reference to the aResource.
- */
- protected boolean removeResource(Resource aResource) {
- if (aResource != null) {
- aResource.eAdapters().remove(resourceAdapter);
- return getResources().remove(aResource);
- }
- return false;
- }
-
- /**
- * Subclasses should override to post process a removed ReferencedResource.
- *
- * @see J2EEEditModel#revertAllResources()
- */
- protected void reverted(ReferencedResource revertedResource) {
- revertAllResources();
- }
-
- protected void revertAllResources() {
- List someResources = getSortedResources();
- for (int i = 0; i < someResources.size(); i++)
- ((Resource) someResources.get(i)).unload();
- getResources().removeAll(someResources);
- for (int i = 0; i < someResources.size(); i++)
- ((Resource) someResources.get(i)).eAdapters().remove(resourceAdapter);
- }
-
- /**
- * group the resources by XMI first, then XML
- */
- protected List getSortedResources() {
-
- List theResources = getResources();
- int size = theResources.size();
- if (size == 0)
- return Collections.EMPTY_LIST;
- Resource[] sorted = new Resource[size];
- int xmlInsertPos = size - 1;
- int xmiInsertPos = 0;
- Resource res = null;
- for (int i = 0; i < size; i++) {
- res = (Resource) theResources.get(i);
- if (res instanceof TranslatorResource)
- sorted[xmlInsertPos--] = res;
- else
- sorted[xmiInsertPos++] = res;
- }
-
- return Arrays.asList(sorted);
- }
-
- /**
- * Process Resources that we are interrested in.
- */
- protected boolean processResourcesIfInterrested(List someResources) {
- int size = someResources.size();
- Resource res;
- boolean processed = false;
- for (int i = 0; i < size; i++) {
- res = (Resource) someResources.get(i);
- if ((res != null) && (isInterrestedInResource(res))) {
- processResource(res);
- processed = true;
- }
- }
- return processed;
- }
-
- public EMFWorkbenchContext getEmfContext() {
- if (isDisposed())
- throw new IllegalStateException("Edit Model already disposed"); //$NON-NLS-1$
- if (emfContext == null)
- throw new IllegalStateException("EMF context is null"); //$NON-NLS-1$
- return emfContext;
- }
-
- public boolean isDisposed() {
- return disposed;
- }
-
-
-
- public IProject getProject() {
- return project;
- }
-
- /**
- * This method should only be called by the EMFWorkbenchContext.
- */
- public void access(Object accessorKey) {
- registry.access(accessorKey);
- }
-
- /**
- * Access
- *
- * @aResource for read or write.
- */
- protected void access(ReferencedResource aResource) {
- if (shouldAccessForRead(aResource))
- aResource.accessForRead();
- else
- aResource.accessForWrite();
- }
-
- /**
- * This method should be called from each client when they are finished working with the
- * EditModel.
- */
- public void releaseAccess(Object accessorKey) {
-
- registry.release(accessorKey);
-
- if (!isDisposing()) {
- boolean shouldDispose = false;
- shouldDispose = registry.size() == 0;
- if (shouldDispose) {
- dispose();
- }
- }
- }
-
- /**
- * Release each of the referenced resources.
- */
- protected void release(Resource aResource) {
-
- removeResource(aResource);
- if (aResource != null && aResource instanceof ReferencedResource)
- release((ReferencedResource) aResource);
- }
-
- /**
- * Release each of the referenced resources.
- */
- protected void release(ReferencedResource aResource) {
- if (isReadOnly())
- aResource.releaseFromRead();
- else
- aResource.releaseFromWrite();
-
- }
-
- /**
- * Release each of the referenced resources.
- */
- protected void releaseResources() {
- List tResources = getSortedResources();
- Resource resource;
- for (int i = 0; i < tResources.size(); i++) {
- resource = (Resource) tResources.get(i);
- release(resource);
- }
- }
-
- public void deleteResource(Resource aResource) {
- if (aResource == null || resources == null || !getResources().contains(aResource))
- return;
- getResourcesTargetedForTermination().add(aResource);
-
- }
-
- /**
- * @return
- */
- protected List getResourcesTargetedForTermination() {
- if (resourcesTargetedForTermination == null)
- resourcesTargetedForTermination = new ArrayList(5);
- return resourcesTargetedForTermination;
- }
-
-
-
- /**
- * Remove my reference to aResource, remove it from the ResourceSet, and delete its file from
- * the Workbench. This only happens if there is currently a reference to
- *
- * @aResource.
- */
- public void primDeleteResource(Resource aResource) {
- if (primFlushResource(aResource)) {
- try {
- getEmfContext().deleteResource(aResource);
- } catch (CoreException e) {
- // what should we do here?
- }
- if (hasListeners()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.REMOVED_RESOURCE, this);
- event.addResource(aResource);
- notifyListeners(event);
- }
- }
- }
-
- /**
- * Remove my reference to aResource and remove it from the ResourceSet.
- */
- public void flushResource(Resource aResource) {
- if (primFlushResource(aResource)) {
- if (hasListeners()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.REMOVED_RESOURCE, this);
- event.addResource(aResource);
- notifyListeners(event);
- }
- }
- }
-
- public Set getAffectedFiles() {
- Set aSet = new HashSet();
- List mofResources = getResources();
- for (int i = 0; i < mofResources.size(); i++) {
- Resource aResource = (Resource) mofResources.get(i);
- IFile output = WorkbenchResourceHelper.getFile(aResource);
- if (output != null)
- aSet.add(output);
- }
- return aSet;
- }
-
- protected List resetKnownResourceUris() {
-
- initializeKnownResourceUris();
-
- return knownResourceUris;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/11/2001 4:14:26 PM)
- *
- * @return java.util.List
- */
- public List getResources() {
- if (resources == null)
- resources = new ArrayList(5);
- return resources;
- }
-
- public String[] getResourceURIs() {
- return getResourceURIs(false);
- }
-
- public String[] getResourceURIs(boolean onlyDirty) {
- List list = getResources();
- int dirtyCount = 0;
- String[] uris = new String[list.size()];
- Resource res;
- for (int i = 0; i < list.size(); i++) {
- res = (Resource) list.get(i);
- if (!onlyDirty)
- uris[i] = res.getURI().toString();
- else if (res.isModified()) {
- uris[i] = res.getURI().toString();
- dirtyCount++;
- }
- }
- if (onlyDirty && dirtyCount > 0) {
- String[] dirty = new String[dirtyCount];
- int j = 0;
- for (int i = 0; i < uris.length; i++) {
- if (uris[i] != null) {
- dirty[j] = uris[i];
- j++;
- }
- }
- uris = dirty;
- }
- return uris;
- }
-
- /**
- * Returns the first element in the extent of the resource; logs an error and returns null if
- * the extent is empty
- */
- public static EObject getRoot(Resource aResource) {
- EList extent = aResource.getContents();
- if (extent.size() < 1)
- return null;
- return (EObject) extent.get(0);
- }
-
- /**
- * Handle the failure of
- *
- * @aResource.
- */
- protected void handleSaveFailed(Resource aResource, Exception e) {
- aResource.setModified(true);
- if (isFailedWriteFileFailure(e) && shouldSaveReadOnly(aResource))
- saveResource(aResource);
- else
- primHandleSaveFailed(aResource, e);
- }
-
- /**
- * Return whether any of my resources has been modified.
- */
- protected boolean isAnyResourceDirty() {
- List list = getResources();
- for (int i = 0; i < list.size(); i++) {
- if (((Resource) list.get(i)).isModified())
- return true;
- }
- return false;
- }
-
- /**
- * Return whether a save is needed on the CommandStack
- */
- public boolean isDirty() {
- return isAnyResourceDirty();
- }
-
- protected boolean isFailedWriteFileFailure(Exception ex) {
- return SaveHandlerHeadless.isFailedWriteFileFailure(ex);
- }
-
- /**
- * Return true if you can only read the resources and not write.
- */
- public boolean isReadOnly() {
- return readOnly;
- }
-
- protected boolean isReadOnlyFailure(Exception ex) {
- return false;
- }
-
- public boolean hasReadOnlyResource() {
- try {
- List list = getResources();
- int size = list.size();
- Resource res = null;
- IFile file;
- for (int i = 0; i < size; i++) {
- res = (Resource) list.get(i);
- file = WorkbenchResourceHelper.getFile(res);
- if (file != null && file.isReadOnly())
- return true;
- }
- } catch (NullPointerException e) {
- System.out.println(e);
- }
- return false;
- }
-
- /**
- * @deprecated use createResource(URI) instead
- */
- public Resource makeResource(String aUri) {
- return createResource(URI.createURI(aUri));
- }
-
- /**
- * Return whether any of my resources has a reference count of one and it has been modified.
- */
- public boolean needsToSave() {
- return !isShared() && isDirty();
- }
-
- /**
- * Remove my reference to aResource and remove it from the ResourceSet. Return true if aResource
- * was removed.
- */
- protected boolean primFlushResource(Resource aResource) {
- if (aResource != null && hasResourceReference(aResource)) {
- removeResource(aResource);
- removeResourceSetResource(aResource);
- return true;
- }
- return false;
- }
-
- /**
- * Handle the failure of
- *
- * @aResource.
- */
- protected void primHandleSaveFailed(Resource aResource, Exception e) {
- org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(e);
- Exception nested = null;
- if (e instanceof IWFTWrappedException)
- nested = ((IWFTWrappedException) e).getNestedException();
- else
- nested = e;
-
- throw new SaveFailedException(EMFWorkbenchResourceHandler.getString("An_error_occurred_while_sa_ERROR_"), nested); //$NON-NLS-1$ = "An error occurred while saving."
- }
-
- /**
- * Prompt for a save.
- */
- protected boolean promptToSave(IOperationHandler operationHandler) {
- if (operationHandler == null)
- return false;
- return operationHandler.canContinue(EMFWorkbenchResourceHandler.getString("The_following_resources_ne_UI_"), getResourceURIs(true)); //$NON-NLS-1$ = "The following resources need to be saved but are currently shared, do you want to save now?"
- }
-
- /**
- * This will force all of the referenced Resources to be saved.
- */
- public void primSave(IProgressMonitor monitor) {
- if (isReadOnly())
- return; // do nothing
- deleteResourcesIfNecessary();
- Resource resource;
- if (getResources().isEmpty())
- return; // nothing to save
- List localResources = getSortedResources();
- for (int i = 0; i < localResources.size(); i++) {
- resource = (Resource) localResources.get(i);
- saveResource(resource);
- }
- getCommandStack().saveIsDone();
- if (hasListeners()) {
- EditModelEvent event = new EditModelEvent(EditModelEvent.SAVE, this);
- notifyListeners(event);
- }
- }
-
- /**
- *
- */
- protected void deleteResourcesIfNecessary() {
- if (resourcesTargetedForTermination == null || resourcesTargetedForTermination.size() == 0)
- return;
- Resource deadres = null;
- for (int i = 0; i < getResourcesTargetedForTermination().size(); i++) {
- deadres = (Resource) getResourcesTargetedForTermination().get(i);
- primDeleteResource(deadres);
-
- getResources().remove(deadres);
- getResourcesTargetedForTermination().remove(deadres);
- }
- }
-
-
-
- /**
- * Save
- *
- * @aResource.
- */
- protected void primSaveResource(Resource aResource) throws Exception {
- if (aResource.isModified())
- aResource.save(Collections.EMPTY_MAP);
- }
-
- /**
- * Process resources that have already been loaded.
- */
- protected void processLoadedResources() {
- List loaded = getResourceSet().getResources();
- if (!loaded.isEmpty())
- processResourcesIfInterrested(loaded);
- }
-
- private void processPreloadResources() {
- for (int i = 0; i < preloadResourceUris.size(); i++) {
- URI uri = (URI) preloadResourceUris.get(i);
- getResource(uri);
- }
- }
-
- /**
- * Remove aResource from my ResourceSet. Return true if aResource was removed.
- */
- protected boolean removeResourceSetResource(Resource aResource) {
- aResource.eSetDeliver(false);
- aResource.unload();
- aResource.eSetDeliver(true);
- return getResourceSet().getResources().remove(aResource);
- }
-
- protected void saveResource(Resource resource) {
- try {
- primSaveResource(resource);
- } catch (Exception e) {
- handleSaveFailed(resource, e);
- }
- }
-
- /**
- * Should the resources be saved.
- */
- protected boolean shouldSave() {
- return !isReadOnly() && !isShared();
- }
-
- /**
- * Should the resources be saved.
- */
- protected boolean shouldSave(IOperationHandler operationHandler) {
- return shouldSave() || promptToSave(operationHandler);
- }
-
- protected boolean shouldSaveReadOnly(Resource aResource) {
- IFile aFile = WorkbenchResourceHelper.getFile(aResource);
- if (aFile == null || !aFile.isReadOnly())
- return false;
-
- return getSaveHandler().shouldContinueAndMakeFileEditable(aFile);
- }
-
- /**
- * Force all of the known resource URIs to be loaded if they are not already.
- */
- public void forceLoadKnownResources() {
- List uris = getKnownResourceUris();
- URI uri = null;
- for (int i = 0; i < uris.size(); i++) {
- uri = (URI) uris.get(i);
- getResource(uri);
- }
- }
-
- /**
- * This method should be called when you want to extend this edit model to handle a resource
- * with a URI equal to <code>aRelativeURI</code>.
- */
- public void manageExtensionResourceURI(String aRelativeURI) {
- if (aRelativeURI != null && aRelativeURI.length() > 0) {
- URI uri = URI.createURI(aRelativeURI);
- if (!isInterrestedInResourceUri(uri)) {
- getKnownResourceUris().add(uri);
- // Process the resource if it is already loaded.
- try {
- Resource res = getEmfContext().getResource(uri);
- if (res != null)
- processResource(res);
- } catch (Exception e) {
- // Ignore
- }
- }
- }
- }
-
- /**
- * Get a cached Resource or try to load the Resource prior to creating a Resource. This api
- * handles the case that the Resource may be created during the load.
- */
- public Resource getOrCreateResource(URI uri) {
- return getResource(uri);
- }
-
- /**
- * @return boolean
- */
- public boolean isAccessAsReadForUnKnownURIs() {
- return accessAsReadForUnKnownURIs;
- }
-
- /**
- * Use this api to indicate that you want all unknown Resources to be accessed for ReadOnly.
- *
- * @param b
- */
- public void setAccessAsReadForUnKnownURIs(boolean b) {
- accessAsReadForUnKnownURIs = b;
- }
-
- public String toString() {
- StringBuffer buffer = new StringBuffer(getClass().getName());
- buffer.append(": "); //$NON-NLS-1$
- if (isReadOnly())
- buffer.append(" R = "); //$NON-NLS-1$
- else
- buffer.append(" W = "); //$NON-NLS-1$
- buffer.append(getRegistry().size());
- buffer.append("[ID: \""); //$NON-NLS-1$
- buffer.append(getEditModelID());
- buffer.append("\" Known Resources: ["); //$NON-NLS-1$
- List uris = getKnownResourceUris();
- if (uris != null) {
- int i = 0;
- for (i = 0; i < (uris.size() - 1); i++)
- buffer.append(uris.get(i) + ", "); //$NON-NLS-1$
- buffer.append(uris.get(i));
- buffer.append("]"); //$NON-NLS-1$
- } else
- buffer.append("none"); //$NON-NLS-1$
-
-
- buffer.append("]"); //$NON-NLS-1$
- return buffer.toString();
- }
-
- public Reference getReference() {
- if (reference == null)
- reference = new Reference();
- return reference;
- }
-
- /**
- * @return
- */
- protected ClientAccessRegistry getRegistry() {
- return registry;
- }
-
- public class Reference {
-
- protected String tostring = null;
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- if (tostring == null) {
- StringBuffer result = new StringBuffer("EditModel.Reference ["); //$NON-NLS-1$
- result.append("{"); //$NON-NLS-1$
- result.append(getEditModelID());
- result.append("} {"); //$NON-NLS-1$
- result.append(getProject().getName());
- result.append("}]"); //$NON-NLS-1$
- tostring = result.toString();
- }
- return tostring;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return toString().hashCode();
- }
- }
-
- /**
- * Subclasses can override - by default this will return the first root object from the first
- * resource referenced by the known resource URIs for this EditModel
- *
- * @return an EObject or Null
- */
- public EObject getPrimaryRootObject() {
- Resource res = getPrimaryResource();
- if (res == null || res.getContents().isEmpty())
- return null;
- return (EObject) res.getContents().get(0);
- }
-
- /**
- * Subclasses can override - by default this will return the first resource referenced by the
- * known resource URIs for this EditModel
- *
- * @return
- */
- public Resource getPrimaryResource() {
- if (knownResourceUris == null)
- getKnownResourceUris();
- if (knownResourceUris == null || knownResourceUris.isEmpty())
- return null;
-
- URI uri = (URI) knownResourceUris.get(0);
- return getResource(uri);
- }
-
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener#identifierChanged(org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent)
- */
- public void identifierChanged(EnablementIdentifierEvent evt) {
- if (evt.hasEnabledChanged()) {
- EditModelEvent editModelEvent = new EditModelEvent(EditModelEvent.KNOWN_RESOURCES_ABOUT_TO_CHANGE, this);
- notifyListeners(editModelEvent);
- IEnablementIdentifier id = evt.getIdentifier();
- if (id.isEnabled())
- addKnownResources(id);
- else
- removeKnownResources(id);
- editModelEvent = new EditModelEvent(EditModelEvent.KNOWN_RESOURCES_CHANGED, this);
- notifyListeners(editModelEvent);
- }
- }
-
- private void removeKnownResources(IEnablementIdentifier id) {
- List editModelResources = getEditModelResources(id);
- EditModelResource editModelResource = null;
- ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getResourceSetSynchronizer();
- for (int i = 0; i < editModelResources.size(); i++) {
- editModelResource = (EditModelResource) editModelResources.get(i);
- if (editModelResource.isAutoLoad() && sync != null) {
- sync.disableAutoload(editModelResource.getURI());
- preloadResourceUris.remove(editModelResource.getURI());
- }
- knownResourceUris.remove(editModelResource.getURI());
- removeResource(editModelResource.getURI());
- }
-
- }
-
-
-
- private void addKnownResources(IEnablementIdentifier id) {
- List editModelResources = getEditModelResources(id);
- EditModelResource editModelResource = null;
- ResourceSetWorkbenchEditSynchronizer sync = (ResourceSetWorkbenchEditSynchronizer) getResourceSetSynchronizer();
- for (int i = 0; i < editModelResources.size(); i++) {
- editModelResource = (EditModelResource) editModelResources.get(i);
- if (editModelResource.isAutoLoad() && sync != null) {
- sync.enableAutoload(editModelResource.getURI());
- preloadResourceUris.add(editModelResource.getURI());
- getResource(editModelResource.getURI());
- }
- knownResourceUris.add(editModelResource.getURI());
-
- }
- }
-
-
- /**
- * @return Returns the params.
- */
- public Map getParams() {
- return params;
- }
-
- /**
- * @param params
- * The params to set.
- */
- public void setParams(Map params) {
- this.params = params;
- }
-
- public class NotifyRunner implements ISafeRunnable {
-
- private final EditModelEvent event;
- private EditModelListener listener;
-
- public NotifyRunner(EditModelEvent event) {
- Assert.isNotNull(event);
- this.event = event;
- }
-
-
- public void setListener(EditModelListener listener) {
- this.listener = listener;
- }
-
- public void handleException(Throwable exception) {
- EMFWorkbenchEditPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, EMFWorkbenchEditPlugin.ID, 0, exception.getMessage(), exception));
-
- }
-
- public void run() throws Exception {
- if(listener != null)
- listener.editModelChanged(event);
- }
-
- };
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelCommand.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelCommand.java
deleted file mode 100644
index 00eed906e..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelCommand.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.emf.common.command.Command;
-
-
-
-/**
- * Insert the type's description here. Creation date: (05/22/01 8:57:00 AM)
- *
- * @author: Administrator
- */
-public abstract class EditModelCommand extends AbstractEditModelCommand {
- protected EditModelCommand() {
- super();
- }
-
- public EditModelCommand(Command targetCommand) {
- super(targetCommand);
- }
-
- public boolean canUndo() {
- return getTarget().canUndo();
- }
-
- protected abstract void executeInModel(AbstractEditModelCommand cmd);
-
- public EditModelCommand getEditModelCommand() {
- return this;
- }
-
- public String getLabel() {
- return getTarget().getLabel();
- }
-
- public void invertAndPush() {
- executeInModel(this.inverted());
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelEvent.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelEvent.java
deleted file mode 100644
index 460a84acb..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelEvent.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.ecore.resource.Resource;
-
-public class EditModelEvent {
- //These are the event codes.
-
- // Used when the edit model is saved.
- public static final int SAVE = 1;
- // Used when the command stack becomes dirty.
- public static final int DIRTY = 2;
- // Used when a referenced resource is removed from the ResourceSet.
- public static final int REMOVED_RESOURCE = 3;
- // Used when a referenced resource is added to the ResourceSet.
- public static final int ADDED_RESOURCE = 4;
- // Used when the edit model is disposed
- public static final int PRE_DISPOSE = 5;
- // Used when a Resource is loaded or the first object
- // is added to the contents when created.
- public static final int LOADED_RESOURCE = 6;
- // Used when a Resource is unloaded.
- public static final int UNLOADED_RESOURCE = 7;
- // Indicates that the list of known resources managed by the edit model is about to change
- public static final int KNOWN_RESOURCES_ABOUT_TO_CHANGE = 8;
- // Indicates that the list of known resources managed by the edit model has changed
- public static final int KNOWN_RESOURCES_CHANGED = 9;
-
- private int eventCode;
- private EditModel editModel;
- private List changedResources;
-
- /**
- * Insert the method's description here. Creation date: (4/12/2001 2:46:59 PM)
- */
- public EditModelEvent(int anEventCode, EditModel model) {
- setEventCode(anEventCode);
- setEditModel(model);
- }
-
- public void addResource(Resource aResource) {
- if (aResource != null)
- getChangedResources().add(aResource);
- }
-
- public void addResources(Collection someResources) {
- if (someResources != null)
- getChangedResources().addAll(someResources);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/12/2001 2:46:43 PM)
- *
- * @return java.util.List
- */
- public java.util.List getChangedResources() {
- if (changedResources == null)
- changedResources = new ArrayList();
- return changedResources;
- }
-
- /**
- * Insert the method's description here. Creation date: (05/21/01 9:01:08 PM)
- *
- * @return com.ibm.etools.j2ee.workbench.EditModel
- */
- public EditModel getEditModel() {
- return editModel;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/12/2001 2:46:43 PM)
- *
- * @return int
- */
- public int getEventCode() {
- return eventCode;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/12/2001 2:46:43 PM)
- *
- * @param newChangedResources
- * java.util.List
- */
- public void setChangedResources(java.util.List newChangedResources) {
- changedResources = newChangedResources;
- }
-
- /**
- * Insert the method's description here. Creation date: (05/21/01 9:01:08 PM)
- *
- * @param newEditModel
- * com.ibm.etools.j2ee.workbench.EditModel
- */
- public void setEditModel(EditModel newEditModel) {
- editModel = newEditModel;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/12/2001 2:46:43 PM)
- *
- * @param newEventCode
- * int
- */
- public void setEventCode(int newEventCode) {
- eventCode = newEventCode;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelFactory.java
deleted file mode 100644
index d97bbe447..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelFactory.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-import java.util.Map;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-
-
-public class EditModelFactory implements IEditModelFactory {
- protected boolean loadKnownResourcesAsReadOnly = true;
-
- public EditModel createEditModelForRead(String editModelID, EMFWorkbenchContext context) {
- return createEditModelForRead(editModelID, context, null);
- }
-
- public EditModel createEditModelForWrite(String editModelID, EMFWorkbenchContext context) {
- return createEditModelForWrite(editModelID, context, null);
- }
-
- public EditModel createEditModelForRead(String editModelID, EMFWorkbenchContext context, Map params) {
- EditModel editModel = new EditModel(editModelID, context, true);
- editModel.setAccessAsReadForUnKnownURIs(loadKnownResourcesAsReadOnly);
- return editModel;
- }
-
- public EditModel createEditModelForWrite(String editModelID, EMFWorkbenchContext context, Map params) {
- EditModel editModel = new EditModel(editModelID, context, false);
- editModel.setAccessAsReadForUnKnownURIs(loadKnownResourcesAsReadOnly);
- return editModel;
- }
-
- public String getCacheID(String editModelID, Map params) {
- return editModelID;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.integration.IEditModelFactory#setLoadKnownResourcesAsReadOnly(boolean)
- */
- public void setLoadKnownResourcesAsReadOnly(boolean value) {
- this.loadKnownResourcesAsReadOnly = value;
- }
-
- /**
- * @return Returns the loadKnownResourcesAsReadOnly.
- */
- protected boolean isLoadKnownResourcesAsReadOnly() {
- return loadKnownResourcesAsReadOnly;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelListener.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelListener.java
deleted file mode 100644
index aefe9e49d..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-/**
- * Insert the type's description here. Creation date: (4/11/2001 4:45:13 PM)
- *
- * @author: Administrator
- */
-public interface EditModelListener {
- /**
- * An event ocurred on the J2EEEditModel.
- */
- void editModelChanged(EditModelEvent anEvent);
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelNature.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelNature.java
deleted file mode 100644
index f80a886b9..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/EditModelNature.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 4, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.Map;
-
-import org.eclipse.jem.util.emf.workbench.nature.EMFNature;
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public abstract class EditModelNature extends EMFNature {
- /**
- *
- */
- public EditModelNature() {
- super();
- }
-
- public EditModel getEditModelForRead(String editModelKey, Object accessorKey) {
- return getEditModelForRead(editModelKey, accessorKey, null);
- }
-
- public EditModel getEditModelForWrite(String editModelKey, Object accessorKey) {
- return getEditModelForWrite(editModelKey, accessorKey, null);
- }
-
- public EditModel getEditModelForRead(String editModelKey, Object accessorKey, Map params) {
- EditModel result = null;
- if (getEmfContext() != null)
- result = getEmfContext().getEditModelForRead(editModelKey, accessorKey, params);
- return result;
- }
-
- public EditModel getEditModelForWrite(String editModelKey, Object accessorKey, Map params) {
- EditModel result = null;
- if (getEmfContext() != null)
- result = getEmfContext().getEditModelForWrite(editModelKey, accessorKey, params);
- return result;
- }
-
- protected EMFWorkbenchContext getEmfContext() {
- return (EMFWorkbenchContext) getEmfContextBase();
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/IEditModelFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/IEditModelFactory.java
deleted file mode 100644
index 873209f5b..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/IEditModelFactory.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.Map;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-
-
-public interface IEditModelFactory {
-
- public abstract EditModel createEditModelForRead(String editModelID, EMFWorkbenchContext context);
-
- public abstract EditModel createEditModelForRead(String editModelID, EMFWorkbenchContext context, Map params);
-
- public abstract EditModel createEditModelForWrite(String editModelID, EMFWorkbenchContext context);
-
- public abstract EditModel createEditModelForWrite(String editModelID, EMFWorkbenchContext context, Map params);
-
- public String getCacheID(String editModelID, Map params);
-
- public void setLoadKnownResourcesAsReadOnly(boolean value);
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/LooseComposedEditModel.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/LooseComposedEditModel.java
deleted file mode 100644
index f9a5f82a2..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/LooseComposedEditModel.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
-
-
-/**
- * @author Administrator
- */
-public class LooseComposedEditModel extends ComposedEditModel {
-
- public LooseComposedEditModel(String editModelID, EMFWorkbenchContext context) {
- super(editModelID, context);
-
- }
-
- public EditModel.Reference addChild(EditModel editModel) {
- getChildren().add(editModel);
- Reference ref = editModel.getReference();
- getChildrenMap().put(ref, editModel);
- return ref;
- }
-
- public void removeChild(EditModel editModel) {
- getChildren().remove(editModel);
- getChildrenMap().remove(editModel.getReference());
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModelModifier.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModelModifier.java
deleted file mode 100644
index 53d88ec79..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModelModifier.java
+++ /dev/null
@@ -1,615 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.RemoveCommand;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.wst.common.internal.emf.utilities.ExtendedEcoreUtil;
-
-/**
- * Insert the type's description here. Creation date: (4/6/2001 3:40:35 PM)
- *
- * @author: Administrator
- */
-public class ModelModifier {
- private static final String SET_PATTERN = "Set {0}"; //$NON-NLS-1$
- private static final String ADD_PATTERN = "Add {0}"; //$NON-NLS-1$
- private static final String REMOVE_PATTERN = "Remove {0}"; //$NON-NLS-1$
- private static final String DEFAULT_COMMAND_LABEL = "Command"; //$NON-NLS-1$
- private EditingDomain editingDomain;
- private List helpers;
- private List extendedHelpers;
- protected List additionalCommands;
- protected int status;
- public static final int NO_VALUE_CHANGE = 0;
- public static final int VALUE_CHANGE = 1;
- public static final int ERROR = 2;
-
- /**
- * J2EEModelModifier constructor comment.
- */
- public ModelModifier() {
- super();
- }
-
- /**
- * J2EEModelModifier constructor comment.
- *
- * @param aDomain
- * EditingDomain
- */
- public ModelModifier(EditingDomain aDomain) {
- setEditingDomain(aDomain);
- }
-
- /**
- * Add
- *
- * @aHelper to the list of helper that will be executed.
- */
- public void addHelper(ModifierHelper aHelper) {
- if (aHelper != null && !getHelpers().contains(aHelper))
- getHelpers().add(aHelper);
- }
-
- public void addAdditionalCommand(Command aCommand) {
- if (aCommand != null && !getAdditionalCommands().contains(aCommand))
- additionalCommands.add(aCommand);
- }
-
- /**
- * Return true if this modifier can create a command that will perform the necessary operation.
- */
- public boolean canExecuteCommand() {
- return getEditingDomain() != null;
- }
-
- public int executeWithStatus() {
- try {
- execute();
- return status;
- } finally {
- status = -1;
- }
- }
-
- /**
- * Execute this modifier using the recording mechanism of the StructedTextUndoManager. If this
- * modifier cannot record, try to execute using the CommandStack (if it can execute commands).
- * Return true if the execution was attempted.
- *
- * @see canExecuteCommand()
- * @see canRecord()
- * @see run()
- */
- public boolean execute(ModifierHelper aHelper) {
- addHelper(aHelper);
- return execute();
- }
-
- /**
- * Execute this modifier using the recording mechanism of the StructedTextUndoManager. If this
- * modifier cannot record, try to execute using the CommandStack (if it can execute commands).
- * Return true if the execution was attempted.
- *
- * @see canExecuteCommand()
- * @see canRecord()
- * @see run()
- */
- public boolean execute(List someHelpers) {
- setHelpers(someHelpers);
- return execute();
- }
-
- /**
- * Execute this modifier by creating a Command that is executed on the CommandStack. If this
- * modifier cannot execute commands, the execution will not take place. Return true if the
- * execution was attempted.
- *
- * @see canExecuteCommand()
- */
- public boolean execute() {
- boolean result = false;
- if (canExecuteCommand()) {
- try {
- Command command = createCommand();
- result = command != null;
- if (result) {
- getCommandStack().execute(command);
- }
- } finally {
- release();
- }
- } else {
- setStatus(ERROR);
- }
- return result;
- }
-
- protected CommandStack getCommandStack() {
- if (getEditingDomain() != null)
- return getEditingDomain().getCommandStack();
- return null;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 2:53:17 PM)
- *
- * @return EditingDomain
- */
- public EditingDomain getEditingDomain() {
- return editingDomain;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/10/2001 8:46:35 AM)
- *
- * @return J2EEModifierHelper
- */
- public ModifierHelper getFirstHelper() {
- if (helpers != null && getHelpers().size() > 0)
- return (ModifierHelper) getHelpers().get(0);
- return null;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/10/2001 8:46:35 AM)
- *
- * @return java.util.List
- */
- public java.util.List getHelpers() {
- if (helpers == null)
- helpers = new ArrayList();
- return helpers;
- }
-
- public java.util.List getAdditionalCommands() {
- if (additionalCommands == null)
- additionalCommands = new ArrayList();
- return additionalCommands;
- }
-
- /**
- * Release all model artifacts.
- */
- protected void release() {
- setEditingDomain(null);
- setHelpers(null);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 2:53:17 PM)
- *
- * @param newEditingDomain
- * EditingDomain
- */
- public void setEditingDomain(EditingDomain newEditingDomain) {
- editingDomain = newEditingDomain;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/10/2001 8:46:35 AM)
- *
- * @param newHelpers
- * java.util.List
- */
- public void setHelpers(java.util.List newHelpers) {
- helpers = newHelpers;
- }
-
- protected void setStatus(int statusCode) {
- if (statusCode > status)
- status = statusCode;
- }
-
- /**
- * Return an AddCommand that will be executed by a CommandStack.
- */
- protected Command createAddCommand(ModifierHelper aHelper) {
- Object value = getValue(aHelper);
- Command command = null;
- if (valueChanged(aHelper.getOwner(), aHelper.getFeature(), value, false)) {
- command = AddCommand.create(getEditingDomain(), aHelper.getOwner(), aHelper.getFeature(), value);
- ((AbstractCommand) command).setLabel(createCommandLabel(ADD_PATTERN, aHelper.getFeature()));
- setStatus(VALUE_CHANGE);
- } else {
- setStatus(NO_VALUE_CHANGE);
- }
- return command;
- }
-
- /**
- * Return a Command that will be executed by a CommandStack. The default is to return null.
- * Subclasses should override this method.
- */
- public Command createCommand() {
- Command chainedCommand = createCommand(null, getHelpers());
- if (null == chainedCommand && additionalCommands != null && additionalCommands.isEmpty()) {
- setStatus(ERROR);
- return null;
- }
- chainedCommand = appendAdditionalCommands(chainedCommand);
- return chainedCommand;
- }
-
- protected Command createCommand(Command chainedCommand, List helpersArg) {
- if (null == extendedHelpers) {
- extendedHelpers = new ArrayList();
- }
-
- if (!helpersArg.isEmpty()) {
- Iterator it = helpersArg.iterator();
- Command nextCommand = null;
- while (it.hasNext()) {
- nextCommand = createCommand((ModifierHelper) it.next());
- if (chainedCommand == null)
- chainedCommand = nextCommand;
- else if (nextCommand != null)
- chainedCommand = chainedCommand.chain(nextCommand);
- }
- }
- if (!extendedHelpers.isEmpty()) {
- List copy = new ArrayList();
- copy.addAll(extendedHelpers);
- extendedHelpers.clear();
- chainedCommand = createCommand(chainedCommand, copy);
- }
- return chainedCommand;
- }
-
- protected Command appendAdditionalCommands(Command chainedCommand) {
- if (additionalCommands != null && !additionalCommands.isEmpty()) {
- Command command;
- for (int i = 0; i < additionalCommands.size(); i++) {
- command = (Command) additionalCommands.get(i);
- if (chainedCommand == null)
- chainedCommand = command;
- else
- chainedCommand = chainedCommand.chain(command);
- }
- }
- return chainedCommand;
- }
-
- /**
- * Return a Command that will be executed by a CommandStack.
- */
- protected Command createCommand(ModifierHelper aHelper) {
- if (aHelper == null)
- return null;
- Command command1, command2;
- ModifierHelper ownerHelper = aHelper.getOwnerHelper();
- if (aHelper.shouldUnsetValue() && ownerHelper != null)
- return null; //we are unsetting a value on an owner that does not exist so do not
- // create the owner
- command1 = createCommand(ownerHelper);
- command2 = primCreateCommand(aHelper);
-
- if (command1 != null) {
- if (command2 == null)
- command2 = command1;
- else
- command2 = command2.chain(command1);
- }
- return command2;
- }
-
- protected String createCommandLabel(String aPattern, EStructuralFeature feature) {
- String replacement = feature == null ? DEFAULT_COMMAND_LABEL : feature.getName();
- return java.text.MessageFormat.format(aPattern, new String[]{replacement});
- }
-
- /**
- * Return a Command that will be executed by a CommandStack. The default is to return null.
- * Subclasses should override this method.
- */
- protected Command createManyCommand(ModifierHelper aHelper) {
- if (aHelper.shouldUnsetValue())
- return createRemoveCommand(aHelper);
- return createAddCommand(aHelper);
- }
-
- protected EObject createObjectFromHelper(ModifierHelper aHelper) {
- return aHelper.createNewObjectFromFeature();
- }
-
- public class ProxyWrappingCommand extends AbstractCommand {
- protected Command baseCommand = null;
- protected EObject eObject = null;
- protected Resource resource = null;
-
- public ProxyWrappingCommand(Command baseCommand, EObject eObject) {
- this.baseCommand = baseCommand;
- this.eObject = eObject;
- this.resource = eObject.eResource();
- }
-
- public boolean canExecute() {
- return baseCommand.canExecute();
- }
-
- public void execute() {
- ExtendedEcoreUtil.becomeProxy(eObject, resource);
- baseCommand.execute();
- }
-
- public boolean canUndo() {
- return baseCommand.canUndo();
- }
-
- public void undo() {
- baseCommand.undo();
- ExtendedEcoreUtil.removeProxy(eObject, resource);
- }
-
- public void redo() {
- baseCommand.redo();
- }
-
- public Collection getResult() {
- return baseCommand.getResult();
- }
-
- public Collection getAffectedObjects() {
- return baseCommand.getAffectedObjects();
- }
-
- public String getLabel() {
- return baseCommand.getLabel();
- }
-
- public String getDescription() {
- return baseCommand.getDescription();
- }
-
- public void dispose() {
- super.dispose();
- baseCommand.dispose();
- }
- }
-
- /**
- * Return a Remove Command that will be executed by a CommandStack.
- */
- protected Command createRemoveCommand(ModifierHelper aHelper) {
- Object value = getValue(aHelper);
- Command command = null;
- EStructuralFeature feature = aHelper.getFeature();
- if (valueChanged(aHelper.getOwner(), feature, value, true)) {
- if (isValueEqual(aHelper, value)) {
- command = RemoveCommand.create(getEditingDomain(), aHelper.getOwner(), feature, (Collection) value);
- } else {
- command = RemoveCommand.create(getEditingDomain(), aHelper.getOwner(), feature, value);
- }
- ((AbstractCommand) command).setLabel(createCommandLabel(REMOVE_PATTERN, feature));
- setStatus(VALUE_CHANGE);
- } else {
- setStatus(NO_VALUE_CHANGE);
- }
- return command;
- }
-
- private boolean isValueEqual(ModifierHelper aHelper, Object value) {
- return aHelper.getOwner().eGet(aHelper.getFeature()) == value;
- }
-
- /**
- * Return a SetCommand that will be executed by a CommandStack.
- */
- protected Command createSingleCommand(ModifierHelper aHelper) {
- Object value = getValue(aHelper);
- Command command = null;
- if (valueChanged(aHelper.getOwner(), aHelper.getFeature(), value, aHelper.shouldUnsetValue())) {
- command = SetCommand.create(getEditingDomain(), aHelper.getOwner(), aHelper.getFeature(), value);
- ((AbstractCommand) command).setLabel(createCommandLabel(SET_PATTERN, aHelper.getFeature()));
- setStatus(VALUE_CHANGE);
- } else {
- setStatus(NO_VALUE_CHANGE);
- }
- return command;
- }
-
- protected Object createValueFromHelper(ModifierHelper aHelper) {
- EObject newObject = createObjectFromHelper(aHelper);
- setNewObjectAttributes(newObject, aHelper);
- return newObject;
- }
-
- protected boolean enumValueChanged(EObject anObject, EStructuralFeature aFeature, Object aValue) {
- if (!anObject.eIsSet(aFeature))
- return true;
- Enumerator existingEnumerator = (Enumerator) anObject.eGet(aFeature);
- Enumerator newEnumerator = getEnumerator(aFeature, aValue);
- return existingEnumerator != newEnumerator;
- }
-
- private Enumerator getEnumerator(EStructuralFeature aFeature, Object aValue) {
- if (aValue instanceof Enumerator)
- return (Enumerator) aValue;
- EEnum anEnum = (EEnum) aFeature.getEType();
- EEnumLiteral literal = null;
- if (aValue instanceof String)
- literal = anEnum.getEEnumLiteral((String) aValue);
- else if (aValue instanceof Integer)
- literal = anEnum.getEEnumLiteral(((Integer) aValue).intValue());
- if (literal != null)
- return literal.getInstance();
- return null;
- }
-
- protected Object getValue(ModifierHelper aHelper) {
- if (aHelper.mustCreateValue()) {
- Object value = createValueFromHelper(aHelper);
- aHelper.setValue(value);
- }
- return aHelper.getValue();
- }
-
- protected boolean manyValueChanged(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean isUnset) {
- List list = (List) anObject.eGet(aFeature);
- if (isUnset)
- return list.contains(aValue) || (list == aValue && !list.isEmpty());
- return !list.contains(aValue);
- }
-
- /**
- * Return a Command that will be executed by a CommandStack. The default is to return null.
- * Subclasses should override this method.
- */
- protected Command primCreateCommand(ModifierHelper aHelper) {
- Command command = doCreateCommand(aHelper);
- if (aHelper.shouldUnsetValue()) {
- Object value = aHelper.getValue();
- if (value instanceof EObject && !((EObject) value).eIsProxy()) {
- command = new ProxyWrappingCommand(command, (EObject) value);
- }
- }
- return command;
- }
-
- protected Command doCreateCommand(ModifierHelper aHelper) {
- if (!aHelper.isComplete()) {
- setStatus(ERROR);
- return null;
- }
- Command command = null;
- if (aHelper.getFeature().isMany())
- command = createManyCommand(aHelper);
- else
- command = createSingleCommand(aHelper);
-
- if (null != command) {
- List localHelpers = ModifierHelperRegistry.getInstance().getHelpers(aHelper);
- if (null != localHelpers) {
- extendedHelpers.addAll(localHelpers);
- }
- }
- return command;
-
- }
-
- /**
- * Run using
- *
- * @aHelper. This will set a MOF attibute value to the owner of the helper.
- */
- protected void primRun(ModifierHelper aHelper) {
- if (aHelper.isComplete()) {
- Object value = getValue(aHelper);
- if (valueChanged(aHelper.getOwner(), aHelper.getFeature(), value, aHelper.shouldUnsetValue()))
- setObjectAttribute(aHelper.getOwner(), aHelper.getFeature(), value, aHelper.shouldUnsetValue());
- }
- }
-
- /**
- * The default is to do nothing. Subclasses should override this method if they are using
- * recordable commands. The implementation of this method should update the MOF model directly.
- * Any modification will be recorded.
- */
- public void run() {
- if (!getHelpers().isEmpty()) {
- Iterator it = getHelpers().iterator();
- while (it.hasNext())
- run((ModifierHelper) it.next());
- }
- }
-
- /**
- * Run using
- *
- * @aHelper's ownerHelper first before running with
- * @aHelper.
- */
- protected void run(ModifierHelper aHelper) {
- if (aHelper != null) {
- run(aHelper.getOwnerHelper());
- primRun(aHelper);
- }
- }
-
- protected void setNewObjectAttributes(EObject anObject, ModifierHelper aHelper) {
- HashMap attributes = aHelper.getAttributes();
- Iterator it = attributes.keySet().iterator();
- EStructuralFeature feature;
- Object value = null;
- while (it.hasNext()) {
- feature = (EStructuralFeature) it.next();
- value = attributes.get(feature);
- setObjectAttribute(anObject, feature, value, false);
- }
- }
-
- protected void setObjectAttribute(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean shouldUnsetValue) {
- if (aFeature.isMany())
- setObjectManyAttribute(anObject, aFeature, aValue, shouldUnsetValue);
- else
- setObjectSingleAttribute(anObject, aFeature, aValue, shouldUnsetValue);
- }
-
- protected void setObjectEnumAttribute(EObject anObject, EStructuralFeature aFeature, Object aValue) {
- Enumerator enumerator = getEnumerator(aFeature, aValue);
- anObject.eSet(aFeature, enumerator);
- }
-
- protected void setObjectManyAttribute(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean shouldUnsetValue) {
- List list = (List) anObject.eGet(aFeature);
- if (shouldUnsetValue)
- list.remove(aValue);
- else
- list.add(aValue);
- }
-
- protected void setObjectSingleAttribute(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean shouldUnsetValue) {
- if (shouldUnsetValue)
- anObject.eUnset(aFeature);
- else if (aFeature.getEType() instanceof EEnum)
- setObjectEnumAttribute(anObject, aFeature, aValue);
- else
- anObject.eSet(aFeature, aValue);
- }
-
- protected boolean singleValueChanged(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean isUnset) {
- if (aFeature.getEType() instanceof EEnum)
- return enumValueChanged(anObject, aFeature, aValue);
-
- Object existingValue = anObject.eGet(aFeature);
- if (existingValue == null && aValue == null)
- return false;
- if (existingValue != null && !existingValue.equals(aValue))
- return true;
- if (aValue != null && !aValue.equals(existingValue))
- return true;
- return false;
- }
-
- protected boolean valueChanged(EObject anObject, EStructuralFeature aFeature, Object aValue, boolean isUnset) {
- if (aFeature.isMany())
- return manyValueChanged(anObject, aFeature, aValue, isUnset);
- return singleValueChanged(anObject, aFeature, aValue, isUnset);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelper.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelper.java
deleted file mode 100644
index 1936a2c31..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelper.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-
-import java.util.HashMap;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.ecore.impl.EClassImpl;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.wst.common.internal.emf.utilities.FeatureValueConversionException;
-import org.eclipse.wst.common.internal.emf.utilities.FeatureValueConverter;
-
-/**
- * Insert the type's description here. Creation date: (4/6/2001 3:23:36 PM)
- *
- * @author: Administrator
- */
-public class ModifierHelper {
-
- private EObject owner;
- private ModifierHelper ownerHelper;
- private OwnerProvider ownerProvider;
- private Object value;
- private EStructuralFeature feature;
- private HashMap attributes;
- private boolean shouldUnsetValue = false;
- private String valueXSITypeName;
- private FeatureValueConverter featureValueConverter;
-
- public static final int ACTION_SET = 0;
- public static final int ACTION_UNSET = 1;
- public static final int ACTION_BOTH = 2;
-
- /**
- * J2EEModifierHelper constructor comment.
- */
- public ModifierHelper() {
- super();
- }
-
- /**
- * J2EEModifierHelper constructor comment.
- */
- public ModifierHelper(EObject anOwner, EStructuralFeature aFeature, Object aValue) {
- setOwner(anOwner);
- setFeature(aFeature);
- setValue(aValue);
- }
-
- /**
- * J2EEModifierHelper constructor comment.
- */
- public ModifierHelper(ModifierHelper anOwnerHelper, EStructuralFeature aFeature, Object aValue) {
- setOwnerHelper(anOwnerHelper);
- setFeature(aFeature);
- setValue(aValue);
- }
-
- /**
- * J2EEModifierHelper constructor comment.
- */
- public ModifierHelper(OwnerProvider anOwnerProvider, EStructuralFeature aFeature, Object aValue) {
- setOwnerProvider(anOwnerProvider);
- setFeature(aFeature);
- setValue(aValue);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return java.util.HashMap
- */
- public void addAttribute(EStructuralFeature aFeature, Object aValue) {
- if (aFeature != null && aValue != null)
- getAttributes().put(aFeature, aValue);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newValue
- * java.lang.Object
- */
- protected Object convertValue(java.lang.Object newValue) {
- return getFeatureValueConverter().convertValue(newValue, getFeature());
- }
-
- //Calling this will cause the value to be removed or unset from the owner.
- public void doUnsetValue() {
- shouldUnsetValue = true;
- if (value != SetCommand.UNSET_VALUE && feature != null && !feature.isMany())
- primSetValue(SetCommand.UNSET_VALUE);
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return java.util.HashMap
- */
- public java.util.HashMap getAttributes() {
- if (attributes == null)
- attributes = new HashMap();
- return attributes;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return org.eclipse.emf.ecore.EFactory
- */
- protected org.eclipse.emf.ecore.EFactory getFactory() {
- return getPackage().getEFactoryInstance();
- }
-
- protected EPackage getPackage() {
- return ((EClassImpl) getFeatureType()).getEPackage();
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return org.eclipse.emf.ecore.EStructuralFeature
- */
- public org.eclipse.emf.ecore.EStructuralFeature getFeature() {
- return feature;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return EObject
- */
- protected EObject getFeatureType() {
- return getFeature().getEType();
- }
-
- /**
- * Insert the method's description here. Creation date: (5/10/2001 4:51:58 PM)
- *
- * @return com.ibm.etools.j2ee.commands.FeatureValueConverter
- */
- public FeatureValueConverter getFeatureValueConverter() {
- if (featureValueConverter == null)
- featureValueConverter = FeatureValueConverter.DEFAULT;
- return featureValueConverter;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return String
- */
- protected String getNewValueTypeName() {
- if (getValueXSITypeName() != null && getValueXSITypeName().length() > 0)
- return getValueXSITypeName();
- return (((EClass) getFeatureType()).getName());
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return org.eclipse.emf.ecore.EObject
- */
- public org.eclipse.emf.ecore.EObject getOwner() {
- if (owner == null) {
- OwnerProvider provider = getOwnerProvider();
- EObject providerOwner = null;
- if (provider != null)
- providerOwner = provider.getOwner();
- if (providerOwner == null && getOwnerHelper() != null)
- providerOwner = (EObject) getOwnerHelper().getValue();
- return providerOwner;
- }
- return owner;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/8/2001 2:47:54 PM)
- *
- * @return com.ibm.etools.j2ee.commands.J2EEModifierHelper
- */
- public ModifierHelper getOwnerHelper() {
- if (ownerHelper == null) {
- if (getOwnerProvider() != null && getOwnerProvider().getOwner() == null)
- return getOwnerProvider().getOwnerHelper();
- }
- return ownerHelper;
- }
-
- public ModifierHelper primGetOwnerHelper() {
- return ownerHelper;
- }
-
- /**
- * Insert the method's description here. Creation date: (9/18/2001 1:31:14 PM)
- *
- * @return com.ibm.etools.j2ee.ui.J2EEOwnerProvider
- */
- public OwnerProvider getOwnerProvider() {
- return ownerProvider;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @return java.lang.Object
- */
- public java.lang.Object getValue() {
- return value;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/10/2001 3:39:31 PM)
- *
- * @return java.lang.String
- */
- public java.lang.String getValueXSITypeName() {
- return valueXSITypeName;
- }
-
- /**
- * This will automatically get called from the J2EEModelModifier before executing so it is not
- * necessary to call it directly.
- */
- public boolean isComplete() {
- boolean result = true;
- if (getOwnerHelper() != null)
- result = getOwnerHelper().isComplete();
- if (!mustCreateValue())
- result = getValue() != null || shouldUnsetValue();
- else
- result = getFeatureType() != null;
- return result && getFeature() != null && (getOwner() != null || getOwnerHelper() != null);
- }
-
- public boolean mustCreateValue() {
- return getValue() == null && getFeature() != null && !shouldUnsetValue();
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newValue
- * java.lang.Object
- */
- public void primSetValue(java.lang.Object newValue) {
- value = newValue;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newFeature
- * org.eclipse.emf.ecore.EStructuralFeature
- */
- public void setFeature(org.eclipse.emf.ecore.EStructuralFeature newFeature) {
- feature = newFeature;
- }
-
- /**
- * Insert the method's description here. Creation date: (5/10/2001 4:51:58 PM)
- *
- * @param newFeatureValueConverter
- * com.ibm.etools.j2ee.commands.FeatureValueConverter
- */
- public void setFeatureValueConverter(FeatureValueConverter newFeatureValueConverter) {
- featureValueConverter = newFeatureValueConverter;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newOwner
- * org.eclipse.emf.ecore.EObject
- */
- public void setOwner(org.eclipse.emf.ecore.EObject newOwner) {
- owner = newOwner;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/8/2001 2:47:54 PM)
- *
- * @param newOwnerHelper
- * com.ibm.etools.j2ee.commands.J2EEModifierHelper
- */
- public void setOwnerHelper(ModifierHelper newOwnerHelper) {
- ownerHelper = newOwnerHelper;
- }
-
- /**
- * Insert the method's description here. Creation date: (9/18/2001 1:31:14 PM)
- *
- * @param newOwnerProvider
- * com.ibm.etools.j2ee.ui.J2EEOwnerProvider
- */
- public void setOwnerProvider(OwnerProvider newOwnerProvider) {
- ownerProvider = newOwnerProvider;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newValue
- * java.lang.Object
- */
- public void setValue(java.lang.Object newValue) {
- try {
- primSetValue(convertValue(newValue));
- } catch (FeatureValueConversionException featureException) {
- Logger.getLogger().logError(featureException);
- primSetValue(null);
- }
- }
-
- /**
- * Treat an empty String as a null value. Creation date: (4/6/2001 3:28:16 PM)
- *
- * @param newValue
- * java.lang.Object
- */
- public void setValueFromWidget(String newValue) {
- Object data = newValue;
- if (newValue != null && newValue.length() == 0)
- data = null;
- setValue(data);
- if (data == null)
- doUnsetValue();
- else
- shouldUnsetValue = false;
- }
-
- /**
- * Insert the method's description here. Creation date: (4/10/2001 3:39:31 PM)
- *
- * @param newValueXSITypeName
- * java.lang.String
- */
- public void setValueXSITypeName(java.lang.String newValueXSITypeName) {
- valueXSITypeName = newValueXSITypeName;
- }
-
- public boolean shouldUnsetValue() {
- return shouldUnsetValue;
- }
-
- public EObject createNewObjectFromFeature() {
- EClass metaClass = (EClass) getPackage().getEClassifier(getNewValueTypeName());
- return getFactory().create(metaClass);
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperChainer.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperChainer.java
deleted file mode 100644
index d36148d59..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperChainer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-
-
-
-/**
- * @version 1.0
- * @author
- */
-public class ModifierHelperChainer {
-
- ModifierHelper helper;
-
- public ModifierHelperChainer(EStructuralFeature feature, EObject owner, Object value) {
- helper = new ModifierHelper();
-
- if (owner != null)
- helper.setOwner(owner);
-
- helper.setFeature(feature);
-
- if (value != null)
- helper.setValue(value);
-
- }
-
- public ModifierHelper getHelper() {
- return helper;
- }
-
- public void setOwnerBasedOnType(Object owner) {
- if (owner instanceof EObject)
- helper.setOwner((EObject) owner);
- else if (owner instanceof ModifierHelper)
- helper.setOwnerHelper((ModifierHelper) owner);
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperFactory.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperFactory.java
deleted file mode 100644
index bc41a627e..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Apr 27, 2004
- *
- * To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-/**
- * @author jsholl
- *
- * To change the template for this generated type comment go to Window - Preferences - Java - Code
- * Generation - Code and Comments
- */
-public interface ModifierHelperFactory {
-
-
- /**
- * @param baseHelper
- * @param actionFlag
- * @return
- */
- ModifierHelper getHelper(ModifierHelper baseHelper, int actionFlag);
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperRegistry.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperRegistry.java
deleted file mode 100644
index b1da8ade0..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ModifierHelperRegistry.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Apr 27, 2004
- *
- * To change the template for this generated file go to Window - Preferences -
- * Java - Code Generation - Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.jem.util.logger.proxy.Logger;
-
-/**
- * @author jsholl
- *
- */
-public class ModifierHelperRegistry {
- private static final String PLUGIN_ID = "org.eclipse.wst.common.internal.emfworkbench.integration"; //$NON-NLS-1$
- private static final String EXTENSION_POINT = "ModifierHelperFactory"; //$NON-NLS-1$
- private static final String FACTORY_CLASS = "class"; //$NON-NLS-1$
- private static final String PACKAGE = "package"; //$NON-NLS-1$
- private static final String PACKAGE_URI = "uri"; //$NON-NLS-1$
- private static final String NAME = "name"; //$NON-NLS-1$
- private static final String TYPE = "type"; //$NON-NLS-1$
- private static final String FEATURE = "feature"; //$NON-NLS-1$
- private static final String FEATURE_ACTION = "action"; //$NON-NLS-1$
- private static final String FEATURE_ACTION_SET = "set"; //$NON-NLS-1$
- private static final String FEATURE_ACTION_UNSET = "unset"; //$NON-NLS-1$
- private static final String FEATURE_ACTION_BOTH = "both"; //default //$NON-NLS-1$
- private static ModifierHelperRegistry INSTANCE = null;
- // Hashtable mapping features to a list of FactoryHolders
- private Hashtable featureHash = new Hashtable();
- private Hashtable factoryHash = new Hashtable();
-
- private class FactoryHolder {
- private int actionType;
- private IConfigurationElement element;
-
- public FactoryHolder(IConfigurationElement element, int actionType) {
- this.element = element;
- this.actionType = actionType;
- }
-
- public ModifierHelperFactory getFactory(int actionTypeArg) {
- if (this.actionType == actionTypeArg || this.actionType == ModifierHelper.ACTION_BOTH) {
- String hashKey = getFactoryHash(element);
- ModifierHelperFactory factory = (ModifierHelperFactory) factoryHash.get(hashKey);
- if (null == factory) {
- try {
- factory = (ModifierHelperFactory) element.createExecutableExtension(FACTORY_CLASS);
- factoryHash.put(hashKey, factory);
- } catch (CoreException e) {
- Logger.getLogger().logError(e);
- }
- }
- return factory;
- }
- return null;
- }
-
- public boolean equals(Object obj) {
- if (super.equals(obj)) {
- return true;
- }
- FactoryHolder holder = (FactoryHolder) obj;
- return getFactoryHash(element).equals(getFactoryHash(holder.element));
- }
- }
-
- private ModifierHelperRegistry() {
- readExtensions();
- }
-
- private void readExtensions() {
- IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID, EXTENSION_POINT);
- if (point == null)
- return;
- IConfigurationElement[] elements = point.getConfigurationElements();
- for (int i = 0; i < elements.length; i++) {
- readFactory(elements[i]);
- }
- }
-
- private void readFactory(IConfigurationElement element) {
- String factoryClassName = element.getAttribute(FACTORY_CLASS);
- if (null == factoryClassName) {
- logError(element, "No " + FACTORY_CLASS + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- IConfigurationElement[] packages = element.getChildren(PACKAGE);
- if (packages.length == 0) {
- logError(element, "No " + PACKAGE + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- for (int j = 0; j < packages.length; j++) {
- readPackage(element, packages[j]);
- }
- }
-
- private void readPackage(IConfigurationElement factoryElement, IConfigurationElement element) {
- String packageURI = element.getAttribute(PACKAGE_URI);
- if (null == packageURI) {
- logError(element, "No " + PACKAGE_URI + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(packageURI);
- if (null == ePackage) {
- logError(element, PACKAGE + " " + packageURI + " can not be found."); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- IConfigurationElement[] types = element.getChildren(TYPE);
- if (types.length == 0) {
- logError(element, "No " + TYPE + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- }
- for (int i = 0; i < types.length; i++) {
- readType(factoryElement, ePackage, types[i]);
- }
- }
-
- private void readType(IConfigurationElement factoryElement, EPackage ePackage, IConfigurationElement element) {
- String typeName = element.getAttribute(NAME);
- if (null == typeName) {
- logError(element, "No " + NAME + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- EClassifier eClassifier = ePackage.getEClassifier(typeName);
- if (null == eClassifier) {
- logError(element, TYPE + " " + typeName + " can not be found in " + PACKAGE + " " + ePackage.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return;
- }
- EClass eClass = (EClass) eClassifier;
- IConfigurationElement[] features = element.getChildren(FEATURE);
- if (features.length == 0) {
- logError(element, "No " + FEATURE + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- for (int i = 0; i < features.length; i++) {
- readFeature(factoryElement, eClass, features[i]);
- }
- }
-
- private void readFeature(IConfigurationElement factoryElement, EClass eClass, IConfigurationElement element) {
- String featureName = element.getAttribute(NAME);
- if (null == featureName) {
- logError(element, "No " + NAME + " defined."); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
- String action = element.getAttribute(FEATURE_ACTION);
- if (null == action) {
- action = FEATURE_ACTION_BOTH;
- }
- int actionType = -1;
- if (action.equalsIgnoreCase(FEATURE_ACTION_BOTH)) {
- actionType = ModifierHelper.ACTION_BOTH;
- } else if (action.equalsIgnoreCase(FEATURE_ACTION_SET)) {
- actionType = ModifierHelper.ACTION_SET;
- } else if (action.equalsIgnoreCase(FEATURE_ACTION_UNSET)) {
- actionType = ModifierHelper.ACTION_UNSET;
- }
- if (actionType == -1) {
- logError(element, "Invalid " + FEATURE_ACTION + "=" + action + " defined. Valid values are: " + FEATURE_ACTION_BOTH + ", " + FEATURE_ACTION_SET + ", or " + FEATURE_ACTION_UNSET); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- return;
- }
- EStructuralFeature feature = null;
- EList allFeatures = eClass.getEAllStructuralFeatures();
- EStructuralFeature tempFeature = null;
- Iterator iterator = allFeatures.iterator();
- while (null == feature && iterator.hasNext()) {
- tempFeature = (EStructuralFeature) iterator.next();
- if (tempFeature.getName().equals(featureName)) {
- feature = tempFeature;
- }
- }
- if (feature == null) {
- logError(element, FEATURE + " " + featureName + " can not be found in " + TYPE + " " + eClass.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return;
- }
- List factoryHolderList = (List) featureHash.get(feature);
- if (null == factoryHolderList) {
- factoryHolderList = new ArrayList();
- featureHash.put(feature, factoryHolderList);
- }
- FactoryHolder factoryHolder = new FactoryHolder(factoryElement, actionType);
- if (factoryHolderList.contains(factoryHolder)) {
- logError(element, "Duplicate" + FEATURE + ":" + featureName + " defined for " + FACTORY_CLASS + ":" + factoryElement.getAttribute(FACTORY_CLASS)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- return;
- }
- factoryHolderList.add(factoryHolder);
- }
-
- private String getFactoryHash(IConfigurationElement factoryElement) {
- return factoryElement.getDeclaringExtension().getNamespace() + factoryElement.getAttribute(FACTORY_CLASS);
- }
-
- public static void logError(IConfigurationElement element, String text) {
- IExtension extension = element.getDeclaringExtension();
- StringBuffer buf = new StringBuffer();
- buf.append("Plugin " + extension.getNamespace() + ", extension " + extension.getExtensionPointUniqueIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
- buf.append("\n" + text); //$NON-NLS-1$
- Logger.getLogger().logError(buf.toString());
- }
-
- public static ModifierHelperRegistry getInstance() {
- if (null == INSTANCE) {
- INSTANCE = new ModifierHelperRegistry();
- }
- return INSTANCE;
- }
-
- /**
- * returns a list of ModifierHelpers
- *
- * @param baseHelper
- * @param actionFlag
- * @return
- */
- public List getHelpers(ModifierHelper baseHelper) {
- int actionFlag = baseHelper.shouldUnsetValue() ? ModifierHelper.ACTION_UNSET : ModifierHelper.ACTION_SET;
- EStructuralFeature feature = baseHelper.getFeature();
- List factoryList = getFactories(feature, actionFlag);
- if (null == factoryList) {
- return null;
- }
- ArrayList helpers = new ArrayList();
- Iterator it = factoryList.iterator();
- ModifierHelperFactory factory = null;
- while (it.hasNext()) {
- factory = (ModifierHelperFactory) it.next();
- Object helper = factory.getHelper(baseHelper, actionFlag);
- if (null != helper) {
- helpers.add(helper);
- }
- }
- return helpers;
- }
-
- private List getFactories(EStructuralFeature feature, int actionFlag) {
- List factoryHolderList = (List) featureHash.get(feature);
- if (null == factoryHolderList) {
- return null;
- }
- List factoryList = new ArrayList();
- ModifierHelperFactory factory = null;
- for (int i = 0; i < factoryHolderList.size(); i++) {
- factory = ((FactoryHolder) factoryHolderList.get(i)).getFactory(actionFlag);
- if (null != factory) {
- factoryList.add(factory);
- }
- }
- return factoryList;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/OwnerProvider.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/OwnerProvider.java
deleted file mode 100644
index e08243980..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/OwnerProvider.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.emf.ecore.EObject;
-
-
-/**
- * Insert the type's description here. Creation date: (6/20/2001 10:24:46 PM)
- *
- * @author: Administrator
- */
-public interface OwnerProvider {
- /**
- * Return the EObject that will serve as the owner of a given J2EEModifierHelper.
- */
- EObject getOwner();
-
- /**
- * Return a J2EEModifierHelper for the owner if the owner does not yet exist.
- */
- ModifierHelper getOwnerHelper();
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ProjectResourceSetEditImpl.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ProjectResourceSetEditImpl.java
deleted file mode 100644
index aa8f271f8..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ProjectResourceSetEditImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 4, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class ProjectResourceSetEditImpl extends ProjectResourceSetImpl {
-
- /**
- * @param aProject
- */
- public ProjectResourceSetEditImpl(IProject aProject) {
- super(aProject);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jem.internal.util.emf.workbench.ProjectResourceSetImpl#createResource(org.eclipse.emf.common.util.URI)
- */
- public Resource createResource(URI uri) {
- Resource result = super.createResource(uri);
- if (result != null && WorkbenchResourceHelper.isReferencedResource(result))
- WorkbenchResourceHelper.cacheSynchronizationStamp((ReferencedResource) result);
- return result;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
deleted file mode 100644
index 2c180da2e..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/integration/ResourceSetWorkbenchEditSynchronizer.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on Mar 4, 2004
- *
- * To change the template for this generated file go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-package org.eclipse.wst.common.internal.emfworkbench.integration;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IResourceDelta;
-import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.jobs.ILock;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.common.util.WrappedException;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jem.internal.util.emf.workbench.EMFWorkbenchContextFactory;
-import org.eclipse.jem.util.emf.workbench.ProjectResourceSet;
-import org.eclipse.jem.util.emf.workbench.ResourceSetWorkbenchSynchronizer;
-import org.eclipse.jem.util.logger.proxy.Logger;
-import org.eclipse.jem.util.plugin.JEMUtilPlugin;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-
-/**
- * @author schacher
- *
- * To change the template for this generated type comment go to
- * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
- */
-public class ResourceSetWorkbenchEditSynchronizer extends ResourceSetWorkbenchSynchronizer implements IResourceDeltaVisitor {
- private static final String CLASS_EXTENSION = "class"; //$NON-NLS-1$
- private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$
- private Set recentlySavedFiles = new HashSet();
- private Map ignoredFilesCache = new HashMap();
-
- /** The emf resources to be removed from the resource set as a result of a delta */
- protected List deferredRemoveResources = new ArrayList();
- protected List deferredUnloadResources = new ArrayList();
- protected List deferredLoadResources = new ArrayList();
-
- protected List autoloadResourcesURIs = new ArrayList();
- protected List autoloadResourcesExts = new ArrayList();
-
-
- /**
- * @param aResourceSet
- * @param aProject
- */
- public ResourceSetWorkbenchEditSynchronizer(ResourceSet aResourceSet, IProject aProject) {
- super(aResourceSet, aProject);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.ResourceSetWorkbenchSynchronizer#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
- */
- public void resourceChanged(IResourceChangeEvent event) {
- super.resourceChanged(event);
- try {
- acceptDelta(event);
- notifyExtendersIfNecessary();
- processDeferredResources();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- deferredRemoveResources.clear();
- deferredUnloadResources.clear();
- deferredLoadResources.clear();
- }
- }
-
- protected void processDeferredRemovedResources() {
- Resource resource = null;
- for (int i = 0; i < deferredRemoveResources.size(); i++) {
- resource = (Resource) deferredRemoveResources.get(i);
- resourceSet.getResources().remove(resource);
- resource.unload();
- }
- }
-
- protected void processDeferredUnloadedResources() {
- Resource resource = null;
- for (int i = 0; i < deferredUnloadResources.size(); i++) {
- resource = (Resource) deferredUnloadResources.get(i);
- resource.unload();
- }
- }
-
- private void processDeferredLoadResources() {
- URI uri = null;
- for (int i = 0; i < deferredLoadResources.size(); i++) {
- uri = (URI) deferredLoadResources.get(i);
- try {
- resourceSet.getResource(uri, true);
- } catch (WrappedException ex) {
- Logger.getLogger().logError(ex);
- }
-
- }
- }
-
- private ILock lock;
- private static final long delay = 30;
-
- private ILock getLock() {
- if (lock == null)
- lock = Platform.getJobManager().newLock();
- return lock;
- }
-
- private void releaseLock() {
- getLock().release();
- }
- private boolean aquireLock() throws InterruptedException{
- return getLock().acquire(delay);
- }
-
- protected void acceptDelta(final IResourceChangeEvent event) {
-
- boolean hasLocked = false;
- try {
- hasLocked = aquireLock();
- } catch (InterruptedException e) {
- Logger.getLogger().write(e);
- }
-
- try{
- final IResourceDelta delta = event.getDelta();
-
- if (ResourcesPlugin.getWorkspace().isTreeLocked()) {
- primAcceptDelta(delta, event);
- }
- else {
- IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
- public void run(IProgressMonitor monitor) throws CoreException {
- primAcceptDelta(delta, event);
- }
- };
- try {
- ResourcesPlugin.getWorkspace().run(runnable, project, IWorkspace.AVOID_UPDATE, null);
- } catch (CoreException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }finally{
- if( hasLocked )
- releaseLock();
- }
- }
-
- private void primAcceptDelta(IResourceDelta delta, IResourceChangeEvent event) {
- if (delta != null) {
- try {
- delta.accept(ResourceSetWorkbenchEditSynchronizer.this);
- } catch (Exception e) {
- Logger.getLogger().logError(e);
- }
- }
- }
-
- /**
- * The project is going away so we need to cleanup ourself and the ResourceSet. TODO Need to
- * push up this code to ResourceSetWorkbenchSynchronizer in next release.
- */
- protected void release() {
- if (JEMUtilPlugin.isActivated()) {
- try {
- if (resourceSet instanceof ProjectResourceSet)
- ((ProjectResourceSet) resourceSet).release();
- } finally {
- EMFWorkbenchContextFactory.INSTANCE.removeCachedProject(getProject());
- dispose();
- }
- }
- }
-
- private void processDeferredResources() {
- processDeferredRemovedResources();
- processDeferredUnloadedResources();
- processDeferredLoadResources();
- }
-
- public boolean visit(IResourceDelta delta) {
- IResource resource = delta.getResource();
- // only respond to project changes
- if (resource != null) {
- if (resource.getType() == IResource.PROJECT) {
- IProject p = (IProject) resource;
- if (isInterrestedInProject(p)) {
- currentProjectDelta = delta;
- return true;
- }
- // added line
- currentProjectDelta = null;
- return false;
- }
- if (resource.getType() == IResource.FILE && isInterrestedInFile((IFile) resource)) {
- switch (delta.getKind()) {
- case IResourceDelta.REMOVED :
- removedResource((IFile) resource);
- break;
- case IResourceDelta.ADDED :
- addedResource((IFile) resource);
- break;
- case IResourceDelta.CHANGED :
- if ((delta.getFlags() & IResourceDelta.CONTENT) != 0)
- changedResource((IFile) resource);
- break;
- default :
- if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0 || (delta.getFlags() & IResourceDelta.MOVED_TO) != 0)
- movedResource((IFile) resource);
- break;
- }
- return false;
- }
- }
- return true;
- }
-
- /**
- * Queue up the <code>Resource</code> that corresponds to <code>aFile</code>, for removal
- * from the cache of resources.
- *
- * @post Return true if a <code>Resource</code> was queued up to be removed.
- */
- protected boolean removedResource(IFile aFile) {
- return processResource(aFile, true);
- }
-
- /**
- * Queue up the <code>Resource</code> that corresponds to <code>aFile</code>, for reload.
- *
- * @post Return true if a <code>Resource</code> was queued up to be reloaded.
- */
- protected boolean addedResource(IFile aFile) {
- boolean didProcess = false;
- Resource resource = getResource(aFile);
- if ((resource != null) || (recentlySavedFiles.contains(resource))){
- /*
- * The IFile was just added to the workspace but we have a resource
- * in memory. Need to decide if it should be unloaded.
- */
- if (resource.isModified()) {
- if (WorkbenchResourceHelper.isReferencedResource(resource)) {
- ReferencedResource refRes = (ReferencedResource) resource;
- if (refRes.shouldForceRefresh()) {
- deferredUnloadResources.add(resource);
- didProcess = true;
- }
- }
- } else {
- /*Unload if found and is not modified but inconsistent.*/
- if (resource.isLoaded() && WorkbenchResourceHelper.isReferencedResource(resource) && !WorkbenchResourceHelper.isConsistent((ReferencedResource)resource)) {
- deferredUnloadResources.add(resource);
- didProcess = true;
- }
- }
- } else {
- //Process resource as a refresh.
- URI uri = URI.createPlatformResourceURI(aFile.getFullPath().toString());
- if ((autoloadResourcesURIs.contains(uri)) || (autoloadResourcesExts.contains(aFile.getFileExtension()))) {
- deferredLoadResources.add(uri);
- didProcess = true;
- }
- }
- return didProcess;
-}
-
- protected boolean processResource(IFile aFile, boolean isRemove) {
- Resource resource = getResource(aFile);
- if ((resource != null) || (recentlySavedFiles.contains(resource))){
- if (resource.isModified()) {
- if (WorkbenchResourceHelper.isReferencedResource(resource)) {
- ReferencedResource refRes = (ReferencedResource) resource;
- if (!refRes.shouldForceRefresh())
- return false; //Do not do anything
- } else
- return false;
- }
-
- if (isRemove)
- deferredRemoveResources.add(resource);
- else if (resource.isLoaded() && WorkbenchResourceHelper.isReferencedResource(resource) && !WorkbenchResourceHelper.isConsistent((ReferencedResource)resource))
- deferredUnloadResources.add(resource);
- }
- return false;
- }
-
- /**
- * For now, do the same as if the <code>aFile</code> was removed.
- */
- protected boolean movedResource(IFile aFile) {
- return removedResource(aFile);
- }
-
- /**
- * The contents of <code>aFile</code> have changed in the Workbench and we may need to update
- * our cached resources.
- *
- * We will process this resource to be refreshed and not removed.
- *
- * @post Return true if a <code>Resource</code> was actually removed.
- */
-
- protected boolean changedResource(IFile aFile) {
- //Process resource as a refresh.
- return processResource(aFile, false);
- }
-
- protected Resource getResource(IFile aFile) {
-
- return resourceSet.getResource(URI.createPlatformResourceURI(aFile.getFullPath().toString()), false);
- }
-
-
- /**
- * This method should be called prior to writing to an IFile from a MOF resource.
- */
- public void preSave(IFile aFile) {
- if (aFile != null) {
- recentlySavedFiles.add(aFile);
- ignoredFilesCache.remove(aFile);
- }
- }
-
- /**
- * This method should be called after a preSave if the save fails
- */
- public void removeFromRecentlySavedList(IFile aFile) {
- if (aFile != null) {
- recentlySavedFiles.remove(aFile);
- ignoredFilesCache.remove(aFile);
- }
- }
-
- /**
- * This method should be called just after writing to an IFile from a MOF resource.
- *
- * @deprecated No longer needs to be called.
- */
- public void postSave(IFile aFile) {
- //TODO remove this method
- }
-
- /**
- * Return <code>true</code> if <code>aProject</code> has the projectNatureID.
- */
- protected boolean isInterrestedInProject(IProject aProject) {
- return aProject.equals(getProject());
- }
-
- /**
- * Optimized not to be not interrested in files with an extension of .java or .class or if the
- * file has just been saved by our own internal mechanism.
- */
- protected boolean isInterrestedInFile(IFile aFile) {
- String extension = aFile.getFileExtension();
- if (CLASS_EXTENSION.equals(extension) || JAVA_EXTENSION.equals(extension))
- return false;
- if (recentlySavedFiles.remove(aFile)) {
- cacheIgnored(aFile);
- return false;
- }
- return !hasIgnored(aFile);
- }
-
- /**
- * Return true if we have already ignored this <code>file</code> and that its modification
- * stamp is the same as when we processed it.
- *
- * @param file
- * @return
- */
- private boolean hasIgnored(IFile file) {
- Long cachedStamp = (Long) ignoredFilesCache.get(file);
- if (cachedStamp == null)
- return false;
- long stamp = WorkbenchResourceHelper.computeModificationStamp(file);
- return cachedStamp.longValue() == stamp;
- }
-
- /**
- * Cache the modification stamp of the <code>file</code>.
- *
- * @param file
- */
- private void cacheIgnored(IFile file) {
- long stamp = WorkbenchResourceHelper.computeModificationStamp(file);
- ignoredFilesCache.put(file, new Long(stamp));
- }
-
- public void enableAutoload(URI uri) {
- URI normalized = resourceSet.getURIConverter().normalize(uri);
- autoloadResourcesURIs.add(normalized);
- }
-
- public void disableAutoload(URI uri) {
- URI normalized = resourceSet.getURIConverter().normalize(uri);
- autoloadResourcesURIs.remove(normalized);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.ResourceSetWorkbenchSynchronizer#initialize()
- */
- protected void initialize() {
- getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.POST_CHANGE);
- }
- public void enableAutoload(String extension) {
- autoloadResourcesExts.add(extension);
-
- }
- public void disableAutoload(String extension) {
- autoloadResourcesExts.remove(extension);
- }
-
- public void dispose() {
- super.dispose();
- currentProjectDelta = null;
- extenders = null;
- }
-
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/IValidateEditContext.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/IValidateEditContext.java
deleted file mode 100644
index e965900b8..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/IValidateEditContext.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on May 18, 2004
- */
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-
-
-/**
- * @author jlanuti This is the abstraction layer for validate edit
- */
-public interface IValidateEditContext extends ResourceStateValidatorPresenter {
-
- public static final String CLASS_KEY = "ValidateEditContext"; //$NON-NLS-1$
-
- public void setEditModel(EditModel fValidator);
-
- public IStatus validateState(EditModel fValidator);
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateInputProvider.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateInputProvider.java
deleted file mode 100644
index 4b8bc6054..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateInputProvider.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-
-import java.util.List;
-
-public interface ResourceStateInputProvider {
- /**
- * Return true if any of the controlled resources or files has been modified.
- *
- * @return boolean
- */
- boolean isDirty();
-
- /**
- * Return a <code>List</code> of the MOF Resources that are being managed. Synchronization
- * checking will only work if you are using the emf.workbench plugin apis for loading resources.
- * This will ensure that you get an instance of a <code>ReferencedResource</code>. This
- * resource type is capable of caching its last known synchronization stamp that may be used to
- * test if the resource is consitent with the underlying IFile.
- *
- * @return List
- */
- List getResources();
-
- /**
- * Return a <code>List</code> of IFiles that are not MOF Resources that are also being
- * modified.
- *
- * @return List
- */
- List getNonResourceFiles();
-
- /**
- * Return a subset of the List from getNonResourceFiles() that are inconsistent with the
- * underlying java.io.File.
- *
- * @return List
- * @see ResourceStateInputProvider#getNonResourceFiles()
- */
- List getNonResourceInconsistentFiles();
-
- /**
- * It is the responsibility of the provider to cache the synchronization stamp for the List of
- * <code>roNonResourceFiles</code>. This stamp will be used to determine the inconsistent
- * files. This is only necessary of IFiles that are not MOF resources.
- *
- * @param roNonResourceFiles
- * @see ResourceStateInputProvider#getNonResourceInconsistentFiles()
- */
- void cacheNonResourceValidateState(List roNonResourceFiles);
-}
-
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidator.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidator.java
deleted file mode 100644
index ef337c447..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jem.util.plugin.JEMUtilPlugin;
-
-public interface ResourceStateValidator {
- static final IStatus OK_STATUS = new Status(IStatus.OK, JEMUtilPlugin.ID, 0, "", null); //$NON-NLS-1$
-
- /**
- * This method should be called whenever a <code>presenter</code> is activated (becomes
- * active). This will check the timestamps of the underlying files to see if they are different
- * from the last cached modified value. The <code>presenter</code> should be prepared to
- * prompt the user if they would like to refresh with the contents on disk if we are dirty.
- */
- void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException;
-
- /**
- * This method should be called whenever a <code>presenter</code> looses activation. This will
- * check the timestamps of the underlying files to see if they are different from the last
- * cached modified value. The <code>presenter</code> should be prepared to prompt the user if
- * they would like to refresh with the contents on disk if we are dirty.
- */
- void lostActivation(ResourceStateValidatorPresenter presenter) throws CoreException;
-
- /**
- * This method should be called the first time the files are about to be modified after a
- * <code>presenter</code> becomes active. The returned IStatus may have an ERROR status which
- * should be presented to the user.
- */
- IStatus validateState(ResourceStateValidatorPresenter presenter) throws CoreException;
-
- /**
- * This method should be called prior to the <code>presenter</code> saving the modified
- * contents. This will check the consistency of the underlying files to ensure that they are
- * synchronized. If true is returned, the save can proceed.
- */
- boolean checkSave(ResourceStateValidatorPresenter presenter) throws CoreException;
-
- /**
- * Return true if there are any read only files.
- */
- boolean checkReadOnly();
-}
-
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java
deleted file mode 100644
index 729443f9f..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorImpl.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2005 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase;
-import org.eclipse.wst.common.internal.emf.resource.ReferencedResource;
-import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
-
-public class ResourceStateValidatorImpl implements ResourceStateValidator {
- protected ResourceStateInputProvider provider;
- protected Map lastNonRefreshStateMap;
- protected boolean isCheckingConsistency;
-
- class RefreshRunnable implements IWorkspaceRunnable {
- CoreException thrownException;
- List files;
- List resources;
-
- RefreshRunnable(List someFiles, List inconsistentResources) {
- files = someFiles;
- resources = inconsistentResources;
- }
-
- public CoreException getThrownException() {
- return thrownException;
- }
-
- public void run(IProgressMonitor aMonitor) {
- try {
- prepareResourcesForRefresh(resources);
- primRefreshFiles(files);
- } catch (CoreException e) {
- thrownException = e;
- }
- }
- }
-
- /**
- * Constructor for ResourceStateValidator.
- */
- public ResourceStateValidatorImpl(ResourceStateInputProvider aProvider) {
- provider = aProvider;
- }
-
- /**
- * This method should be called whenever <code>aListener</code> is activated (becomes active).
- * This will check the timestamps of the underlying files to see if they are different from the
- * last cached modified value. <code>aListener</code> should be prepared to prompt the user if
- * they would like to refresh with the contents on disk if we are dirty.
- */
- public void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
- checkConsistency(presenter);
- }
-
- public void lostActivation(ResourceStateValidatorPresenter presenter) throws CoreException {
- checkConsistency(presenter);
- }
-
- public boolean checkSave(ResourceStateValidatorPresenter presenter) throws CoreException {
- if (presenter == null)
- return false;
- if (!provider.isDirty())
- return false;
- List inconsistentResources = getInconsistentResources();
- List inconsistentFiles = getFiles(inconsistentResources);
- inconsistentFiles = addOtherInconsistentFiles(inconsistentFiles);
- if (inconsistentFiles == null || inconsistentFiles.isEmpty())
- return true;
- return presenter.promptForInconsistentFileOverwrite(inconsistentFiles);
- }
-
- /**
- * @see ResourceStateValidator#checkReadOnly()
- */
- public boolean checkReadOnly() {
- boolean result = checkReadOnlyResources();
- if (!result)
- result = checkReadOnlyNonResourceFiles();
- return result;
- }
-
- /**
- * Method checkReadOnlyNonResourceFiles.
- *
- * @return boolean
- */
- private boolean checkReadOnlyNonResourceFiles() {
- List files = provider.getNonResourceFiles();
- if (files == null || files.isEmpty())
- return false;
- int size = files.size();
- IFile file = null;
- for (int i = 0; i < size; i++) {
- file = (IFile) files.get(i);
- if (file.isReadOnly())
- return true;
- }
- return false;
- }
-
- /**
- * Method checkReadOnlyResources.
- *
- * @return boolean
- */
- private boolean checkReadOnlyResources() {
- List resources = provider.getResources();
- if (resources == null || resources.isEmpty())
- return false;
- int size = resources.size();
- Resource res = null;
- IFile file = null;
- for (int i = 0; i < size; i++) {
- res = (Resource) resources.get(i);
- file = WorkbenchResourceHelper.getFile(res);
- if (file != null && file.isReadOnly())
- return true;
- }
- return false;
- }
-
- protected void checkConsistency(ResourceStateValidatorPresenter presenter) throws CoreException {
- if (isCheckingConsistency || presenter == null)
- return;
- isCheckingConsistency = true;
- try {
- List inconsistentResources = getInconsistentResources();
- List inconsistentFiles = getFiles(inconsistentResources);
- inconsistentFiles = addOtherInconsistentFiles(inconsistentFiles);
- if (inconsistentFiles == null || inconsistentFiles.isEmpty())
- return;
- boolean shouldRefreshFiles = true;
- //Defect 208654 & 209631 want prompt no matter what.
- if (anyFileChangedSinceLastRefreshPrompt(inconsistentFiles)) {
- clearLastNonRefreshStateMap();
- shouldRefreshFiles = presenter.promptForInconsistentFileRefresh(inconsistentFiles);
- } else
- return;
- if (shouldRefreshFiles)
- refreshFiles(inconsistentFiles, inconsistentResources);
- else
- cacheLastNonRefreshFileStamps(inconsistentFiles);
- } finally {
- isCheckingConsistency = false;
- }
- }
-
- /**
- * Method cacheLastNonRefreshFileStamps.
- *
- * @param inconsistentFiles
- */
- private void cacheLastNonRefreshFileStamps(List inconsistentFiles) {
- if (inconsistentFiles != null && !inconsistentFiles.isEmpty()) {
- Map map = getLastNonRefreshStateMap();
- IFile file = null;
- long stamp = 0;
- for (int i = 0; i < inconsistentFiles.size(); i++) {
- file = (IFile) inconsistentFiles.get(i);
- stamp = WorkbenchResourceHelper.computeModificationStamp(file);
- map.put(file, new Long(stamp));
- }
- }
- }
-
- /**
- * Method cacheValidateState.
- *
- * @param result
- */
- private void cacheValidateState(IStatus aStatus, List readOnlyResources, List roNonResourceFiles) {
- if (aStatus.isOK()) {
- if (readOnlyResources != null && !readOnlyResources.isEmpty()) {
- ReferencedResource res = null;
- for (int i = 0; i < readOnlyResources.size(); i++) {
- res = (ReferencedResource) readOnlyResources.get(i);
- WorkbenchResourceHelper.setSynhronizationStamp(res, computeModificationStamp(res));
- }
- }
- provider.cacheNonResourceValidateState(roNonResourceFiles);
- }
- }
-
- private void clearLastNonRefreshStateMap() {
- if (lastNonRefreshStateMap != null)
- lastNonRefreshStateMap.clear();
- }
-
- /**
- * Method anyFileChangedSinceLastRefreshPrompt.
- *
- * @param inconsistentFiles
- * @return boolean
- */
- private boolean anyFileChangedSinceLastRefreshPrompt(List inconsistentFiles) {
- if (inconsistentFiles == null || inconsistentFiles.isEmpty())
- return false;
- if (lastNonRefreshStateMap == null || lastNonRefreshStateMap.isEmpty())
- return true;
- int size = inconsistentFiles.size();
- IFile file = null;
- Long stamp = null;
- for (int i = 0; i < size; i++) {
- file = (IFile) inconsistentFiles.get(i);
- stamp = (Long) getLastNonRefreshStateMap().get(file);
- if (stamp == null || (stamp.longValue() != WorkbenchResourceHelper.computeModificationStamp(file)))
- return true;
- }
- return false;
- }
-
- protected List addOtherInconsistentFiles(List inconsistentFiles) {
- if (inconsistentFiles == null || inconsistentFiles.isEmpty())
- return getNonResourceInconsistentFiles();
- List nonResFiles = getNonResourceInconsistentFiles();
- if (nonResFiles != null)
- inconsistentFiles.addAll(nonResFiles);
- return inconsistentFiles;
- }
-
- /**
- * Method getNonResourceInconsistentFiles.
- *
- * @return List
- */
- private List getNonResourceInconsistentFiles() {
- List files = provider.getNonResourceInconsistentFiles();
- if (files != null && !files.isEmpty())
- return files;
- //Determine consistency based on the synchronization of the IFile
- files = provider.getNonResourceFiles();
- if (files == null || files.isEmpty())
- return Collections.EMPTY_LIST;
- List inconsistent = null;
- int size = files.size();
- IFile file = null;
- for (int i = 0; i < size; i++) {
- file = (IFile) files.get(i);
- if (file.isAccessible() && !file.isSynchronized(IResource.DEPTH_ZERO)) {
- if (inconsistent == null)
- inconsistent = new ArrayList();
- inconsistent.add(file);
- }
- }
- if (inconsistent == null)
- inconsistent = Collections.EMPTY_LIST;
- return inconsistent;
- }
-
- protected List getInconsistentResources() {
- List mofResources = provider.getResources();
- List inconsistent = null;
- int size = mofResources.size();
- Resource res = null;
- ReferencedResource refRes = null;
- for (int i = 0; i < size; i++) {
- res = (Resource) mofResources.get(i);
- if (WorkbenchResourceHelper.isReferencedResource(res)) {
- refRes = (ReferencedResource) res;
- if (!WorkbenchResourceHelper.isConsistent(refRes) && (refRes.isLoaded() && !refRes.isNew())) {
- if (inconsistent == null)
- inconsistent = new ArrayList();
- inconsistent.add(refRes);
- }
- }
- }
- if (inconsistent == null)
- inconsistent = Collections.EMPTY_LIST;
- return inconsistent;
- }
-
- protected List getFiles(List refResources) {
- List files = new ArrayList(refResources.size());
- IFile file = null;
- ReferencedResource refRes = null;
- for (int i = 0; i < refResources.size(); i++) {
- refRes = (ReferencedResource) refResources.get(i);
- file = WorkbenchResourceHelper.getFile(refRes);
- if (file != null)
- files.add(file);
- }
- return files;
- }
-
- /**
- * This method should be called at least the first time a ResourceStateValidatorPresenter
- * becomes active and is about to edit its contents. The returned IStatus may have an ERROR
- * status which should be presented to the user.
- */
- public IStatus validateState(ResourceStateValidatorPresenter presenter) throws CoreException {
- List roResources, nonResROFiles, roFiles = null;
- List[] readOnly = selectReadOnlyResources(provider.getResources());
- roResources = readOnly[0];
- roFiles = readOnly[1];
- nonResROFiles = selectReadOnlyFiles(provider.getNonResourceFiles());
- if (nonResROFiles != null) {
- if (roFiles == null)
- roFiles = nonResROFiles;
- else
- roFiles.addAll(nonResROFiles);
- }
- if (roFiles == null || roFiles.isEmpty())
- return OK_STATUS;
- IFile[] files = new IFile[roFiles.size()];
- roFiles.toArray(files);
- Object ctx = presenter != null ? presenter.getValidateEditContext() : null;
- IStatus result = ResourcesPlugin.getWorkspace().validateEdit(files, ctx);
- cacheValidateState(result, roResources, nonResROFiles);
- if (!result.isOK())
- checkConsistency(presenter);
- return result;
- }
-
- /**
- * Method selectReadOnlyFiles.
- *
- * @param list
- * @param roFiles
- */
- private List selectReadOnlyFiles(List files) {
- if (files == null || files.isEmpty())
- return files;
- int size = files.size();
- List readOnly = null;
- IFile file = null;
- for (int i = 0; i < size; i++) {
- file = (IFile) files.get(i);
- if (file.isReadOnly()) {
- if (readOnly == null)
- readOnly = new ArrayList(size);
- readOnly.add(file);
- }
- }
- return readOnly;
- }
-
- /**
- * Method selectReadOnlyResources.
- *
- * @param list
- * @param roFiles
- * @return List
- */
- private List[] selectReadOnlyResources(List resources) {
- if (resources == null || resources.isEmpty())
- return new List[]{resources, null};
- IFile file = null;
- int size = resources.size();
- Resource res = null;
- List readOnly = null;
- List roFiles = null;
- for (int i = 0; i < size; i++) {
- res = (Resource) resources.get(i);
- file = WorkbenchResourceHelper.getFile(res);
- if (file != null && file.isReadOnly()) {
- if (readOnly == null)
- readOnly = new ArrayList(size);
- readOnly.add(res);
- if (roFiles == null)
- roFiles = new ArrayList(size);
- roFiles.add(file);
- }
- }
- return new List[]{readOnly, roFiles};
- }
-
- protected long computeModificationStamp(ReferencedResource resource) {
- return WorkbenchResourceHelper.computeModificationStamp(resource);
- }
-
-
- protected void refreshFiles(List someFiles, List inconsitentResources) throws CoreException {
- RefreshRunnable runnable = new RefreshRunnable(someFiles, inconsitentResources);
- ResourcesPlugin.getWorkspace().run(runnable, null);
- if (runnable.getThrownException() != null)
- throw runnable.getThrownException();
- }
-
- protected void primRefreshFiles(List someFiles) throws CoreException {
- int size = someFiles.size();
- IFile file = null;
- for (int i = 0; i < size; i++) {
- file = (IFile) someFiles.get(i);
- if (!file.isSynchronized(IResource.DEPTH_ZERO))
- file.refreshLocal(IResource.DEPTH_ONE, null);
- else
- refreshResource(file);
- }
- }
-
- /**
- * We need to remove the Resource that corresponds to the <code>file</code> to force a
- * refresh.
- */
- protected void refreshResource(IFile file) {
- Resource res = WorkbenchResourceHelperBase.getResource(file);
- if (res != null)
- res.unload();
- }
-
- /**
- * Force the resources to not be dirty to ensure that they will be removed from their
- * ResourceSet when their file is refreshed.
- */
- protected void prepareResourcesForRefresh(List refResources) {
- ReferencedResource res = null;
- for (int i = 0; i < refResources.size(); i++) {
- res = (ReferencedResource) refResources.get(i);
- res.setForceRefresh(true);
- }
- }
-
- /**
- * Gets the lastNonRefreshStateMap.
- *
- * @return Returns a Map
- */
- protected Map getLastNonRefreshStateMap() {
- if (lastNonRefreshStateMap == null)
- lastNonRefreshStateMap = new HashMap();
- return lastNonRefreshStateMap;
- }
-}
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorPresenter.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorPresenter.java
deleted file mode 100644
index 47545d304..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ResourceStateValidatorPresenter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/***************************************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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: IBM Corporation - initial API and implementation
- **************************************************************************************************/
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-
-public interface ResourceStateValidatorPresenter {
- /**
- * Present to the user that the <code>inconsistentFiles</code> will need to be refreshed in
- * the workbench. Return true if the refresh should occur. The List will be a list of IFiles.
- *
- * @param inconsistentFiles
- * @return boolean
- */
- boolean promptForInconsistentFileRefresh(List inconsistentFiles);
-
- /**
- * Return the context (Shell) that would be passed to the validateEdit method. If this method
- * returns null, a prompt to check out code will not be presented to the user.
- *
- * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[],
- * java.lang.Object)
- */
- Object getValidateEditContext();
-
- /**
- * Present a dialog to the user that indicates that the user is about to save and overwrite the
- * list of <code>inconsitentFiles</codes>. Return true if
- * the overwrite should proceed. The list of <code>inconsitentFiles</codes> will
- * be a list of IFiles.
- * @param inconsistentFiles
- * @return boolean
- */
- boolean promptForInconsistentFileOverwrite(List inconsistentFiles);
-
- /**
- * This method should be called by any action that is about to edit any contents of any IFile.
- */
- public IStatus validateState();
-}
-
diff --git a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ValidateEditHeadlessContext.java b/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ValidateEditHeadlessContext.java
deleted file mode 100644
index 11efe031b..000000000
--- a/plugins/org.eclipse.wst.common.emfworkbench.integration/src/org/eclipse/wst/common/internal/emfworkbench/validateedit/ValidateEditHeadlessContext.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2004 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-/*
- * Created on May 18, 2004
- */
-package org.eclipse.wst.common.internal.emfworkbench.validateedit;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.wst.common.internal.emfworkbench.integration.EditModel;
-
-
-/**
- * @author jlanuti Headless Validate Edit Context Implementation
- */
-public class ValidateEditHeadlessContext implements IValidateEditContext {
-
- protected boolean fNeedsStateValidation = true;
- protected boolean fMessageUp = false;
- protected EditModel fValidator = null;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.IValidateEditContext#validateState()
- */
- public IStatus validateState() {
- // For now do nothing in headless state
- return Status.OK_STATUS;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter#getValidateEditContext()
- */
- public Object getValidateEditContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter#promptForInconsistentFileOverwrite(java.util.List)
- */
- public boolean promptForInconsistentFileOverwrite(List inconsistentFiles) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter#promptForInconsistentFileRefresh(java.util.List)
- */
- public boolean promptForInconsistentFileRefresh(List inconsistentFiles) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /**
- * @see IValidateEditListener#setNeedsStateValidation(boolean)
- */
- public void setNeedsStateValidation(boolean needsStateValidation) {
- fNeedsStateValidation = needsStateValidation;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.IValidateEditContext#setEditModel(org.eclipse.wst.common.internal.emfworkbench.integration.EditModel)
- */
- public void setEditModel(EditModel fValidator) {
- this.fValidator = fValidator;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.common.internal.emfworkbench.validateedit.IValidateEditContext#validateState(org.eclipse.wst.common.internal.emfworkbench.integration.EditModel)
- */
- public IStatus validateState(EditModel editModel) {
- setEditModel(editModel);
- return validateState();
- }
-} \ No newline at end of file

Back to the top