diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IStorageProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IStorageProvider.java index 58a620d44f80936f8a8f4fcef6b45cb768e8f3d7..9ae5f721eebb354ba96111e4122d6ae9c7a0e099 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IStorageProvider.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IStorageProvider.java @@ -19,9 +19,6 @@ package org.fortiss.tooling.kernel.interfaces; import java.util.List; -import org.eclipse.emf.common.command.CommandStack; -import org.eclipse.emf.ecore.EObject; - /** * An {@link IStorageProvider} implements a storage mechanism for EMF models. * @@ -33,12 +30,6 @@ import org.eclipse.emf.ecore.EObject; public interface IStorageProvider { /** Returns the top-level elements provided by this storage provider. */ - List<EObject> getTopLevelElements(); - - /** Returns the command stack for accessing the stored model. */ - CommandStack getCommandStack(EObject modelElement); - - /** Executes the given {@link Runnable} as model changing command-. */ - void runAsCommand(EObject modelElement, Runnable runner); + List<ITopLevelElementContext> getTopLevelElementContexts(); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementChangeListener.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementChangeListener.java index 38119cc5b02339515bf0e4cd6146f7ddebe41104..60274f7f21ce47f66e8caf03b9396a65fd1fb430 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementChangeListener.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementChangeListener.java @@ -17,8 +17,6 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.interfaces; -import org.eclipse.emf.ecore.EObject; - /** * Listener interface notified by the persistency service whenever the list of * top-level elements changes. @@ -31,8 +29,8 @@ import org.eclipse.emf.ecore.EObject; public interface ITopLevelElementChangeListener { /** Notifies the listener about the adding of the given element. */ - void topLevelElementAdded(EObject topLevelElement); + void topLevelElementAdded(ITopLevelElementContext elmentContext); /** Notifies the listener about the removal of the given element. */ - void topLevelElementRemoved(EObject topLevelElement); + void topLevelElementRemoved(ITopLevelElementContext elmentContext); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementContext.java new file mode 100644 index 0000000000000000000000000000000000000000..fff99cae5bd62075e411becb113cd2db93fedde7 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ITopLevelElementContext.java @@ -0,0 +1,70 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.interfaces; + +import java.io.IOException; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.command.CommandStackListener; +import org.eclipse.emf.ecore.EObject; + +/** + * Interface for accessing top-level elements provided by + * {@link IStorageProvider}s. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public interface ITopLevelElementContext { + + /** Returns the top-level model element represented by this context. */ + EObject getTopLevelElement(); + + /** Executes the given {@link Runnable} as model changing command-. */ + void runAsCommand(Runnable runner); + + /** Adds a command stack listener. */ + void addCommandStackListener(CommandStackListener listener); + + /** Removes the command stack listener. */ + void removeCommandStackListener(CommandStackListener listener); + + /** Returns whether undo operation is possible. */ + boolean canUndo(); + + /** Returns whether redo operation is possible. */ + boolean canRedo(); + + /** Executes the undo operation. */ + void undo(); + + /** Executes the redo operation. */ + void redo(); + + /** Returns whether there is unsaved content. */ + boolean isDirty(); + + /** Returns the name of the saveable unit. */ + String getSaveableName(); + + /** Performs the save operation. */ + void doSave(IProgressMonitor monitor) throws CoreException, IOException; +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java index 3861ea32a77c0ebc073e794963768b78caf9f0ea..05685793624a86a25f3649acdfe39f341d5306a6 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java @@ -135,7 +135,7 @@ public class ActionService implements IActionService { /** {@inheritDoc} */ @Override - public void update() { + public void refresh() { EObject target = EObjectSelectionUtils .getCurrentSelectionFirstElement(); @@ -157,8 +157,7 @@ public class ActionService implements IActionService { boolean canDelete = (target instanceof IRemovable) && ((IRemovable) target).canRemove(); canDelete = canDelete - || !IPersistencyService.INSTANCE.getTopLevelElements() - .contains(target); + || !IPersistencyService.INSTANCE.isTopLevelElement(target); globalDeleteAction.setTarget(target); globalDeleteAction.setEnabled(canDelete); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java index e0b8351b4423f2f41b2fb2a02f506de630205857..1b5871478ce4b7b56ef4ed31f68489f5171e1c64 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CommandStackService.java @@ -17,9 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.ecore.EObject; -import org.fortiss.tooling.kernel.interfaces.IStorageProvider; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.services.ICommandStackService; import org.fortiss.tooling.kernel.services.IPersistencyService; @@ -36,41 +35,41 @@ public class CommandStackService implements ICommandStackService { /** {@inheritDoc} */ @Override public void runAsCommand(EObject target, Runnable runner) { - IStorageProvider provider = IPersistencyService.INSTANCE - .getStorageProviderFor(target); - if (provider != null) { - provider.runAsCommand(target, runner); + ITopLevelElementContext context = IPersistencyService.INSTANCE + .getTopLevelElementContextFor(target); + if (context != null) { + context.runAsCommand(runner); } } /** {@inheritDoc} */ @Override public boolean canUndo(EObject target) { - CommandStack stack = getCommandStack(target); - return stack != null && stack.canUndo(); + ITopLevelElementContext context = IPersistencyService.INSTANCE + .getTopLevelElementContextFor(target); + return context != null && context.canUndo(); } /** {@inheritDoc} */ @Override public boolean canRedo(EObject target) { - CommandStack stack = getCommandStack(target); - return stack != null && stack.canRedo(); + ITopLevelElementContext context = IPersistencyService.INSTANCE + .getTopLevelElementContextFor(target); + return context != null && context.canRedo(); } /** {@inheritDoc} */ @Override public void undo(EObject target) { - getCommandStack(target).undo(); + IPersistencyService.INSTANCE.getTopLevelElementContextFor(target) + .undo(); + } /** {@inheritDoc} */ @Override public void redo(EObject target) { - getCommandStack(target).redo(); - } - - /** Fetches command stack from persistency service. */ - private CommandStack getCommandStack(EObject target) { - return IPersistencyService.INSTANCE.getCommandStack(target); + IPersistencyService.INSTANCE.getTopLevelElementContextFor(target) + .redo(); } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java index df0d6f12adada01471ed2c24ff1217829b24b5fc..9faa26537e2fede0f39fa659c5c3029c443e5bfc 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java @@ -17,13 +17,29 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; +import java.io.IOException; +import java.util.EventObject; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.command.CommandStackListener; import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.Saveable; import org.eclipse.ui.part.ViewPart; +import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.interfaces.ITopLevelElementChangeListener; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.internal.navigator.NavigatorViewPart; import org.fortiss.tooling.kernel.services.INavigatorService; import org.fortiss.tooling.kernel.services.IPersistencyService; +import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; /** * This class implements the {@link INavigatorService} interface. @@ -34,13 +50,21 @@ import org.fortiss.tooling.kernel.services.IPersistencyService; * @levd.rating RED Rev: */ public class NavigatorService implements INavigatorService, - ITopLevelElementChangeListener { + ITopLevelElementChangeListener, CommandStackListener { /** Stores the navigator view. */ private NavigatorViewPart navigatorViewPart; + /** Stores the {@link Saveable}s for the top-level elements. */ + private Map<ITopLevelElementContext, TopLevelElementSaveable> saveables = new HashMap<ITopLevelElementContext, NavigatorService.TopLevelElementSaveable>(); + /** Constructor. */ public NavigatorService() { + for (ITopLevelElementContext context : IPersistencyService.INSTANCE + .getTopLevelElementContexts()) { + context.addCommandStackListener(this); + saveables.put(context, new TopLevelElementSaveable(context)); + } IPersistencyService.INSTANCE.addTopLevelElementListener(this); } @@ -64,13 +88,106 @@ public class NavigatorService implements INavigatorService, /** {@inheritDoc} */ @Override - public void topLevelElementAdded(EObject topLevelElement) { + public void topLevelElementAdded(ITopLevelElementContext context) { + context.addCommandStackListener(this); + saveables.put(context, new TopLevelElementSaveable(context)); + navigatorViewPart.refresh(); + } + + /** {@inheritDoc} */ + @Override + public void topLevelElementRemoved(ITopLevelElementContext context) { + context.removeCommandStackListener(this); + saveables.remove(context); navigatorViewPart.refresh(); } /** {@inheritDoc} */ @Override - public void topLevelElementRemoved(EObject topLevelElement) { + public void commandStackChanged(EventObject event) { navigatorViewPart.refresh(); } + + /** {@inheritDoc} */ + @Override + public Saveable[] getSaveables() { + return saveables.values().toArray(new Saveable[saveables.size()]); + } + + /** {@inheritDoc} */ + @Override + public Saveable[] getActiveSaveables() { + Set<Saveable> result = new HashSet<Saveable>(); + for (EObject selection : EObjectSelectionUtils + .getCurrentSelectionEObjects()) { + ITopLevelElementContext context = IPersistencyService.INSTANCE + .getTopLevelElementContextFor(selection); + if (saveables.get(context) != null) { + result.add(saveables.get(context)); + } + } + return result.toArray(new Saveable[result.size()]); + } + + /** + * Implementation of {@link Saveable}s for {@link ITopLevelElementContext}s. + */ + private static class TopLevelElementSaveable extends Saveable { + + /** Stores the {@link ITopLevelElementContext}. */ + public final ITopLevelElementContext context; + + /** Constructor. */ + public TopLevelElementSaveable(ITopLevelElementContext context) { + this.context = context; + } + + /** {@inheritDoc} */ + @Override + public String getName() { + return context.getSaveableName(); + } + + /** {@inheritDoc} */ + @Override + public String getToolTipText() { + return ""; + } + + /** {@inheritDoc} */ + @Override + public ImageDescriptor getImageDescriptor() { + return null; + } + + /** {@inheritDoc} */ + @Override + public void doSave(IProgressMonitor monitor) throws CoreException { + try { + context.doSave(monitor); + } catch (IOException e) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Error during save of " + getName(), e); + } + } + + /** {@inheritDoc} */ + @Override + public boolean isDirty() { + return context.isDirty(); + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object object) { + return object instanceof TopLevelElementSaveable + && ((TopLevelElementSaveable) object).context == context; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + return context.hashCode(); + } + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PersistencyService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PersistencyService.java index a0600e968c66a68ea9e6c9d048d850ae39f048a8..2e94b94a0328f842751810575ffb1dbd5d870ecd 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PersistencyService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PersistencyService.java @@ -25,10 +25,11 @@ import java.util.Map; import org.conqat.lib.commons.collections.CollectionUtils; import org.conqat.lib.commons.collections.UnmodifiableList; -import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.interfaces.IStorageProvider; import org.fortiss.tooling.kernel.interfaces.ITopLevelElementChangeListener; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.internal.storage.eclipse.EclipseResourceStorageProvider; import org.fortiss.tooling.kernel.services.IPersistencyService; @@ -42,8 +43,11 @@ import org.fortiss.tooling.kernel.services.IPersistencyService; */ public class PersistencyService implements IPersistencyService { + /** Stores the top-level element contexts. */ + private final List<ITopLevelElementContext> contextCache = new LinkedList<ITopLevelElementContext>(); + /** Stores the storage providers and their element caches. */ - private final Map<IStorageProvider, List<EObject>> storageProviderCache = new HashMap<IStorageProvider, List<EObject>>(); + private final Map<ITopLevelElementContext, IStorageProvider> storageProviderCache = new HashMap<ITopLevelElementContext, IStorageProvider>(); /** Stores the top-level element listeners. */ private final List<ITopLevelElementChangeListener> listeners = new ArrayList<ITopLevelElementChangeListener>(); @@ -52,70 +56,78 @@ public class PersistencyService implements IPersistencyService { public PersistencyService() { // TODO (FH): replace with extension mechanism IStorageProvider provider = new EclipseResourceStorageProvider(); - storageProviderCache.put(provider, new LinkedList<EObject>()); - storageProviderCache.get(provider).addAll( - provider.getTopLevelElements()); + for (ITopLevelElementContext context : provider + .getTopLevelElementContexts()) { + contextCache.add(context); + storageProviderCache.put(context, provider); + } + } + + /** {@inheritDoc} */ + @Override + public UnmodifiableList<ITopLevelElementContext> getTopLevelElementContexts() { + return CollectionUtils.asUnmodifiable(contextCache); + } - refreshAllProviderElements(); + /** {@inheritDoc} */ + @Override + public boolean isTopLevelElement(EObject element) { + for (ITopLevelElementContext context : contextCache) { + if (context.getTopLevelElement() == element) { + return true; + } + } + return false; } /** {@inheritDoc} */ @Override - public UnmodifiableList<EObject> getTopLevelElements() { - List<EObject> result = new ArrayList<EObject>(); - for (IStorageProvider provider : storageProviderCache.keySet()) { - result.addAll(storageProviderCache.get(provider)); + public boolean isDirty() { + for (ITopLevelElementContext context : contextCache) { + if (context.isDirty()) { + return true; + } } - return CollectionUtils.asUnmodifiable(result); + return false; + } + + /** {@inheritDoc} */ + @Override + public void doSave(IProgressMonitor monitor) { + // TODO Auto-generated method stub + } /** {@inheritDoc} */ @Override public void refreshTopLevelElements(IStorageProvider provider) { - if (!storageProviderCache.containsKey(provider)) { + if (provider == null) { return; } - List<EObject> elementCache = storageProviderCache.get(provider); - List<EObject> providedElements = provider.getTopLevelElements(); - List<EObject> removedCacheElements = new LinkedList<EObject>(); - for (EObject top : elementCache) { - if (!providedElements.contains(top)) { + + List<ITopLevelElementContext> providedElements = provider + .getTopLevelElementContexts(); + List<ITopLevelElementContext> removedCacheElements = new LinkedList<ITopLevelElementContext>(); + for (ITopLevelElementContext top : contextCache) { + if (provider == storageProviderCache.get(top) + && !providedElements.contains(top)) { removedCacheElements.add(top); } } - for (EObject top : providedElements) { - if (!elementCache.contains(top)) { - elementCache.add(top); + for (ITopLevelElementContext top : providedElements) { + if (!contextCache.contains(top)) { + contextCache.add(top); + storageProviderCache.put(top, provider); notifyListenersAboutAdd(top); } } - for (EObject top : removedCacheElements) { - elementCache.remove(top); + for (ITopLevelElementContext top : removedCacheElements) { + contextCache.remove(top); + storageProviderCache.remove(top); notifyListenersAboutRemove(top); } } - /** Refreshes all providers' top-level elements. */ - private void refreshAllProviderElements() { - for (IStorageProvider provider : storageProviderCache.keySet()) { - refreshTopLevelElements(provider); - } - } - - /** Notifies listener about top-level element adding. */ - private void notifyListenersAboutAdd(EObject top) { - for (ITopLevelElementChangeListener listener : listeners) { - listener.topLevelElementAdded(top); - } - } - - /** Notifies listener about top-level element removal. */ - private void notifyListenersAboutRemove(EObject top) { - for (ITopLevelElementChangeListener listener : listeners) { - listener.topLevelElementRemoved(top); - } - } - /** {@inheritDoc} */ @Override public void addTopLevelElementListener( @@ -132,38 +144,32 @@ public class PersistencyService implements IPersistencyService { listeners.remove(listener); } - /** {@inheritDoc} */ - @Override - public EObject getTopLevelElementFor(EObject modelElement) { - while (modelElement != null) { - for (List<EObject> topLevelElements : storageProviderCache.values()) { - if (topLevelElements.contains(modelElement)) { - return modelElement; - } - } - modelElement = modelElement.eContainer(); + /** Notifies listener about top-level element adding. */ + private void notifyListenersAboutAdd(ITopLevelElementContext top) { + for (ITopLevelElementChangeListener listener : listeners) { + listener.topLevelElementAdded(top); + } + } + + /** Notifies listener about top-level element removal. */ + private void notifyListenersAboutRemove(ITopLevelElementContext top) { + for (ITopLevelElementChangeListener listener : listeners) { + listener.topLevelElementRemoved(top); } - return null; } /** {@inheritDoc} */ @Override - public IStorageProvider getStorageProviderFor(EObject modelElement) { + public ITopLevelElementContext getTopLevelElementContextFor( + EObject modelElement) { while (modelElement != null) { - for (IStorageProvider provider : storageProviderCache.keySet()) { - if (storageProviderCache.get(provider).contains(modelElement)) { - return provider; + for (ITopLevelElementContext context : contextCache) { + if (context.getTopLevelElement() == modelElement) { + return context; } } modelElement = modelElement.eContainer(); } return null; } - - /** {@inheritDoc} */ - @Override - public CommandStack getCommandStack(EObject modelElement) { - return getStorageProviderFor(modelElement) - .getCommandStack(modelElement); - } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeContentProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeContentProvider.java index 6ec7533b18c8324f7c55bb34e08a7d937c0c9488..93d4177c6e11f54563b0684dab83a4224f6805cf 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeContentProvider.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeContentProvider.java @@ -17,10 +17,14 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal.navigator; +import java.util.LinkedList; +import java.util.List; + import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; import org.fortiss.tooling.kernel.interfaces.IHandler; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.services.IModelElementService; import org.fortiss.tooling.kernel.services.IPersistencyService; @@ -37,8 +41,14 @@ public class NavigatorTreeContentProvider implements ITreeContentProvider { /** {@inheritDoc} */ @Override public Object[] getElements(Object inputElement) { - // delegate to the top-level elements of the persistency service - return IPersistencyService.INSTANCE.getTopLevelElements().toArray(); + // delegate to the top-level element contexts of the persistency service + List<EObject> result = new LinkedList<EObject>(); + + for (ITopLevelElementContext context : IPersistencyService.INSTANCE + .getTopLevelElementContexts()) { + result.add(context.getTopLevelElement()); + } + return result.toArray(); } /** {@inheritDoc} */ @@ -59,8 +69,8 @@ public class NavigatorTreeContentProvider implements ITreeContentProvider { @Override public Object getParent(Object element) { if (element instanceof EObject - && IPersistencyService.INSTANCE.getTopLevelElements().contains( - element)) { + && IPersistencyService.INSTANCE + .isTopLevelElement((EObject) element)) { // delegate to persistency service return IPersistencyService.INSTANCE; } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java index 9c9a1f01bd93f49e4113e76d4a46d4758abcc400..c72759531b344ae32b779733e778ffbb7e88bf92 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java @@ -38,9 +38,13 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IDecoratorManager; +import org.eclipse.ui.ISaveablePart; +import org.eclipse.ui.ISaveablesSource; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartConstants; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.Saveable; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.views.properties.IPropertySheetPage; @@ -66,7 +70,8 @@ import org.fortiss.tooling.kernel.util.EObjectSelectionUtils; */ public final class NavigatorViewPart extends ViewPart implements ISelectionListener, ISelectionChangedListener, IDoubleClickListener, - ITabbedPropertySheetPageContributor, ICustomMenuContributor { + ITabbedPropertySheetPageContributor, ICustomMenuContributor, + ISaveablesSource, ISaveablePart { /** Stores the TreeViewer. */ private TreeViewer viewer; @@ -78,6 +83,10 @@ public final class NavigatorViewPart extends ViewPart implements private final UIJob updateUI = new UIJob("Update Model Navigator") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { + if (viewer.getControl().isDisposed()) { + return Status.OK_STATUS; + } + IActionService.INSTANCE.refresh(); viewer.refresh(); return Status.OK_STATUS; } @@ -85,7 +94,6 @@ public final class NavigatorViewPart extends ViewPart implements /** Constructor. */ public NavigatorViewPart() { - ((NavigatorService) INavigatorService.INSTANCE) .setNavigatorViewPart(this); } @@ -146,14 +154,14 @@ public final class NavigatorViewPart extends ViewPart implements /** {@inheritDoc} */ @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { - IActionService.INSTANCE.update(); + IActionService.INSTANCE.refresh(); // TODO (FH): implement link with editor feature here } /** {@inheritDoc} */ @Override public void selectionChanged(SelectionChangedEvent event) { - IActionService.INSTANCE.update(); + IActionService.INSTANCE.refresh(); } /** {@inheritDoc} */ @@ -212,6 +220,52 @@ public final class NavigatorViewPart extends ViewPart implements /** Refreshes the navigator view. */ public void refresh() { + if (INavigatorService.INSTANCE.getNavigatorView() != this) { + return; + } updateUI.schedule(); + firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); + } + + /** {@inheritDoc} */ + @Override + public Saveable[] getSaveables() { + return INavigatorService.INSTANCE.getSaveables(); + } + + /** {@inheritDoc} */ + @Override + public Saveable[] getActiveSaveables() { + return INavigatorService.INSTANCE.getActiveSaveables(); + } + + /** {@inheritDoc} */ + @Override + public void doSave(IProgressMonitor monitor) { + // ignore. SaveableSource is used instead. + } + + /** {@inheritDoc} */ + @Override + public void doSaveAs() { + // ignore + } + + /** {@inheritDoc} */ + @Override + public boolean isDirty() { + return IPersistencyService.INSTANCE.isDirty(); + } + + /** {@inheritDoc} */ + @Override + public boolean isSaveAsAllowed() { + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean isSaveOnCloseNeeded() { + return isDirty(); } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java index d6a2d6cbf38b1c4990f0f3561a0fb9531718bc8d..01829501baef9de91682ad7d725aa9d8fe8fea59 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/properties/PropertiesAdapterFactory.java @@ -41,7 +41,7 @@ public final class PropertiesAdapterFactory implements IAdapterFactory { && adaptableObject instanceof EObject) { EObject modelElement = (EObject) adaptableObject; if (IPersistencyService.INSTANCE - .getTopLevelElementFor(modelElement) != null) { + .getTopLevelElementContextFor(modelElement) != null) { return new ITabbedPropertySheetPageContributor() { @Override diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EMultiContentsIterator.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EMultiContentsIterator.java deleted file mode 100644 index 6bd463b0e0d44f8545e9d8068738b2b786104a7f..0000000000000000000000000000000000000000 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EMultiContentsIterator.java +++ /dev/null @@ -1,87 +0,0 @@ -/*--------------------------------------------------------------------------+ -$Id$ -| | -| Copyright 2011 ForTISS GmbH | -| | -| Licensed under the Apache License, Version 2.0 (the "License"); | -| you may not use this file except in compliance with the License. | -| You may obtain a copy of the License at | -| | -| http://www.apache.org/licenses/LICENSE-2.0 | -| | -| Unless required by applicable law or agreed to in writing, software | -| distributed under the License is distributed on an "AS IS" BASIS, | -| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | -| See the License for the specific language governing permissions and | -| limitations under the License. | -+--------------------------------------------------------------------------*/ -package org.fortiss.tooling.kernel.internal.storage.eclipse; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.emf.ecore.EObject; - -/** - * An iterator class which is similar to the iterator returned from - * {@link EObject#eAllContents()}, but can be used on multiple objects and also - * includes the objects themselves. - * - * @author hummelb - * @author $Author$ - * @version $Rev$ - * @levd.rating GREEN Rev: 1794 - */ -public class EMultiContentsIterator implements Iterator<EObject> { - - /** The objects to iterate on. */ - private final EObject[] objects; - - /** Current index into the array. */ - private int currentIndex = 0; - - /** Inner iterator. */ - private Iterator<EObject> inner = null; - - /** Constructor. */ - public EMultiContentsIterator(EObject... objects) { - this.objects = objects; - } - - /** Constructor. */ - public EMultiContentsIterator(Collection<EObject> objects) { - this.objects = objects.toArray(new EObject[objects.size()]); - } - - /** {@inheritDoc} */ - @Override - public boolean hasNext() { - return currentIndex < objects.length; - } - - /** {@inheritDoc} */ - @Override - public EObject next() { - EObject result; - if (inner == null) { - result = objects[currentIndex]; - inner = result.eAllContents(); - } else { - result = inner.next(); - } - - // already check whether there is more to come - if (!inner.hasNext()) { - inner = null; - currentIndex++; - } - - return result; - } - - /** Removal is not supported. */ - @Override - public void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java index 57cce8c477dffcfc3bd4f1d46ba4834207ca86c5..c75c012e747dad333337fe358cfd3b8a2bd2d657 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/EclipseResourceStorageProvider.java @@ -35,12 +35,11 @@ import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.IResourceDeltaVisitor; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; -import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.swt.widgets.Display; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.interfaces.IStorageProvider; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.services.IPersistencyService; /** @@ -52,8 +51,8 @@ import org.fortiss.tooling.kernel.services.IPersistencyService; * @version $Rev$ * @levd.rating RED Rev: */ -public class EclipseResourceStorageProvider implements IStorageProvider, - IResourceChangeListener { +public class EclipseResourceStorageProvider implements IResourceChangeListener, + IResourceDeltaVisitor, IStorageProvider { /** Cache of models loaded so far. */ private final Map<IFile, ModelContext> loadedContexts = new HashMap<IFile, ModelContext>(); @@ -99,37 +98,7 @@ public class EclipseResourceStorageProvider implements IStorageProvider, return; } try { - event.getDelta().accept(new IResourceDeltaVisitor() { - @Override - public boolean visit(IResourceDelta delta) { - if (delta.getResource() instanceof IFile - && delta.getResource().getParent() instanceof IProject - && delta.getResource().getFileExtension() - .equals("af3_20")) { - IFile file = (IFile) delta.getResource(); - if (delta.getKind() == IResourceDelta.ADDED) { - try { - loadContext(file); - } catch (IOException ioex) { - LoggingUtils.error( - ToolingKernelActivator.getDefault(), - "Had an error during reloading the file!", - ioex); - } - } else if (delta.getKind() == IResourceDelta.REMOVED - && isLoaded(file)) { - unloadContext((IFile) delta.getResource()); - } else if (delta.getKind() == IResourceDelta.CHANGED) { - handleChange((IFile) delta.getResource()); - } - - // Refresh the top-level elements - IPersistencyService.INSTANCE - .refreshTopLevelElements(EclipseResourceStorageProvider.this); - } - return true; - } - }); + event.getDelta().accept(this); } catch (final CoreException e) { LoggingUtils.error(ToolingKernelActivator.getDefault(), "Should not happen!", e); @@ -137,6 +106,34 @@ public class EclipseResourceStorageProvider implements IStorageProvider, } } + /** {@inheritDoc} */ + @Override + public boolean visit(IResourceDelta delta) { + if (delta.getResource() instanceof IFile + && delta.getResource().getParent() instanceof IProject + && delta.getResource().getFileExtension().equals("af3_20")) { + IFile file = (IFile) delta.getResource(); + if (delta.getKind() == IResourceDelta.ADDED) { + try { + loadContext(file); + } catch (IOException ioex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Had an error during reloading the file!", ioex); + } + } else if (delta.getKind() == IResourceDelta.REMOVED + && isLoaded(file)) { + unloadContext((IFile) delta.getResource()); + } else if (delta.getKind() == IResourceDelta.CHANGED) { + handleChange((IFile) delta.getResource()); + } + + // Refresh the top-level elements + IPersistencyService.INSTANCE + .refreshTopLevelElements(EclipseResourceStorageProvider.this); + } + return true; + } + /** Handles a change of the given file (which is actually managed). */ private void handleChange(final IFile file) { final ModelContext context = loadedContexts.get(file); @@ -186,9 +183,7 @@ public class EclipseResourceStorageProvider implements IStorageProvider, private ModelContext loadContext(IFile file) throws IOException { ModelContext mc = new ModelContext(file); loadedContexts.put(file, mc); - for (EObject top : mc.getTopLevelElements()) { - rootElementContexts.put(top, mc); - } + rootElementContexts.put(mc.getTopLevelElement(), mc); return mc; } @@ -196,44 +191,16 @@ public class EclipseResourceStorageProvider implements IStorageProvider, private void unloadContext(IFile file) { final ModelContext context = loadedContexts.remove(file); if (context != null) { - for (EObject top : context.getTopLevelElements()) { - rootElementContexts.remove(top); - } + rootElementContexts.remove(context.getTopLevelElement()); context.destroy(); } } - /** - * Returns the model context for the given model element. This operation is - * implemented by traversing upwards along the parent hierarchy and checking - * all known model contexts if they include the top-most element. If no - * context is found, null is returned. - */ - private synchronized ModelContext getContext(EObject o) { - return rootElementContexts.get(EcoreUtil.getRootContainer(o)); - } - /** {@inheritDoc} */ @Override - public List<EObject> getTopLevelElements() { - List<EObject> result = new ArrayList<EObject>(); - result.addAll(rootElementContexts.keySet()); + public List<ITopLevelElementContext> getTopLevelElementContexts() { + List<ITopLevelElementContext> result = new ArrayList<ITopLevelElementContext>(); + result.addAll(rootElementContexts.values()); return result; } - - /** {@inheritDoc} */ - @Override - public CommandStack getCommandStack(EObject modelElement) { - ModelContext mc = getContext(modelElement); - if (mc != null) { - return mc.getTransactionalCommandStack(); - } - return null; - } - - /** {@inheritDoc} */ - @Override - public void runAsCommand(EObject modelElement, Runnable runner) { - getContext(modelElement).runAsCommand(runner); - } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/ModelContext.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/ModelContext.java index 560cf3cc3506f47741a8d07a288e7eaf2981e753..8d677ea11ad5ed94298e345b06020f0d11d03893 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/ModelContext.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/storage/eclipse/ModelContext.java @@ -24,13 +24,12 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Set; import org.conqat.ide.commons.ui.logging.LoggingUtils; -import org.conqat.lib.commons.collections.CollectionUtils; import org.conqat.lib.commons.collections.IdentityHashSet; -import org.conqat.lib.commons.collections.UnmodifiableList; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; @@ -40,6 +39,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.command.AbstractCommand; import org.eclipse.emf.common.command.BasicCommandStack; import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.emf.common.command.CommandStackListener; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; @@ -48,6 +48,7 @@ import org.eclipse.emf.transaction.TransactionalCommandStack; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.ui.IEditorPart; import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.model.IIdLabeled; import org.fortiss.tooling.kernel.services.IModelElementService; import org.fortiss.tooling.kernel.util.EMFResourceUtils; @@ -61,7 +62,7 @@ import org.fortiss.tooling.kernel.util.EMFResourceUtils; * @version $Rev$ * @levd.rating YELLOW Rev: 1101 */ -class ModelContext { +class ModelContext implements ITopLevelElementContext { /** The resource set we are using. */ private final ResourceSet rset; @@ -107,12 +108,30 @@ class ModelContext { checkIDs(); } + /** {@inheritDoc} */ + @Override + public EObject getTopLevelElement() { + return r.getContents().get(0); + } + + /** {@inheritDoc} */ + @Override + public void addCommandStackListener(CommandStackListener listener) { + transactionalCommandStack.addCommandStackListener(listener); + } + + /** {@inheritDoc} */ + @Override + public void removeCommandStackListener(CommandStackListener listener) { + transactionalCommandStack.removeCommandStackListener(listener); + } + /** Checks whether all IDs are present and updates {@link #maxId}. */ private void checkIDs() { boolean hadMissing = false; - for (final Iterator<EObject> i = new EMultiContentsIterator( - getTopLevelElements()); i.hasNext();) { - final EObject eo = i.next(); + for (Iterator<EObject> i = getTopLevelElement().eAllContents(); i + .hasNext();) { + EObject eo = i.next(); if (eo instanceof IIdLabeled) { if (((IIdLabeled) eo).getId() <= 0) { hadMissing = true; @@ -133,9 +152,9 @@ class ModelContext { /** Generates missing IDs. Must be called within transaction. */ private void generateMissingIDs() { - for (final Iterator<EObject> i = new EMultiContentsIterator( - getTopLevelElements()); i.hasNext();) { - final EObject eo = i.next(); + for (Iterator<EObject> i = getTopLevelElement().eAllContents(); i + .hasNext();) { + EObject eo = i.next(); if (eo instanceof IIdLabeled) { if (((IIdLabeled) eo).getId() <= 0) { ((IIdLabeled) eo).setId((++maxId)); @@ -151,9 +170,8 @@ class ModelContext { */ /* package */void prepareIDsForCompose(EObject other) { boolean needSmart = false; - for (final Iterator<EObject> i = new EMultiContentsIterator(other); i - .hasNext();) { - final EObject eo = i.next(); + for (Iterator<EObject> i = other.eAllContents(); i.hasNext();) { + EObject eo = i.next(); if (eo instanceof IIdLabeled) { if (((IIdLabeled) eo).getId() <= 0) { ((IIdLabeled) eo).setId(++maxId); @@ -164,21 +182,20 @@ class ModelContext { } if (needSmart) { - final Set<Integer> usedIDs = new HashSet<Integer>(); - for (final Iterator<EObject> i = new EMultiContentsIterator( - getTopLevelElements()); i.hasNext();) { - final EObject eo = i.next(); + Set<Integer> usedIDs = new HashSet<Integer>(); + for (Iterator<EObject> i = getTopLevelElement().eAllContents(); i + .hasNext();) { + EObject eo = i.next(); if (eo instanceof IIdLabeled) { usedIDs.add(((IIdLabeled) eo).getId()); } } - for (final Iterator<EObject> i = new EMultiContentsIterator(other); i - .hasNext();) { - final EObject eo = i.next(); + for (Iterator<EObject> i = other.eAllContents(); i.hasNext();) { + EObject eo = i.next(); if (eo instanceof IIdLabeled) { if (!usedIDs.add(((IIdLabeled) eo).getId())) { - final int newId = ++maxId; + int newId = ++maxId; ((IIdLabeled) eo).setId(newId); usedIDs.add(newId); } @@ -205,8 +222,7 @@ class ModelContext { // discard changes ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone(); - final List<IEditorPart> editors = new ArrayList<IEditorPart>( - dependentEditors); + List<IEditorPart> editors = new ArrayList<IEditorPart>(dependentEditors); dependentEditors.clear(); for (final IEditorPart editor : editors) { @@ -219,23 +235,20 @@ class ModelContext { } } - /** Returns the top-level elements of this model. */ - public UnmodifiableList<EObject> getTopLevelElements() { - return CollectionUtils.asUnmodifiable(r.getContents()); - } - /** Returns the file associated with this model. */ public IFile getFile() { return file; } /** Returns whether the model is dirty (i.e. if there are unsaved changes). */ + @Override public boolean isDirty() { return ((BasicCommandStack) editingDomain.getCommandStack()) .isSaveNeeded(); } /** Perform saving of the model. */ + @Override public synchronized void doSave(IProgressMonitor monitor) throws IOException, CoreException { monitor.beginTask("Saving...", 2); @@ -311,6 +324,7 @@ class ModelContext { } /** Runs the given runnable as a command. */ + @Override public void runAsCommand(final Runnable runnable) { transactionalCommandStack.execute(new AbstractCommand() { @@ -357,7 +371,8 @@ class ModelContext { List<EObject> children; if (result == null) { - children = getTopLevelElements(); + children = new LinkedList<EObject>(); + children.add(getTopLevelElement()); } else { children = result.eContents(); } @@ -387,4 +402,33 @@ class ModelContext { } } + /** {@inheritDoc} */ + @Override + public boolean canUndo() { + return transactionalCommandStack.canUndo(); + } + + /** {@inheritDoc} */ + @Override + public boolean canRedo() { + return transactionalCommandStack.canRedo(); + } + + /** {@inheritDoc} */ + @Override + public void undo() { + transactionalCommandStack.undo(); + } + + /** {@inheritDoc} */ + @Override + public void redo() { + transactionalCommandStack.redo(); + } + + /** {@inheritDoc} */ + @Override + public String getSaveableName() { + return getFile().getName(); + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java index d9ad1d071b57f87111e3ead29f691403362a6c7f..e467fe2a1ddcd0b6d6b747f9300b3def869ce90d 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IActionService.java @@ -45,6 +45,6 @@ public interface IActionService { /** Adds the global default actions like undo to the given context menu. */ void addGlobalDefaultActionSectionToMenu(IMenuManager menuManager); - /** Updates the enabled state of the global actions. */ - void update(); + /** Refreshes the enabled state of the global actions. */ + void refresh(); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java index 9a63ab9b35a84735b35f1663f53f518132f80b46..bdda21e43449d3d2fd0378e6e36e06ea2e29b32c 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java @@ -18,6 +18,7 @@ $Id$ package org.fortiss.tooling.kernel.services; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.Saveable; import org.eclipse.ui.part.ViewPart; import org.fortiss.tooling.kernel.internal.NavigatorService; @@ -45,4 +46,10 @@ public interface INavigatorService { /** Returns the current naviaator selection. */ ISelection getCurrentSelection(); + + /** Returns the saveables. */ + Saveable[] getSaveables(); + + /** Returns the saveables of the current selection. */ + Saveable[] getActiveSaveables(); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPersistencyService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPersistencyService.java index 923ebf32e2942f75ba2589ee5507d5ccdcd31ed1..fb1fe74d2bc646f5624d77b26f2388be075a94b7 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPersistencyService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPersistencyService.java @@ -19,16 +19,19 @@ package org.fortiss.tooling.kernel.services; import java.util.List; -import org.eclipse.emf.common.command.CommandStack; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.interfaces.IStorageProvider; import org.fortiss.tooling.kernel.interfaces.ITopLevelElementChangeListener; +import org.fortiss.tooling.kernel.interfaces.ITopLevelElementContext; import org.fortiss.tooling.kernel.internal.PersistencyService; /** * The persistency service provides the transparent access to the different * persistency options, namely an EMFStore or local XML files within an Eclipse - * project. + * project. Independent of the concrete {@link IStorageProvider} variant the + * persistency service offers a list of {@link ITopLevelElementContext}s and a + * notification mechanism for changes to this list. * * @author hoelzl * @author $Author$ @@ -41,17 +44,13 @@ public interface IPersistencyService { public static final IPersistencyService INSTANCE = new PersistencyService(); /** - * Returns the list of top level {@link EObject}s provided by - * {@link IStorageProvider}s. + * Returns the list of top level {@link ITopLevelElementContext}s provided + * by {@link IStorageProvider}s. */ - List<EObject> getTopLevelElements(); + List<ITopLevelElementContext> getTopLevelElementContexts(); - /** - * Refreshes the list of top-level elements. This method should be called by - * storage providers whenever their list of provided top-level elements - * changes. - */ - void refreshTopLevelElements(IStorageProvider provider); + /** Returns whether the given element is a top-level element. */ + boolean isTopLevelElement(EObject element); /** Adds a top-level element listener. */ void addTopLevelElementListener(ITopLevelElementChangeListener listener); @@ -60,11 +59,18 @@ public interface IPersistencyService { void removeTopLevelElementListener(ITopLevelElementChangeListener listener); /** Returns the top-level element for the given model element. */ - EObject getTopLevelElementFor(EObject modelElement); + ITopLevelElementContext getTopLevelElementContextFor(EObject modelElement); + + /** Returns whether the some storage provider has unsaved changes. */ + boolean isDirty(); - /** Returns the storage provider for the given model element. */ - IStorageProvider getStorageProviderFor(EObject modelElement); + /** Saves any dirty top-level elements to disk. */ + void doSave(IProgressMonitor monitor); - /** Returns the command stack for the given model element. */ - CommandStack getCommandStack(EObject modelElement); + /** + * Refreshes the list of top-level elements. This method should be called by + * storage providers whenever their list of provided top-level elements + * changes. + */ + void refreshTopLevelElements(IStorageProvider provider); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java index 08f86437c663bfb7693c6a50b8aa1e3b3edffe6f..490c9604e282054aeea680277dd7c56e7bb53f69 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/EObjectSelectionUtils.java @@ -85,5 +85,4 @@ public final class EObjectSelectionUtils { } return result; } - } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java index 68cb87f7315e565500129974494dd764fb9f8319..ac827aa9d93e16fa6ab149844c94f2910436827a 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/util/ProjectRootElementUtils.java @@ -38,8 +38,10 @@ public final class ProjectRootElementUtils { */ public static <T extends IProjectRootElement> T getRootElement( EObject element, Class<T> clazz) { - return ReflectionUtils.pickInstanceOf(clazz, - IPersistencyService.INSTANCE.getTopLevelElementFor(element) - .eContents()); + return ReflectionUtils.pickInstanceOf( + clazz, + IPersistencyService.INSTANCE + .getTopLevelElementContextFor(element) + .getTopLevelElement().eContents()); } }