Search in sources :

Example 6 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project jbosstools-hibernate by jbosstools.

the class ExportImageActionTest method testAction.

public void testAction() {
    final DiagramViewer editor = context.mock(DiagramViewer.class);
    final SaveAsDialog saveDialog = context.mock(SaveAsDialog.class);
    final GraphicalViewer graphicalViewer = context.mock(GraphicalViewer.class);
    final ScalableFreeformRootEditPart scalableFreeformRootEditPart = context.mock(ScalableFreeformRootEditPart.class);
    final IFigure figure = context.mock(IFigure.class);
    final Control control = context.mock(Control.class);
    final Display display = context.mock(Display.class);
    final Rectangle rectangle = new Rectangle(0, 0, 20, 10);
    // $NON-NLS-1$
    final String filePath = PROJECT_NAME + File.separator + "test.jpg";
    final IPath resPath = new Path(filePath);
    context.checking(new Expectations() {

        {
            allowing(editor).getStoreFileName();
            will(returnValue(filePath));
            allowing(saveDialog).setOriginalName(filePath);
            oneOf(saveDialog).open();
            will(returnValue(0));
            oneOf(saveDialog).getResult();
            will(returnValue(resPath));
            allowing(editor).getEditPartViewer();
            will(returnValue(graphicalViewer));
            allowing(graphicalViewer).getRootEditPart();
            will(returnValue(scalableFreeformRootEditPart));
            allowing(scalableFreeformRootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
            will(returnValue(figure));
            allowing(figure).getBounds();
            will(returnValue(rectangle));
        }
    });
    final ExportImageAction exportImageAction = new ExportImageAction(editor);
    exportImageAction.setSaveDialog(saveDialog);
    exportImageAction.setShowErrDialog(false);
    exportImageAction.run();
    // test is the file created
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath path = workspace.getRoot().getFullPath().append(resPath);
    path = workspace.getRoot().getLocation().append(path);
    File file = path.toFile();
    assertTrue(file.exists() && file.isFile());
    // 
    boolean res = file.delete();
    assertTrue(res);
    // GENERAL TEST:
    // check for all expectations
    context.assertIsSatisfied();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Expectations(org.jmock.Expectations) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) Control(org.eclipse.swt.widgets.Control) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) IWorkspace(org.eclipse.core.resources.IWorkspace) File(java.io.File) IFigure(org.eclipse.draw2d.IFigure) Display(org.eclipse.swt.widgets.Display)

Example 7 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project InformationSystem by ObeoNetwork.

the class StateMachineEditor method doSaveAs.

/**
 * 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));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 8 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project InformationSystem by ObeoNetwork.

the class TypesLibraryEditor method doSaveAs.

/**
 * 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));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 9 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project InformationSystem by ObeoNetwork.

the class EntityEditor method doSaveAs.

/**
 * 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));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 10 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project InformationSystem by ObeoNetwork.

the class RequirementEditor method doSaveAs.

/**
 * 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));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Aggregations

IPath (org.eclipse.core.runtime.IPath)42 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)42 IFile (org.eclipse.core.resources.IFile)39 FileEditorInput (org.eclipse.ui.part.FileEditorInput)35 IWorkspace (org.eclipse.core.resources.IWorkspace)5 CoreException (org.eclipse.core.runtime.CoreException)5 Shell (org.eclipse.swt.widgets.Shell)4 IFileEditorInput (org.eclipse.ui.IFileEditorInput)4 File (java.io.File)3 IEditorInput (org.eclipse.ui.IEditorInput)3 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)3 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFigure (org.eclipse.draw2d.IFigure)2 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2