Search in sources :

Example 36 with BasicCommandStack

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

the class DatabaseEditor 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.
        // 
        DatabaseEditorPlugin.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 37 with BasicCommandStack

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

the class FlowEditor method initializeEditingDomain.

/**
 * This sets up the editing domain for the model editor.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
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 CinematicItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ViewItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new FlowItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new ToolkitsItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new EnvironmentItemProviderAdapterFactory());
    adapterFactory.addAdapterFactory(new TechnicalIDItemProviderAdapterFactory());
    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());
                    }
                    for (Iterator<PropertySheetPage> i = propertySheetPages.iterator(); i.hasNext(); ) {
                        PropertySheetPage propertySheetPage = i.next();
                        if (propertySheetPage.getControl().isDisposed()) {
                            i.remove();
                        } else {
                            propertySheetPage.refresh();
                        }
                    }
                }
            });
        }
    });
    // Create the editing domain with a special command stack.
    // 
    editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>());
}
Also used : TechnicalIDItemProviderAdapterFactory(org.obeonetwork.dsl.technicalid.provider.TechnicalIDItemProviderAdapterFactory) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) CommandStack(org.eclipse.emf.common.command.CommandStack) FlowItemProviderAdapterFactory(org.obeonetwork.dsl.cinematic.flow.provider.FlowItemProviderAdapterFactory) PropertySheetPage(org.eclipse.ui.views.properties.PropertySheetPage) IPropertySheetPage(org.eclipse.ui.views.properties.IPropertySheetPage) ExtendedPropertySheetPage(org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage) ViewItemProviderAdapterFactory(org.obeonetwork.dsl.cinematic.view.provider.ViewItemProviderAdapterFactory) CommandStackListener(org.eclipse.emf.common.command.CommandStackListener) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ToolkitsItemProviderAdapterFactory(org.obeonetwork.dsl.cinematic.toolkits.provider.ToolkitsItemProviderAdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) EventObject(java.util.EventObject) ReflectiveItemProviderAdapterFactory(org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory) Command(org.eclipse.emf.common.command.Command) EnvironmentItemProviderAdapterFactory(org.obeonetwork.dsl.environment.provider.EnvironmentItemProviderAdapterFactory) CinematicItemProviderAdapterFactory(org.obeonetwork.dsl.cinematic.provider.CinematicItemProviderAdapterFactory)

Example 38 with BasicCommandStack

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

the class CinematicEditor 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.
        // 
        CinematicEditorPlugin.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 39 with BasicCommandStack

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

the class ToolkitsEditor 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.
        // 
        CinematicEditorPlugin.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 40 with BasicCommandStack

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

the class ViewEditor 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.
        // 
        CinematicEditorPlugin.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)

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