Search in sources :

Example 51 with BasicCommandStack

use of org.eclipse.emf.common.command.BasicCommandStack in project ecf by eclipse.

the class DiscoveryEditingDomainProvider method load.

public void load() {
    // Create an adapter factory that yields item providers.
    adapterFactory = new ComposedAdapterFactory();
    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ModelItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
    // Create the command stack that will notify this editor as commands are executed.
    commandStack = new BasicCommandStack();
    // Create the editing domain with a special command stack.
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap());
    // Load the resource through the editing domain.
    URI resourceURI = URI.createURI("service://");
    try {
        getEditingDomain().getResourceSet().getResource(resourceURI, true);
    } catch (Exception e) {
        getEditingDomain().getResourceSet().getResource(resourceURI, false);
    }
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) HashMap(java.util.HashMap) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) URI(org.eclipse.emf.common.util.URI) IOException(java.io.IOException)

Example 52 with BasicCommandStack

use of org.eclipse.emf.common.command.BasicCommandStack in project InformationSystem by ObeoNetwork.

the class SoaEditor method 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.
    // 
    adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new SoaItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EnvironmentItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
    // Create the command stack that will notify this editor as commands are executed.
    // 
    BasicCommandStack commandStack = new BasicCommandStack();
    // 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 (propertySheetPage != null && !propertySheetPage.getControl().isDisposed() && propertySheetPage.getCurrentTab() != null) {
                        propertySheetPage.refresh();
                    }
                }
            });
        }
    });
    // Create the editing domain with a special command stack.
    // 
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) CommandStack(org.eclipse.emf.common.command.CommandStack) CommandStackListener(org.eclipse.emf.common.command.CommandStackListener) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) EventObject(java.util.EventObject) SoaItemProviderAdapterFactory(org.obeonetwork.dsl.soa.provider.SoaItemProviderAdapterFactory) ReflectiveItemProviderAdapterFactory(org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory) Command(org.eclipse.emf.common.command.Command) EnvironmentItemProviderAdapterFactory(org.obeonetwork.dsl.environment.provider.EnvironmentItemProviderAdapterFactory)

Example 53 with BasicCommandStack

use of org.eclipse.emf.common.command.BasicCommandStack in project InformationSystem by ObeoNetwork.

the class SoaEditor method doSave.

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(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(IProgressMonitor monitor) {
            // Save the resources to the file system.
            // 
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };
    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        // 
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
        // Refresh the necessary state.
        // 
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        // 
        SoaEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) EventObject(java.util.EventObject) EObject(org.eclipse.emf.ecore.EObject) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 54 with BasicCommandStack

use of org.eclipse.emf.common.command.BasicCommandStack in project InformationSystem by ObeoNetwork.

the class StateMachineEditor method doSave.

/**
 * This is for implementing {@link IEditorPart} and simply saves the model file.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSave(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(IProgressMonitor monitor) {
            // Save the resources to the file system.
            // 
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
                if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) {
                    try {
                        long timeStamp = resource.getTimeStamp();
                        resource.save(saveOptions);
                        if (resource.getTimeStamp() != timeStamp) {
                            savedResources.add(resource);
                        }
                    } catch (Exception exception) {
                        resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
                    }
                    first = false;
                }
            }
        }
    };
    updateProblemIndication = false;
    try {
        // This runs the options, and shows progress.
        // 
        new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
        // Refresh the necessary state.
        // 
        ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
        firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
        // Something went wrong that shouldn't.
        // 
        StateMachineEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) EventObject(java.util.EventObject) EObject(org.eclipse.emf.ecore.EObject) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException)

Example 55 with BasicCommandStack

use of org.eclipse.emf.common.command.BasicCommandStack in project InformationSystem by ObeoNetwork.

the class StateMachineEditor method 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.
    // 
    adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
    adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new StateMachineItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EnvironmentItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
    // Create the command stack that will notify this editor as commands are executed.
    // 
    BasicCommandStack commandStack = new BasicCommandStack();
    // 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 (propertySheetPage != null && !propertySheetPage.getControl().isDisposed() && propertySheetPage.getCurrentTab() != null) {
                        propertySheetPage.refresh();
                    }
                }
            });
        }
    });
    // Create the editing domain with a special command stack.
    // 
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) CommandStack(org.eclipse.emf.common.command.CommandStack) CommandStackListener(org.eclipse.emf.common.command.CommandStackListener) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) EventObject(java.util.EventObject) StateMachineItemProviderAdapterFactory(org.obeonetwork.dsl.statemachine.provider.StateMachineItemProviderAdapterFactory) ReflectiveItemProviderAdapterFactory(org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory) Command(org.eclipse.emf.common.command.Command) EnvironmentItemProviderAdapterFactory(org.obeonetwork.dsl.environment.provider.EnvironmentItemProviderAdapterFactory)

Aggregations

HashMap (java.util.HashMap)61 BasicCommandStack (org.eclipse.emf.common.command.BasicCommandStack)61 EventObject (java.util.EventObject)60 LinkedHashMap (java.util.LinkedHashMap)60 IOException (java.io.IOException)31 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)31 IResource (org.eclipse.core.resources.IResource)30 CoreException (org.eclipse.core.runtime.CoreException)30 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)30 Command (org.eclipse.emf.common.command.Command)30 CommandStack (org.eclipse.emf.common.command.CommandStack)30 CommandStackListener (org.eclipse.emf.common.command.CommandStackListener)30 Resource (org.eclipse.emf.ecore.resource.Resource)30 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)30 ResourceItemProviderAdapterFactory (org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory)30 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)30 PartInitException (org.eclipse.ui.PartInitException)30 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)30 ReflectiveItemProviderAdapterFactory (org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory)29 EObject (org.eclipse.emf.ecore.EObject)21