| /**
|
| * Copyright (c) 2009, 2019 Mia-Software and others.
|
| * All rights reserved. This program and the accompanying materials
|
| * are made available under the terms of the Eclipse Public License v2.0
|
| * which accompanies this distribution, and is available at
|
| * http://www.eclipse.org/legal/epl-v20.html
|
| *
|
| * Contributors:
|
| * Frederic Madiot (Mia-Software) - meta-model design
|
| * Gregoire DUPE (Mia-Software) - design and implementation
|
| * Nicolas BROS (Mia-Software)
|
| *
|
| *
|
| * $Id$
|
| */ |
| package org.eclipse.modisco.infra.facet.editor.presentation;
|
|
|
| import java.io.IOException;
|
| import java.io.InputStream;
|
| import java.util.ArrayList;
|
| import java.util.Collection;
|
| import java.util.Collections;
|
| import java.util.EventObject;
|
| import java.util.HashMap;
|
| import java.util.Iterator;
|
| import java.util.LinkedHashMap;
|
| import java.util.List;
|
| import java.util.Map;
|
|
|
| import org.eclipse.core.resources.IFile;
|
| import org.eclipse.core.resources.IMarker;
|
| import org.eclipse.core.resources.IResource;
|
| import org.eclipse.core.resources.IResourceChangeEvent;
|
| import org.eclipse.core.resources.IResourceChangeListener;
|
| 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.core.runtime.IPath;
|
| import org.eclipse.core.runtime.IProgressMonitor;
|
| import org.eclipse.core.runtime.IStatus;
|
| import org.eclipse.core.runtime.NullProgressMonitor;
|
| import org.eclipse.core.runtime.Status;
|
| import org.eclipse.core.runtime.jobs.Job;
|
| import org.eclipse.emf.common.command.BasicCommandStack;
|
| import org.eclipse.emf.common.command.Command;
|
| import org.eclipse.emf.common.command.CommandStack;
|
| import org.eclipse.emf.common.command.CommandStackListener;
|
| import org.eclipse.emf.common.command.CompoundCommand;
|
| 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.ui.MarkerHelper;
|
| import org.eclipse.emf.common.ui.ViewerPane;
|
| import org.eclipse.emf.common.ui.editor.ProblemEditorPart;
|
| import org.eclipse.emf.common.ui.viewer.IViewerProvider;
|
| import org.eclipse.emf.common.util.BasicDiagnostic;
|
| import org.eclipse.emf.common.util.Diagnostic;
|
| import org.eclipse.emf.common.util.EList;
|
| import org.eclipse.emf.common.util.TreeIterator;
|
| import org.eclipse.emf.common.util.URI;
|
| import org.eclipse.emf.ecore.EClassifier;
|
| import org.eclipse.emf.ecore.EObject;
|
| import org.eclipse.emf.ecore.EPackage;
|
| import org.eclipse.emf.ecore.EPackage.Registry;
|
| import org.eclipse.emf.ecore.EStructuralFeature;
|
| import org.eclipse.emf.ecore.EValidator;
|
| import org.eclipse.emf.ecore.EcorePackage;
|
| import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
|
| 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.EContentAdapter;
|
| import org.eclipse.emf.ecore.util.EcoreUtil;
|
| import org.eclipse.emf.edit.command.SetCommand;
|
| import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
|
| import org.eclipse.emf.edit.domain.EditingDomain;
|
| import org.eclipse.emf.edit.domain.IEditingDomainProvider;
|
| import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
|
| import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
|
| import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
|
| import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
|
| import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
|
| import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor;
|
| import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
|
| import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
|
| import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
|
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
|
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
|
| import org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider;
|
| import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
|
| import org.eclipse.emf.edit.ui.util.EditUIUtil;
|
| import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage;
|
| import org.eclipse.jface.action.IMenuListener;
|
| import org.eclipse.jface.action.IMenuManager;
|
| import org.eclipse.jface.action.IStatusLineManager;
|
| import org.eclipse.jface.action.IToolBarManager;
|
| import org.eclipse.jface.action.MenuManager;
|
| import org.eclipse.jface.action.Separator;
|
| import org.eclipse.jface.dialogs.MessageDialog;
|
| import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
| import org.eclipse.jface.resource.ImageDescriptor;
|
| import org.eclipse.jface.viewers.DecorationOverlayIcon;
|
| import org.eclipse.jface.viewers.IDecoration;
|
| import org.eclipse.jface.viewers.ISelection;
|
| import org.eclipse.jface.viewers.ISelectionChangedListener;
|
| import org.eclipse.jface.viewers.ISelectionProvider;
|
| import org.eclipse.jface.viewers.IStructuredSelection;
|
| import org.eclipse.jface.viewers.SelectionChangedEvent;
|
| import org.eclipse.jface.viewers.StructuredSelection;
|
| import org.eclipse.jface.viewers.StructuredViewer;
|
| import org.eclipse.jface.viewers.TreeViewer;
|
| import org.eclipse.jface.viewers.Viewer;
|
| import org.eclipse.modisco.infra.common.core.internal.builder.AbstractMoDiscoCatalog;
|
| import org.eclipse.modisco.infra.common.core.internal.resource.MoDiscoResourceSet;
|
| import org.eclipse.modisco.infra.common.core.logging.MoDiscoLogger;
|
| import org.eclipse.modisco.infra.common.ui.internal.controls.EObjectErrorPainter;
|
| import org.eclipse.modisco.infra.facet.Facet;
|
| import org.eclipse.modisco.infra.facet.FacetPackage;
|
| import org.eclipse.modisco.infra.facet.FacetSet;
|
| import org.eclipse.modisco.infra.facet.FacetStructuralFeature;
|
| import org.eclipse.modisco.infra.facet.core.FacetSetCatalog;
|
| import org.eclipse.modisco.infra.facet.edit.provider.FacetItemProviderAdapterFactory;
|
| import org.eclipse.modisco.infra.facet.editor.Messages;
|
| import org.eclipse.modisco.infra.query.ModelQuery;
|
| import org.eclipse.modisco.infra.query.edit.provider.QueryItemProviderAdapterFactory;
|
| import org.eclipse.swt.SWT;
|
| import org.eclipse.swt.custom.CTabFolder;
|
| import org.eclipse.swt.dnd.DND;
|
| import org.eclipse.swt.dnd.Transfer;
|
| import org.eclipse.swt.events.ControlAdapter;
|
| import org.eclipse.swt.events.ControlEvent;
|
| import org.eclipse.swt.events.MouseAdapter;
|
| import org.eclipse.swt.events.MouseEvent;
|
| import org.eclipse.swt.graphics.Image;
|
| import org.eclipse.swt.graphics.Point;
|
| import org.eclipse.swt.widgets.Composite;
|
| import org.eclipse.swt.widgets.Control;
|
| import org.eclipse.swt.widgets.Display;
|
| import org.eclipse.swt.widgets.Menu;
|
| import org.eclipse.swt.widgets.Tree;
|
| import org.eclipse.ui.IActionBars;
|
| import org.eclipse.ui.IEditorInput;
|
| import org.eclipse.ui.IEditorPart;
|
| import org.eclipse.ui.IEditorSite;
|
| import org.eclipse.ui.IPartListener;
|
| import org.eclipse.ui.ISharedImages;
|
| import org.eclipse.ui.IWorkbenchPart;
|
| import org.eclipse.ui.PartInitException;
|
| import org.eclipse.ui.PlatformUI;
|
| import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
| import org.eclipse.ui.dialogs.SaveAsDialog;
|
| import org.eclipse.ui.ide.IGotoMarker;
|
| import org.eclipse.ui.part.FileEditorInput;
|
| import org.eclipse.ui.part.MultiPageEditorPart;
|
| import org.eclipse.ui.views.contentoutline.ContentOutline;
|
| import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
|
| import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
| import org.eclipse.ui.views.properties.IPropertySheetPage;
|
| import org.eclipse.ui.views.properties.PropertySheet;
|
| import org.eclipse.ui.views.properties.PropertySheetPage;
|
|
|
| /**
|
| * This is an example of a Facet model editor. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated NOT
|
| * @deprecated Replaced by EMF Facet
|
| */
|
| @Deprecated
|
| public class FacetEditor extends MultiPageEditorPart implements IEditingDomainProvider,
|
| ISelectionProvider, IMenuListener, IViewerProvider, IGotoMarker {
|
|
|
| private static final String PROPERTY_VIEW_ID = "org.eclipse.ui.views.PropertySheet"; //$NON-NLS-1$
|
|
|
| /**
|
| * This keeps track of the editing domain that is used to track all changes
|
| * to the model. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected AdapterFactoryEditingDomain editingDomain;
|
|
|
| /**
|
| * This is the one adapter factory used for providing views of the model.
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected ComposedAdapterFactory adapterFactory;
|
|
|
| /**
|
| * This is the content outline page. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected IContentOutlinePage contentOutlinePage;
|
|
|
| /**
|
| * This is a kludge... <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected IStatusLineManager contentOutlineStatusLineManager;
|
|
|
| /**
|
| * This is the content outline page's viewer. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected TreeViewer contentOutlineViewer;
|
|
|
| /**
|
| * This is the property sheet page. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected PropertySheetPage propertySheetPage;
|
|
|
| /**
|
| * This is the viewer that shadows the selection in the content outline. The
|
| * parent relation must be correctly defined for this to work. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected TreeViewer selectionViewer;
|
|
|
| /**
|
| * This keeps track of the active viewer pane, in the book. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected ViewerPane currentViewerPane;
|
|
|
| /**
|
| * This keeps track of the active content viewer, which may be either one of
|
| * the viewers in the pages or the content outline viewer. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected Viewer currentViewer;
|
|
|
| /**
|
| * This listens to which ever viewer is active. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected ISelectionChangedListener selectionChangedListener;
|
|
|
| /**
|
| * This keeps track of all the
|
| * {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are
|
| * listening to this editor. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>();
|
|
|
| /**
|
| * This keeps track of the selection of the editor as a whole. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected ISelection editorSelection = StructuredSelection.EMPTY;
|
|
|
| /**
|
| * The MarkerHelper is responsible for creating workspace resource markers
|
| * presented in Eclipse's Problems View. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected MarkerHelper markerHelper = new EditUIMarkerHelper();
|
|
|
| /**
|
| * This listens for when the outline becomes active <!-- begin-user-doc -->
|
| * <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected IPartListener partListener = new IPartListener() {
|
| public void partActivated(final IWorkbenchPart p) {
|
| if (p instanceof ContentOutline) {
|
| if (((ContentOutline) p).getCurrentPage() == FacetEditor.this.contentOutlinePage) {
|
| getActionBarContributor().setActiveEditor(FacetEditor.this);
|
|
|
| setCurrentViewer(FacetEditor.this.contentOutlineViewer);
|
| }
|
| } else if (p instanceof PropertySheet) {
|
| if (((PropertySheet) p).getCurrentPage() == FacetEditor.this.propertySheetPage) {
|
| getActionBarContributor().setActiveEditor(FacetEditor.this);
|
| handleActivate();
|
| }
|
| } else if (p == FacetEditor.this) {
|
| handleActivate();
|
| }
|
| }
|
|
|
| public void partBroughtToTop(final IWorkbenchPart p) {
|
| // Ignore.
|
| }
|
|
|
| public void partClosed(final IWorkbenchPart p) {
|
| // Ignore.
|
| }
|
|
|
| public void partDeactivated(final IWorkbenchPart p) {
|
| // Ignore.
|
| }
|
|
|
| public void partOpened(final IWorkbenchPart p) {
|
| // Ignore.
|
| }
|
| };
|
|
|
| /**
|
| * Resources that have been removed since last activation. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected Collection<Resource> removedResources = new ArrayList<Resource>();
|
|
|
| /**
|
| * Resources that have been changed since last activation. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected Collection<Resource> changedResources = new ArrayList<Resource>();
|
|
|
| /**
|
| * Resources that have been saved. <!-- begin-user-doc --> <!-- end-user-doc
|
| * -->
|
| *
|
| * @generated
|
| */
|
| protected Collection<Resource> savedResources = new ArrayList<Resource>();
|
|
|
| /**
|
| * Map to store the diagnostic associated with a resource. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>();
|
|
|
| /**
|
| * Controls whether the problem indication should be updated. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected boolean updateProblemIndication = true;
|
|
|
| /**
|
| * Adapter used to update the problem indication when resources are demanded
|
| * loaded. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected EContentAdapter problemIndicationAdapter = new EContentAdapter() {
|
| @Override
|
| public void notifyChanged(final Notification notification) {
|
| if (notification.getNotifier() instanceof Resource) {
|
| switch (notification.getFeatureID(Resource.class)) {
|
| case Resource.RESOURCE__IS_LOADED:
|
| case Resource.RESOURCE__ERRORS:
|
| case Resource.RESOURCE__WARNINGS: {
|
| Resource resource = (Resource) notification.getNotifier();
|
| Diagnostic diagnostic = analyzeResourceProblems(resource, null);
|
| if (diagnostic.getSeverity() != Diagnostic.OK) {
|
| FacetEditor.this.resourceToDiagnosticMap.put(resource, diagnostic);
|
| } else {
|
| FacetEditor.this.resourceToDiagnosticMap.remove(resource);
|
| }
|
|
|
| if (FacetEditor.this.updateProblemIndication) {
|
| getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| updateProblemIndication();
|
| }
|
| });
|
| }
|
| break;
|
| }
|
| }
|
| } else {
|
| super.notifyChanged(notification);
|
| }
|
| }
|
|
|
| @Override
|
| protected void setTarget(final Resource target) {
|
| basicSetTarget(target);
|
| }
|
|
|
| @Override
|
| protected void unsetTarget(final Resource target) {
|
| basicUnsetTarget(target);
|
| }
|
| };
|
|
|
| /**
|
| * This listens for workspace changes. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| protected IResourceChangeListener resourceChangeListener = new IResourceChangeListener() {
|
| public void resourceChanged(final IResourceChangeEvent event) {
|
| IResourceDelta delta = event.getDelta();
|
| try {
|
| class ResourceDeltaVisitor implements IResourceDeltaVisitor {
|
| protected ResourceSet resourceSet = FacetEditor.this.editingDomain
|
| .getResourceSet();
|
| protected Collection<Resource> changedResources = new ArrayList<Resource>();
|
| protected Collection<Resource> removedResources = new ArrayList<Resource>();
|
|
|
| public boolean visit(final IResourceDelta delta) {
|
| if (delta.getResource().getType() == IResource.FILE) {
|
| if (delta.getKind() == IResourceDelta.REMOVED
|
| || delta.getKind() == IResourceDelta.CHANGED) {
|
| Resource resource = this.resourceSet.getResource(URI
|
| .createPlatformResourceURI(delta.getFullPath().toString(),
|
| true), false);
|
| if (resource != null) {
|
| if (delta.getKind() == IResourceDelta.REMOVED) {
|
| this.removedResources.add(resource);
|
| } else {
|
| if ((delta.getFlags() & IResourceDelta.MARKERS) != 0) {
|
| markersChanged();
|
| }
|
| if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) {
|
| if (!FacetEditor.this.savedResources.remove(resource)) {
|
| this.changedResources.add(resource);
|
| }
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| return true;
|
| }
|
|
|
| public Collection<Resource> getChangedResources() {
|
| return this.changedResources;
|
| }
|
|
|
| public Collection<Resource> getRemovedResources() {
|
| return this.removedResources;
|
| }
|
| }
|
|
|
| final ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
|
| delta.accept(visitor);
|
|
|
| if (!visitor.getRemovedResources().isEmpty()) {
|
| getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| FacetEditor.this.removedResources.addAll(visitor.getRemovedResources());
|
| if (!isDirty()) {
|
| getSite().getPage().closeEditor(FacetEditor.this, false);
|
| }
|
| }
|
| });
|
| }
|
|
|
| if (!visitor.getChangedResources().isEmpty()) {
|
| getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| FacetEditor.this.changedResources.addAll(visitor.getChangedResources());
|
| if (getSite().getPage().getActiveEditor() == FacetEditor.this) {
|
| handleActivate();
|
| }
|
| }
|
| });
|
| }
|
| } catch (CoreException exception) {
|
| FacetEditorPlugin.INSTANCE.log(exception);
|
| }
|
| }
|
| };
|
|
|
| private Image errorTitleImage = null;
|
| private Image originalTitleImage = null;
|
|
|
| private void markersChanged() {
|
| // draws an error decorator on the editor's tab
|
| final FacetEditor editor = this;
|
| Display.getDefault().asyncExec(new Runnable() {
|
| public void run() {
|
| Image currentImage = editor.getTitleImage();
|
| if (FacetEditor.this.originalTitleImage == null) {
|
| // make a copy because the original image will be disposed
|
| FacetEditor.this.originalTitleImage = new Image(Display.getDefault(),
|
| currentImage.getImageData());
|
| }
|
| boolean hasMarkers = FacetEditor.this.markerHelper.hasMarkers(
|
| FacetEditor.this.editingDomain.getResourceSet(), true,
|
| IResource.DEPTH_INFINITE);
|
| if (hasMarkers) {
|
| if (FacetEditor.this.errorTitleImage == null) {
|
| ImageDescriptor errorDescriptor = PlatformUI.getWorkbench()
|
| .getSharedImages()
|
| .getImageDescriptor(ISharedImages.IMG_DEC_FIELD_ERROR);
|
| FacetEditor.this.errorTitleImage = new DecorationOverlayIcon(
|
| FacetEditor.this.originalTitleImage, errorDescriptor,
|
| IDecoration.BOTTOM_LEFT).createImage();
|
| }
|
| if (currentImage != FacetEditor.this.errorTitleImage) {
|
| editor.setTitleImage(FacetEditor.this.errorTitleImage);
|
| }
|
| } else {
|
| if (currentImage != FacetEditor.this.originalTitleImage) {
|
| editor.setTitleImage(FacetEditor.this.originalTitleImage);
|
| }
|
| }
|
| redraw();
|
| }
|
| });
|
| }
|
|
|
| /**
|
| * Handles activation of the editor or it's associated views. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void handleActivate() {
|
| // Recompute the read only state.
|
| //
|
| if (this.editingDomain.getResourceToReadOnlyMap() != null) {
|
| this.editingDomain.getResourceToReadOnlyMap().clear();
|
|
|
| // Refresh any actions that may become enabled or disabled.
|
| //
|
| setSelection(getSelection());
|
| }
|
|
|
| if (!this.removedResources.isEmpty()) {
|
| if (handleDirtyConflict()) {
|
| getSite().getPage().closeEditor(FacetEditor.this, false);
|
| } else {
|
| this.removedResources.clear();
|
| this.changedResources.clear();
|
| this.savedResources.clear();
|
| }
|
| } else if (!this.changedResources.isEmpty()) {
|
| this.changedResources.removeAll(this.savedResources);
|
| handleChangedResources();
|
| this.changedResources.clear();
|
| this.savedResources.clear();
|
| }
|
| }
|
|
|
| /**
|
| * Handles what to do with changed resources on activation. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| protected void handleChangedResources() {
|
| if (!this.changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) {
|
| if (isDirty()) {
|
| this.changedResources.addAll(this.editingDomain.getResourceSet().getResources());
|
| }
|
| this.editingDomain.getCommandStack().flush();
|
|
|
| this.updateProblemIndication = false;
|
| for (Resource resource : this.changedResources) {
|
| // see Bug 310572 - FileNotFoundException:
|
| // http://www.eclipse.org/emf/2002/Ecore
|
| if (resource.isLoaded() && resource.getContents().size() > 0
|
| && resource.getContents().get(0) instanceof FacetSet) {
|
| resource.unload();
|
| try {
|
| resource.load(Collections.EMPTY_MAP);
|
| } catch (IOException exception) {
|
| if (!this.resourceToDiagnosticMap.containsKey(resource)) {
|
| this.resourceToDiagnosticMap.put(resource,
|
| analyzeResourceProblems(resource, exception));
|
| }
|
| }
|
| }
|
| }
|
|
|
| if (AdapterFactoryEditingDomain.isStale(this.editorSelection)) {
|
| setSelection(StructuredSelection.EMPTY);
|
| }
|
|
|
| this.updateProblemIndication = true;
|
| updateProblemIndication();
|
| }
|
| }
|
|
|
| /**
|
| * Updates the problems indication with the information described in the
|
| * specified diagnostic. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void updateProblemIndication() {
|
| if (this.updateProblemIndication) {
|
| BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.OK,
|
| "org.eclipse.modisco.infra.facet.editor", //$NON-NLS-1$
|
| 0, null, new Object[] { this.editingDomain.getResourceSet() });
|
| for (Diagnostic childDiagnostic : this.resourceToDiagnosticMap.values()) {
|
| if (childDiagnostic.getSeverity() != Diagnostic.OK) {
|
| diagnostic.add(childDiagnostic);
|
| }
|
| }
|
|
|
| int lastEditorPage = getPageCount() - 1;
|
| if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) {
|
| ((ProblemEditorPart) getEditor(lastEditorPage)).setDiagnostic(diagnostic);
|
| if (diagnostic.getSeverity() != Diagnostic.OK) {
|
| setActivePage(lastEditorPage);
|
| }
|
| } else if (diagnostic.getSeverity() != Diagnostic.OK) {
|
| ProblemEditorPart problemEditorPart = new ProblemEditorPart();
|
| problemEditorPart.setDiagnostic(diagnostic);
|
| problemEditorPart.setMarkerHelper(this.markerHelper);
|
| try {
|
| addPage(++lastEditorPage, problemEditorPart, getEditorInput());
|
| setPageText(lastEditorPage, problemEditorPart.getPartName());
|
| setActivePage(lastEditorPage);
|
| showTabs();
|
| } catch (PartInitException exception) {
|
| FacetEditorPlugin.INSTANCE.log(exception);
|
| }
|
| }
|
|
|
| if (this.markerHelper.hasMarkers(this.editingDomain.getResourceSet())) {
|
| this.markerHelper.deleteMarkers(this.editingDomain.getResourceSet());
|
| if (diagnostic.getSeverity() != Diagnostic.OK) {
|
| try {
|
| this.markerHelper.createMarkers(diagnostic);
|
| } catch (CoreException exception) {
|
| FacetEditorPlugin.INSTANCE.log(exception);
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * Shows a dialog that asks if conflicting changes should be discarded. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected boolean handleDirtyConflict() {
|
| return MessageDialog.openQuestion(getSite().getShell(),
|
| getString("_UI_FileConflict_label"), //$NON-NLS-1$
|
| getString("_WARN_FileConflict")); //$NON-NLS-1$
|
| }
|
|
|
| /**
|
| * This creates a model editor. <!-- begin-user-doc --> <!-- end-user-doc
|
| * -->
|
| *
|
| * @generated
|
| */
|
| public FacetEditor() {
|
| super();
|
| initializeEditingDomain();
|
| }
|
|
|
| /**
|
| * This sets up the editing domain for the model editor. <!-- begin-user-doc
|
| * --> <!-- end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| protected void initializeEditingDomain() {
|
| // Create an adapter factory that yields item providers.
|
| //
|
| this.adapterFactory = new ComposedAdapterFactory(
|
| ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
|
|
|
| this.adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
|
| this.adapterFactory.addAdapterFactory(new FacetItemProviderAdapterFactory());
|
| this.adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
|
| this.adapterFactory.addAdapterFactory(new QueryItemProviderAdapterFactory());
|
| // adapterFactory.addAdapterFactory(new
|
| // RuntimeItemProviderAdapterFactory());
|
| this.adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
|
|
|
| // Create the command stack that will notify this editor as commands are
|
| // executed.
|
| final BasicCommandStack commandStack = new BasicCommandStack() {
|
| @Override
|
| public void execute(final Command command) {
|
| /*
|
| * Bug 309917 - Compute the FacetReference::eType and
|
| * FacetAttribute::eType
|
| *
|
| * If the command changes the ValueQuery of a FacetAttribute or
|
| * FacetReference, then also set the type, lower bound and upper
|
| * bound, so that they match the query's
|
| */
|
| if (command instanceof SetCommand) {
|
| SetCommand setCommand = (SetCommand) command;
|
| if (setCommand.getFeature() == FacetPackage.eINSTANCE
|
| .getFacetStructuralFeature_ValueQuery()) {
|
| Object value = setCommand.getValue();
|
| if (value instanceof ModelQuery) {
|
| ModelQuery modelQuery = (ModelQuery) value;
|
| EClassifier returnType = modelQuery.getReturnType();
|
| CompoundCommand compoundCommand = new CompoundCommand();
|
| compoundCommand.append(command);
|
| compoundCommand.setLabel(command.getLabel());
|
| if (returnType != null) {
|
| Command setEtypeCommand = SetCommand.create(
|
| FacetEditor.this.editingDomain, setCommand.getOwner(),
|
| EcorePackage.Literals.ETYPED_ELEMENT__ETYPE, returnType);
|
| compoundCommand.append(setEtypeCommand);
|
| }
|
| Command setLowerBoundCommand = SetCommand.create(
|
| FacetEditor.this.editingDomain, setCommand.getOwner(),
|
| EcorePackage.Literals.ETYPED_ELEMENT__LOWER_BOUND,
|
| modelQuery.getLowerBound());
|
| compoundCommand.append(setLowerBoundCommand);
|
| Command setUpperBoundCommand = SetCommand.create(
|
| FacetEditor.this.editingDomain, setCommand.getOwner(),
|
| EcorePackage.Literals.ETYPED_ELEMENT__UPPER_BOUND,
|
| modelQuery.getUpperBound());
|
| compoundCommand.append(setUpperBoundCommand);
|
| execute(compoundCommand);
|
| return;
|
| }
|
| }
|
| }
|
| super.execute(command);
|
| }
|
| };
|
|
|
| // Add a listener to set the most recent command's affected objects to
|
| // be the selection of the viewer with focus.
|
| //
|
| commandStack.addCommandStackListener(new CommandStackListener() {
|
| public void commandStackChanged(final EventObject event) {
|
| getContainer().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| firePropertyChange(IEditorPart.PROP_DIRTY);
|
|
|
| // Try to select the affected objects.
|
| //
|
| Command mostRecentCommand = ((CommandStack) event.getSource())
|
| .getMostRecentCommand();
|
| if (mostRecentCommand != null) {
|
| setSelectionToViewer(mostRecentCommand.getAffectedObjects());
|
| }
|
| if (FacetEditor.this.propertySheetPage != null
|
| && !FacetEditor.this.propertySheetPage.getControl().isDisposed()) {
|
| FacetEditor.this.propertySheetPage.refresh();
|
| }
|
| }
|
| });
|
| }
|
| });
|
|
|
| // Create the editing domain with a special command stack.
|
| //
|
| this.editingDomain = new AdapterFactoryEditingDomain(this.adapterFactory, commandStack,
|
| new HashMap<Resource, Boolean>());
|
|
|
| URI uri = URI.createURI(EcorePackage.eNS_URI);
|
| ResourceSet resourceSet = this.editingDomain.getResourceSet();
|
| /*
|
| * To manage correctly saving of resources, we need to replace current
|
| * uri converter by a modisco one (to handle modisco protocol).
|
| * correction of bug 306050
|
| */
|
| URIConverter converter = MoDiscoResourceSet.createURIConverter();
|
| resourceSet.setURIConverter(converter);
|
|
|
| Resource r = resourceSet.getResource(uri, true);
|
| if (!resourceSet.getResources().contains(r)) {
|
| Registry packageRegistry = resourceSet.getPackageRegistry();
|
| for (EObject eObject : r.getContents()) {
|
| if (eObject instanceof EPackage) {
|
| EPackage ePackage = (EPackage) eObject;
|
| packageRegistry.put(ePackage.getNsURI(), ePackage);
|
| }
|
| }
|
| resourceSet.getResources().add(r);
|
| }
|
| }
|
|
|
| /**
|
| * This is here for the listener to be able to call it. <!-- begin-user-doc
|
| * --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| protected void firePropertyChange(final int action) {
|
| super.firePropertyChange(action);
|
| }
|
|
|
| /**
|
| * This sets the selection into whichever viewer is active. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void setSelectionToViewer(final Collection<?> collection) {
|
| final Collection<?> theSelection = collection;
|
| // Make sure it's okay.
|
| //
|
| if (theSelection != null && !theSelection.isEmpty()) {
|
| Runnable runnable = new Runnable() {
|
| public void run() {
|
| // Try to select the items in the current content viewer of
|
| // the editor.
|
| //
|
| if (FacetEditor.this.currentViewer != null) {
|
| FacetEditor.this.currentViewer.setSelection(new StructuredSelection(
|
| theSelection.toArray()), true);
|
| }
|
| }
|
| };
|
| getSite().getShell().getDisplay().asyncExec(runnable);
|
| }
|
| }
|
|
|
| public void setSelectionToViewer(final EObject eObject) {
|
| Object input = this.currentViewer.getInput();
|
| if (input instanceof ResourceSet) {
|
| ResourceSet resourceSet = (ResourceSet) input;
|
| TreeIterator<Notifier> allContents = resourceSet.getAllContents();
|
| while (allContents.hasNext()) {
|
| Notifier element = allContents.next();
|
| if (element instanceof EObject) {
|
| EObject eObject2 = (EObject) element;
|
| if (representSameElement(eObject, eObject2)) {
|
| setSelectionToViewer(Collections.singleton(eObject2));
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| private boolean representSameElement(final EObject eObject1, final EObject eObject2) {
|
| try {
|
| if (eObject1 instanceof FacetSet && eObject2 instanceof FacetSet) {
|
| FacetSet facetSet1 = (FacetSet) eObject1;
|
| FacetSet facetSet2 = (FacetSet) eObject2;
|
| return facetSet1.getName().equals(facetSet2.getName());
|
| } else if (eObject1 instanceof Facet && eObject2 instanceof Facet) {
|
| Facet facet1 = (Facet) eObject1;
|
| Facet facet2 = (Facet) eObject2;
|
| FacetSet facetSet1 = (FacetSet) facet1.eContainer();
|
| FacetSet facetSet2 = (FacetSet) facet2.eContainer();
|
| return facet1.getName().equals(facet2.getName())
|
| && facetSet1.getName().equals(facetSet2.getName());
|
| } else if (eObject1 instanceof FacetStructuralFeature
|
| && eObject2 instanceof FacetStructuralFeature) {
|
| EStructuralFeature feature1 = (EStructuralFeature) eObject1;
|
| EStructuralFeature feature2 = (EStructuralFeature) eObject2;
|
| return feature1.getName().equals(feature2.getName());
|
| }
|
| } catch (Exception e) {
|
| MoDiscoLogger.logError(e, null);
|
| }
|
| return false;
|
| }
|
|
|
| /**
|
| * This returns the editing domain as required by the
|
| * {@link IEditingDomainProvider} interface. This is important for
|
| * implementing the static methods of {@link AdapterFactoryEditingDomain}
|
| * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public EditingDomain getEditingDomain() {
|
| return this.editingDomain;
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public class ReverseAdapterFactoryContentProvider extends AdapterFactoryContentProvider {
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public ReverseAdapterFactoryContentProvider(final AdapterFactory adapterFactory) {
|
| super(adapterFactory);
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public Object[] getElements(final Object object) {
|
| Object parent = super.getParent(object);
|
| return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent))
|
| .toArray();
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public Object[] getChildren(final Object object) {
|
| Object parent = super.getParent(object);
|
| return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent))
|
| .toArray();
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public boolean hasChildren(final Object object) {
|
| Object parent = super.getParent(object);
|
| return parent != null;
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public Object getParent(final Object object) {
|
| return null;
|
| }
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void setCurrentViewerPane(final ViewerPane viewerPane) {
|
| if (this.currentViewerPane != viewerPane) {
|
| if (this.currentViewerPane != null) {
|
| this.currentViewerPane.showFocus(false);
|
| }
|
| this.currentViewerPane = viewerPane;
|
| }
|
| setCurrentViewer(this.currentViewerPane.getViewer());
|
| }
|
|
|
| /**
|
| * This makes sure that one content viewer, either for the current page or
|
| * the outline view, if it has focus, is the current one. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void setCurrentViewer(final Viewer viewer) {
|
| // If it is changing...
|
| //
|
| if (this.currentViewer != viewer) {
|
| if (this.selectionChangedListener == null) {
|
| // Create the listener on demand.
|
| //
|
| this.selectionChangedListener = new ISelectionChangedListener() {
|
| // This just notifies those things that are affected by the
|
| // section.
|
| //
|
| public void selectionChanged(final SelectionChangedEvent selectionChangedEvent) {
|
| setSelection(selectionChangedEvent.getSelection());
|
| }
|
| };
|
| }
|
|
|
| // Stop listening to the old one.
|
| //
|
| if (this.currentViewer != null) {
|
| this.currentViewer.removeSelectionChangedListener(this.selectionChangedListener);
|
| }
|
|
|
| // Start listening to the new one.
|
| //
|
| if (viewer != null) {
|
| viewer.addSelectionChangedListener(this.selectionChangedListener);
|
| }
|
|
|
| // Remember it.
|
| //
|
| this.currentViewer = viewer;
|
|
|
| // Set the editors selection based on the current viewer's
|
| // selection.
|
| //
|
| setSelection(this.currentViewer == null ? StructuredSelection.EMPTY
|
| : this.currentViewer.getSelection());
|
| }
|
| }
|
|
|
| /**
|
| * This returns the viewer as required by the {@link IViewerProvider}
|
| * interface. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public Viewer getViewer() {
|
| return this.currentViewer;
|
| }
|
|
|
| /**
|
| * This creates a context menu for the viewer and adds a listener as well
|
| * registering the menu for extension. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void createContextMenuFor(final StructuredViewer viewer) {
|
| MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$
|
| contextMenu.add(new Separator("additions")); //$NON-NLS-1$
|
| contextMenu.setRemoveAllWhenShown(true);
|
| contextMenu.addMenuListener(this);
|
| Menu menu = contextMenu.createContextMenu(viewer.getControl());
|
| viewer.getControl().setMenu(menu);
|
| getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));
|
|
|
| int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
|
| Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
|
| viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
|
| viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(
|
| this.editingDomain, viewer));
|
| }
|
|
|
| /**
|
| * This is the method called to load a resource into the editing domain's
|
| * resource set based on the editor's input. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void createModel() {
|
| URI resourceURI = EditUIUtil.getURI(getEditorInput());
|
| Exception exception = null;
|
| Resource resource = null;
|
| try {
|
| // Load the resource through the editing domain.
|
| //
|
| resource = this.editingDomain.getResourceSet().getResource(resourceURI, true);
|
| } catch (Exception e) {
|
| exception = e;
|
| resource = this.editingDomain.getResourceSet().getResource(resourceURI, false);
|
| }
|
|
|
| Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
|
| if (diagnostic.getSeverity() != Diagnostic.OK) {
|
| this.resourceToDiagnosticMap
|
| .put(resource, analyzeResourceProblems(resource, exception));
|
| }
|
| this.editingDomain.getResourceSet().eAdapters().add(this.problemIndicationAdapter);
|
| }
|
|
|
| /**
|
| * Returns a diagnostic describing the errors and warnings listed in the
|
| * resource and the specified exception (if any). <!-- begin-user-doc -->
|
| * <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public Diagnostic analyzeResourceProblems(final Resource resource, final Exception exception) {
|
| if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) {
|
| BasicDiagnostic basicDiagnostic = new BasicDiagnostic(Diagnostic.ERROR,
|
| "org.eclipse.modisco.infra.facet.editor", //$NON-NLS-1$
|
| 0, getString("_UI_CreateModelError_message", resource.getURI()), //$NON-NLS-1$
|
| new Object[] { exception == null ? (Object) resource : exception });
|
| basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
|
| return basicDiagnostic;
|
| } else if (exception != null) {
|
| return new BasicDiagnostic(Diagnostic.ERROR,
|
| "org.eclipse.modisco.infra.facet.editor", //$NON-NLS-1$
|
| 0, getString("_UI_CreateModelError_message", resource.getURI()), //$NON-NLS-1$
|
| new Object[] { exception });
|
| } else {
|
| return Diagnostic.OK_INSTANCE;
|
| }
|
| }
|
|
|
| /**
|
| * This is the method used by the framework to install your own controls.
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| @Override
|
| public void createPages() {
|
| // Creates the model from the editor input
|
| //
|
| createModel();
|
|
|
| // Only creates the other pages if there is something that can be edited
|
| //
|
| if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
|
| // Create a page for the selection tree view.
|
| //
|
| {
|
| ViewerPane viewerPane = new ViewerPane(getSite().getPage(), FacetEditor.this) {
|
| @Override
|
| public Viewer createViewer(final Composite composite) {
|
| Tree tree = new Tree(composite, SWT.MULTI);
|
| EObjectErrorPainter errorPainter = new EObjectErrorPainter(
|
| getEditorInput(), FacetEditor.this.editingDomain);
|
| errorPainter.installOn(tree);
|
| registerShowPropertyViewOnDblClick(tree);
|
| TreeViewer newTreeViewer = new TreeViewer(tree);
|
| return newTreeViewer;
|
| }
|
|
|
| @Override
|
| public void requestActivation() {
|
| super.requestActivation();
|
| setCurrentViewerPane(this);
|
| }
|
|
|
| @Override
|
| protected void createTitleBar() {
|
| // remove title bar
|
| }
|
| };
|
| viewerPane.createControl(getContainer());
|
|
|
| this.selectionViewer = (TreeViewer) viewerPane.getViewer();
|
| this.selectionViewer.setContentProvider(new AdapterFactoryContentProvider(
|
| this.adapterFactory));
|
|
|
| this.selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(
|
| this.adapterFactory));
|
| this.selectionViewer.setInput(this.editingDomain.getResourceSet());
|
| this.selectionViewer.setSelection(new StructuredSelection(this.editingDomain
|
| .getResourceSet().getResources().get(0)), true);
|
| // viewerPane.setTitle(editingDomain.getResourceSet());
|
|
|
| @SuppressWarnings("unused")
|
| AdapterFactoryTreeEditor adapterFactoryTreeEditor = new AdapterFactoryTreeEditor(
|
| this.selectionViewer.getTree(), this.adapterFactory);
|
|
|
| createContextMenuFor(this.selectionViewer);
|
| int pageIndex = addPage(viewerPane.getControl());
|
| setPageText(pageIndex, Messages.FacetEditor_Edition);
|
| }
|
|
|
| getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| setActivePage(0);
|
| }
|
| });
|
| }
|
|
|
| // Ensures that this editor will only display the page's tab
|
| // area if there are more than one page
|
| //
|
| getContainer().addControlListener(new ControlAdapter() {
|
| boolean guard = false;
|
|
|
| @Override
|
| public void controlResized(final ControlEvent event) {
|
| if (!this.guard) {
|
| this.guard = true;
|
| hideTabs();
|
| this.guard = false;
|
| }
|
| }
|
| });
|
|
|
| getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
| public void run() {
|
| updateProblemIndication();
|
| }
|
| });
|
|
|
| markersChanged();
|
| }
|
|
|
| /**
|
| * Register a listener to show the property view when the tree is
|
| * double-clicked
|
| */
|
| private void registerShowPropertyViewOnDblClick(final Tree tree) {
|
| tree.addMouseListener(new MouseAdapter() {
|
| @Override
|
| public void mouseDoubleClick(final MouseEvent event) {
|
| openPropertiesView();
|
| }
|
| });
|
| }
|
|
|
| private void openPropertiesView() {
|
| try {
|
| getEditorSite().getPage().showView(FacetEditor.PROPERTY_VIEW_ID);
|
| } catch (final PartInitException e) {
|
| MoDiscoLogger.logError(e, null);
|
| }
|
| }
|
|
|
| /**
|
| * If there is just one page in the multi-page editor part, this hides the
|
| * single tab at the bottom. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void hideTabs() {
|
| if (getPageCount() <= 1) {
|
| setPageText(0, ""); //$NON-NLS-1$
|
| if (getContainer() instanceof CTabFolder) {
|
| ((CTabFolder) getContainer()).setTabHeight(1);
|
| Point point = getContainer().getSize();
|
| getContainer().setSize(point.x, point.y + 6);
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * If there is more than one page in the multi-page editor part, this shows
|
| * the tabs at the bottom. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void showTabs() {
|
| if (getPageCount() > 1) {
|
| setPageText(0, getString("_UI_SelectionPage_label")); //$NON-NLS-1$
|
| if (getContainer() instanceof CTabFolder) {
|
| ((CTabFolder) getContainer()).setTabHeight(SWT.DEFAULT);
|
| Point point = getContainer().getSize();
|
| getContainer().setSize(point.x, point.y - 6);
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * This is used to track the active viewer. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| protected void pageChange(final int pageIndex) {
|
| super.pageChange(pageIndex);
|
|
|
| if (this.contentOutlinePage != null) {
|
| handleContentOutlineSelection(this.contentOutlinePage.getSelection());
|
| }
|
| }
|
|
|
| /**
|
| * This is how the framework determines which interfaces we implement. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @SuppressWarnings("unchecked")
|
| @Override
|
| public Object getAdapter(final Class key) {
|
| if (key.equals(IContentOutlinePage.class)) {
|
| return showOutlineView() ? getContentOutlinePage() : null;
|
| } else if (key.equals(IPropertySheetPage.class)) {
|
| return getPropertySheetPage();
|
| } else if (key.equals(IGotoMarker.class)) {
|
| return this;
|
| } else {
|
| return super.getAdapter(key);
|
| }
|
| }
|
|
|
| /**
|
| * This accesses a cached version of the content outliner. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public IContentOutlinePage getContentOutlinePage() {
|
| if (this.contentOutlinePage == null) {
|
| // The content outline is just a tree.
|
| //
|
| class MyContentOutlinePage extends ContentOutlinePage {
|
| @Override
|
| public void createControl(final Composite parent) {
|
| super.createControl(parent);
|
| FacetEditor.this.contentOutlineViewer = getTreeViewer();
|
| FacetEditor.this.contentOutlineViewer.addSelectionChangedListener(this);
|
|
|
| // Set up the tree viewer.
|
| //
|
| FacetEditor.this.contentOutlineViewer
|
| .setContentProvider(new AdapterFactoryContentProvider(
|
| FacetEditor.this.adapterFactory));
|
| FacetEditor.this.contentOutlineViewer
|
| .setLabelProvider(new AdapterFactoryLabelProvider(
|
| FacetEditor.this.adapterFactory));
|
| FacetEditor.this.contentOutlineViewer.setInput(FacetEditor.this.editingDomain
|
| .getResourceSet());
|
|
|
| // Make sure our popups work.
|
| //
|
| createContextMenuFor(FacetEditor.this.contentOutlineViewer);
|
|
|
| if (!FacetEditor.this.editingDomain.getResourceSet().getResources().isEmpty()) {
|
| // Select the root object in the view.
|
| //
|
| FacetEditor.this.contentOutlineViewer.setSelection(
|
| new StructuredSelection(FacetEditor.this.editingDomain
|
| .getResourceSet().getResources().get(0)), true);
|
| }
|
| }
|
|
|
| @Override
|
| public void makeContributions(final IMenuManager menuManager,
|
| final IToolBarManager toolBarManager,
|
| final IStatusLineManager statusLineManager) {
|
| super.makeContributions(menuManager, toolBarManager, statusLineManager);
|
| FacetEditor.this.contentOutlineStatusLineManager = statusLineManager;
|
| }
|
|
|
| @Override
|
| public void setActionBars(final IActionBars actionBars) {
|
| super.setActionBars(actionBars);
|
| getActionBarContributor().shareGlobalActions(this, actionBars);
|
| }
|
| }
|
|
|
| this.contentOutlinePage = new MyContentOutlinePage();
|
|
|
| // Listen to selection so that we can handle it is a special way.
|
| //
|
| this.contentOutlinePage.addSelectionChangedListener(new ISelectionChangedListener() {
|
| // This ensures that we handle selections correctly.
|
| //
|
| public void selectionChanged(final SelectionChangedEvent event) {
|
| handleContentOutlineSelection(event.getSelection());
|
| }
|
| });
|
| }
|
|
|
| return this.contentOutlinePage;
|
| }
|
|
|
| /**
|
| * This accesses a cached version of the property sheet. <!-- begin-user-doc
|
| * --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public IPropertySheetPage getPropertySheetPage() {
|
| if (this.propertySheetPage == null) {
|
| this.propertySheetPage = new ExtendedPropertySheetPage(this.editingDomain) {
|
| @Override
|
| public void setSelectionToViewer(final List<?> selection) {
|
| FacetEditor.this.setSelectionToViewer(selection);
|
| FacetEditor.this.setFocus();
|
| }
|
|
|
| @Override
|
| public void setActionBars(final IActionBars actionBars) {
|
| super.setActionBars(actionBars);
|
| getActionBarContributor().shareGlobalActions(this, actionBars);
|
| }
|
| };
|
| this.propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(
|
| this.adapterFactory));
|
| }
|
|
|
| return this.propertySheetPage;
|
| }
|
|
|
| /**
|
| * This deals with how we want selection in the outliner to affect the other
|
| * views. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void handleContentOutlineSelection(final ISelection selection) {
|
| if (this.currentViewerPane != null && !selection.isEmpty()
|
| && selection instanceof IStructuredSelection) {
|
| Iterator<?> selectedElements = ((IStructuredSelection) selection).iterator();
|
| if (selectedElements.hasNext()) {
|
| // Get the first selected element.
|
| //
|
| Object selectedElement = selectedElements.next();
|
|
|
| // If it's the selection viewer, then we want it to select the
|
| // same selection as this selection.
|
| //
|
| if (this.currentViewerPane.getViewer() == this.selectionViewer) {
|
| ArrayList<Object> selectionList = new ArrayList<Object>();
|
| selectionList.add(selectedElement);
|
| while (selectedElements.hasNext()) {
|
| selectionList.add(selectedElements.next());
|
| }
|
|
|
| // Set the selection to the widget.
|
| //
|
| this.selectionViewer.setSelection(new StructuredSelection(selectionList));
|
| } else {
|
| // Set the input to the widget.
|
| //
|
| if (this.currentViewerPane.getViewer().getInput() != selectedElement) {
|
| this.currentViewerPane.getViewer().setInput(selectedElement);
|
| this.currentViewerPane.setTitle(selectedElement);
|
| }
|
| }
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * This is for implementing {@link IEditorPart} and simply tests the command
|
| * stack. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public boolean isDirty() {
|
| return ((BasicCommandStack) this.editingDomain.getCommandStack()).isSaveNeeded();
|
| }
|
|
|
| /**
|
| * This is for implementing {@link IEditorPart} and simply saves the model
|
| * file. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| @Override
|
| public void doSave(final IProgressMonitor progressMonitor) {
|
| // Save only resources that have actually changed.
|
| //
|
| final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
|
| saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED,
|
| Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
|
|
|
| // Do the work within an operation because this is a long running
|
| // activity that modifies the workbench.
|
| //
|
| WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
|
| // This is the method that gets invoked when the operation runs.
|
| //
|
| @Override
|
| public void execute(final IProgressMonitor monitor) {
|
| // Bug 312088 - Conflict between QuerySet and FacetSet editor
|
| // while open at the same time
|
| EList<Resource> resources = FacetEditor.this.editingDomain.getResourceSet()
|
| .getResources();
|
| // save only the resource that contains the FacetSet
|
| Resource resource = null;
|
| for (Resource aResource : resources) {
|
| if (aResource.getContents().size() > 0
|
| && aResource.getContents().get(0) instanceof FacetSet) {
|
| resource = aResource;
|
| break;
|
| }
|
| }
|
| if (resource == null) {
|
| MoDiscoLogger.logError("Found no resource to save", //$NON-NLS-1$
|
| FacetEditorPlugin.getPlugin());
|
| return;
|
| }
|
| try {
|
| long timeStamp = resource.getTimeStamp();
|
| resource.save(saveOptions);
|
| if (resource.getTimeStamp() != timeStamp) {
|
| FacetEditor.this.savedResources.add(resource);
|
| }
|
| } catch (Exception exception) {
|
| FacetEditor.this.resourceToDiagnosticMap.put(resource,
|
| analyzeResourceProblems(resource, exception));
|
| }
|
|
|
| Job refreshJob = new Job(Messages.FacetEditor_refreshErrorMarkersJobName) {
|
| @Override
|
| protected IStatus run(final IProgressMonitor monitor) {
|
| FacetSetCatalog.getSingleton().waitUntilBuilt();
|
| Display.getDefault().asyncExec(new Runnable() {
|
| public void run() {
|
| redraw();
|
| }
|
| });
|
| return Status.OK_STATUS;
|
| }
|
| };
|
| refreshJob.setPriority(Job.DECORATE);
|
| refreshJob.schedule();
|
| }
|
| };
|
|
|
| this.updateProblemIndication = false;
|
| try {
|
| Job currentJob = Job.getJobManager().currentJob();
|
| if (currentJob == null || currentJob.getRule() == null) {
|
| // This runs the options, and shows progress.
|
| new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
|
| } else {
|
| // see Bug 317295 - no save when drag & drop a query set
|
| operation.run(new NullProgressMonitor());
|
| }
|
|
|
| // Refresh the necessary state.
|
| //
|
| ((BasicCommandStack) this.editingDomain.getCommandStack()).saveIsDone();
|
| firePropertyChange(IEditorPart.PROP_DIRTY);
|
| } catch (Exception exception) {
|
| // Something went wrong that shouldn't.
|
| //
|
| FacetEditorPlugin.INSTANCE.log(exception);
|
| }
|
| this.updateProblemIndication = true;
|
| updateProblemIndication();
|
| }
|
|
|
| private void redraw() {
|
| Viewer viewer = getViewer();
|
| if (viewer != null) {
|
| Control control = viewer.getControl();
|
| if (control != null && !control.isDisposed()) {
|
| control.redraw();
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * This returns whether something has been persisted to the URI of the
|
| * specified resource. The implementation uses the URI converter from the
|
| * editor's resource set to try to open an input stream. <!-- begin-user-doc
|
| * --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected boolean isPersisted(final Resource resource) {
|
| boolean result = false;
|
| try {
|
| InputStream stream = this.editingDomain.getResourceSet().getURIConverter()
|
| .createInputStream(resource.getURI());
|
| if (stream != null) {
|
| result = true;
|
| stream.close();
|
| }
|
| } catch (IOException e) {
|
| // Ignore
|
| }
|
| return result;
|
| }
|
|
|
| /**
|
| * This always returns true because it is not currently supported. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public boolean isSaveAsAllowed() {
|
| return true;
|
| }
|
|
|
| /**
|
| * This also changes the editor's input. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public void doSaveAs() {
|
| SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
|
| saveAsDialog.open();
|
| IPath path = saveAsDialog.getResult();
|
| if (path != null) {
|
| IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
| if (file != null) {
|
| doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true),
|
| new FileEditorInput(file));
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected void doSaveAs(final URI uri, final IEditorInput editorInput) {
|
| (this.editingDomain.getResourceSet().getResources().get(0)).setURI(uri);
|
| setInputWithNotify(editorInput);
|
| setPartName(editorInput.getName());
|
| IProgressMonitor progressMonitor = getActionBars().getStatusLineManager() != null ? getActionBars()
|
| .getStatusLineManager().getProgressMonitor() : new NullProgressMonitor();
|
| doSave(progressMonitor);
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated NOT
|
| */
|
| public void gotoMarker(final IMarker marker) {
|
| try {
|
| if (marker.getType().equals(EValidator.MARKER)
|
| || marker.getType().equals(AbstractMoDiscoCatalog.BROKEN_REF_MARKER)) {
|
| String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
|
| if (uriAttribute != null) {
|
| URI uri = URI.createURI(uriAttribute);
|
| EObject eObject = this.editingDomain.getResourceSet().getEObject(uri, true);
|
| if (eObject != null) {
|
| setSelectionToViewer(Collections.singleton(this.editingDomain
|
| .getWrapper(eObject)));
|
| }
|
| }
|
| }
|
| } catch (CoreException exception) {
|
| FacetEditorPlugin.INSTANCE.log(exception);
|
| }
|
| }
|
|
|
| /**
|
| * This is called during startup. <!-- begin-user-doc --> <!-- end-user-doc
|
| * -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public void init(final IEditorSite site, final IEditorInput editorInput) {
|
| setSite(site);
|
| setInputWithNotify(editorInput);
|
| setPartName(editorInput.getName());
|
| site.setSelectionProvider(this);
|
| site.getPage().addPartListener(this.partListener);
|
| ResourcesPlugin.getWorkspace().addResourceChangeListener(this.resourceChangeListener,
|
| IResourceChangeEvent.POST_CHANGE);
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public void setFocus() {
|
| if (this.currentViewerPane != null) {
|
| this.currentViewerPane.setFocus();
|
| } else {
|
| getControl(getActivePage()).setFocus();
|
| }
|
| }
|
|
|
| /**
|
| * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void addSelectionChangedListener(final ISelectionChangedListener listener) {
|
| this.selectionChangedListeners.add(listener);
|
| }
|
|
|
| /**
|
| * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void removeSelectionChangedListener(final ISelectionChangedListener listener) {
|
| this.selectionChangedListeners.remove(listener);
|
| }
|
|
|
| /**
|
| * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to
|
| * return this editor's overall selection. <!-- begin-user-doc --> <!--
|
| * end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public ISelection getSelection() {
|
| return this.editorSelection;
|
| }
|
|
|
| /**
|
| * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to
|
| * set this editor's overall selection. Calling this result will notify the
|
| * listeners. <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void setSelection(final ISelection selection) {
|
| this.editorSelection = selection;
|
|
|
| for (ISelectionChangedListener listener : this.selectionChangedListeners) {
|
| listener.selectionChanged(new SelectionChangedEvent(this, selection));
|
| }
|
| setStatusLineManager(selection);
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void setStatusLineManager(final ISelection selection) {
|
| IStatusLineManager statusLineManager = this.currentViewer != null
|
| && this.currentViewer == this.contentOutlineViewer ? this.contentOutlineStatusLineManager
|
| : getActionBars().getStatusLineManager();
|
|
|
| if (statusLineManager != null) {
|
| if (selection instanceof IStructuredSelection) {
|
| Collection<?> collection = ((IStructuredSelection) selection).toList();
|
| switch (collection.size()) {
|
| case 0: {
|
| statusLineManager.setMessage(getString("_UI_NoObjectSelected")); //$NON-NLS-1$
|
| break;
|
| }
|
| case 1: {
|
| String text = new AdapterFactoryItemDelegator(this.adapterFactory)
|
| .getText(collection.iterator().next());
|
| statusLineManager.setMessage(getString("_UI_SingleObjectSelected", text)); //$NON-NLS-1$
|
| break;
|
| }
|
| default: {
|
| statusLineManager.setMessage(getString(
|
| "_UI_MultiObjectSelected", Integer.toString(collection.size()))); //$NON-NLS-1$
|
| break;
|
| }
|
| }
|
| } else {
|
| statusLineManager.setMessage(""); //$NON-NLS-1$
|
| }
|
| }
|
| }
|
|
|
| /**
|
| * This looks up a string in the plugin's plugin.properties file. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| private static String getString(final String key) {
|
| return FacetEditorPlugin.INSTANCE.getString(key);
|
| }
|
|
|
| /**
|
| * This looks up a string in plugin.properties, making a substitution. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| private static String getString(final String key, final Object s1) {
|
| return FacetEditorPlugin.INSTANCE.getString(key, new Object[] { s1 });
|
| }
|
|
|
| /**
|
| * This implements {@link org.eclipse.jface.action.IMenuListener} to help
|
| * fill the context menus with contributions from the Edit menu. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public void menuAboutToShow(final IMenuManager menuManager) {
|
| ((IMenuListener) getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public EditingDomainActionBarContributor getActionBarContributor() {
|
| return (EditingDomainActionBarContributor) getEditorSite().getActionBarContributor();
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public IActionBars getActionBars() {
|
| return getActionBarContributor().getActionBars();
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| public AdapterFactory getAdapterFactory() {
|
| return this.adapterFactory;
|
| }
|
|
|
| /**
|
| * <!-- begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| @Override
|
| public void dispose() {
|
| this.updateProblemIndication = false;
|
|
|
| ResourcesPlugin.getWorkspace().removeResourceChangeListener(this.resourceChangeListener);
|
|
|
| getSite().getPage().removePartListener(this.partListener);
|
|
|
| this.adapterFactory.dispose();
|
|
|
| if (getActionBarContributor().getActiveEditor() == this) {
|
| getActionBarContributor().setActiveEditor(null);
|
| }
|
|
|
| if (this.propertySheetPage != null) {
|
| this.propertySheetPage.dispose();
|
| }
|
|
|
| if (this.contentOutlinePage != null) {
|
| this.contentOutlinePage.dispose();
|
| }
|
|
|
| super.dispose();
|
| }
|
|
|
| /**
|
| * Returns whether the outline view should be presented to the user. <!--
|
| * begin-user-doc --> <!-- end-user-doc -->
|
| *
|
| * @generated
|
| */
|
| protected boolean showOutlineView() {
|
| return true;
|
| }
|
| }
|