Example usage for org.eclipse.jface.dialogs MessageDialog openWarning

List of usage examples for org.eclipse.jface.dialogs MessageDialog openWarning

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openWarning.

Prototype

public static void openWarning(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard warning dialog.

Usage

From source file:edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.IStar_MAVODiagramEditor.java

License:Open Source License

/**
* @generated//from  w ww.  j  a v  a2 s  . c  o m
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(
                edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.Messages.IStar_MAVODiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell,
                    edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.Messages.IStar_MAVODiagramEditor_SaveAsErrorTitle,
                    edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.Messages.IStar_MAVODiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell,
                    edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.Messages.IStar_MAVODiagramEditor_SaveErrorTitle,
                    edu.toronto.cs.se.modelepedia.istar_mavo.diagram.part.Messages.IStar_MAVODiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.NECSIS14_ClassDiagramDiagramEditor.java

License:Open Source License

/**
 * @generated// www .ja  v a2 s  . c  o m
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(
                edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.Messages.NECSIS14_ClassDiagramDiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell,
                    edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.Messages.NECSIS14_ClassDiagramDiagramEditor_SaveAsErrorTitle,
                    edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.Messages.NECSIS14_ClassDiagramDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell,
                    edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.Messages.NECSIS14_ClassDiagramDiagramEditor_SaveErrorTitle,
                    edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part.Messages.NECSIS14_ClassDiagramDiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.NECSIS14_DatabaseSchemaDiagramEditor.java

License:Open Source License

/**
 * @generated/*from  ww  w.  j  a  va2s  .c o  m*/
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(
                edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.Messages.NECSIS14_DatabaseSchemaDiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell,
                    edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.Messages.NECSIS14_DatabaseSchemaDiagramEditor_SaveAsErrorTitle,
                    edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.Messages.NECSIS14_DatabaseSchemaDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell,
                    edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.Messages.NECSIS14_DatabaseSchemaDiagramEditor_SaveErrorTitle,
                    edu.toronto.cs.se.modelepedia.necsis14_databaseschema.diagram.part.Messages.NECSIS14_DatabaseSchemaDiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.powerwindow.diagram.part.PowerWindowDiagramEditor.java

License:Open Source License

/**
 * @generated//from   w w  w.  j ava  2 s  .  c  o  m
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.PowerWindowDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.PowerWindowDiagramEditor_SaveAsErrorTitle,
                    Messages.PowerWindowDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.PowerWindowDiagramEditor_SaveErrorTitle,
                    Messages.PowerWindowDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.relationaldatabase.diagram.part.RelationalDatabaseDiagramEditor.java

License:Open Source License

/**
 * @generated// w ww.  j a va2 s .  co m
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.RelationalDatabaseDiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.RelationalDatabaseDiagramEditor_SaveAsErrorTitle,
                    Messages.RelationalDatabaseDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.RelationalDatabaseDiagramEditor_SaveErrorTitle,
                    Messages.RelationalDatabaseDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.RelationalDatabase_MAVODiagramEditor.java

License:Open Source License

/**
* @generated/* www  . j a  v a2 s  .co m*/
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(
                edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.Messages.RelationalDatabase_MAVODiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell,
                    edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.Messages.RelationalDatabase_MAVODiagramEditor_SaveAsErrorTitle,
                    edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.Messages.RelationalDatabase_MAVODiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell,
                    edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.Messages.RelationalDatabase_MAVODiagramEditor_SaveErrorTitle,
                    edu.toronto.cs.se.modelepedia.relationaldatabase_mavo.diagram.part.Messages.RelationalDatabase_MAVODiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.statemachine.diagram.part.StateMachineDiagramEditor.java

License:Open Source License

/**
 * @generated/*from  w ww .  j a  va 2s .  c o m*/
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.StateMachineDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.StateMachineDiagramEditor_SaveAsErrorTitle,
                    Messages.StateMachineDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.StateMachineDiagramEditor_SaveErrorTitle,
                    Messages.StateMachineDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.StateMachine_MAVODiagramEditor.java

License:Open Source License

/**
* @generated/*w  ww.j  av  a2 s . c o m*/
*/
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(
                edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages.StateMachine_MAVODiagramEditor_SavingDeletedFile,
                original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell,
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages.StateMachine_MAVODiagramEditor_SaveAsErrorTitle,
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages.StateMachine_MAVODiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell,
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages.StateMachine_MAVODiagramEditor_SaveErrorTitle,
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages.StateMachine_MAVODiagramEditor_SaveErrorMessage,
                    x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.tutorial.army.diagram.part.ArmyDiagramEditor.java

License:Open Source License

/**
 * @generated//from  w w  w  . java  2 s. c  o m
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.ArmyDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.ArmyDiagramEditor_SaveAsErrorTitle,
                    Messages.ArmyDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.ArmyDiagramEditor_SaveErrorTitle,
                    Messages.ArmyDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}

From source file:edu.toronto.cs.se.modelepedia.tutorial.economy.diagram.part.EconomyDiagramEditor.java

License:Open Source License

/**
 * @generated/*  ww w  . j a v  a2 s.  c  om*/
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
    if (original != null) {
        dialog.setOriginalFile(original);
    }
    dialog.create();
    IDocumentProvider provider = getDocumentProvider();
    if (provider == null) {
        // editor has been programmatically closed while the dialog was open
        return;
    }
    if (provider.isDeleted(input) && original != null) {
        String message = NLS.bind(Messages.EconomyDiagramEditor_SavingDeletedFile, original.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.CANCEL) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IPath filePath = dialog.getResult();
    if (filePath == null) {
        if (progressMonitor != null) {
            progressMonitor.setCanceled(true);
        }
        return;
    }
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IFile file = workspaceRoot.getFile(filePath);
    final IEditorInput newInput = new FileEditorInput(file);
    // Check if the editor is already open
    IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
    IEditorReference[] editorRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    for (int i = 0; i < editorRefs.length; i++) {
        if (matchingStrategy.matches(editorRefs[i], newInput)) {
            MessageDialog.openWarning(shell, Messages.EconomyDiagramEditor_SaveAsErrorTitle,
                    Messages.EconomyDiagramEditor_SaveAsErrorMessage);
            return;
        }
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        getDocumentProvider(newInput).saveDocument(progressMonitor, newInput,
                getDocumentProvider().getDocument(getEditorInput()), true);
        success = true;
    } catch (CoreException x) {
        IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            ErrorDialog.openError(shell, Messages.EconomyDiagramEditor_SaveErrorTitle,
                    Messages.EconomyDiagramEditor_SaveErrorMessage, x.getStatus());
        }
    } finally {
        provider.changed(newInput);
        if (success) {
            setInput(newInput);
        }
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}