Search in sources :

Example 1 with DiagramViewer

use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.

the class DiagramBaseAction method getDiagramViewer.

protected DiagramViewer getDiagramViewer() {
    DiagramViewer res = editor;
    final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (workbenchWindow == null) {
        return res;
    }
    final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    if (workbenchPage == null) {
        return res;
    }
    IWorkbenchPart part = workbenchPage.getActivePart();
    if (part instanceof DiagramViewer) {
        res = (DiagramViewer) part;
    } else if (part instanceof ContentOutline) {
        ContentOutline co = (ContentOutline) part;
        if (co.getCurrentPage() instanceof DiagramContentOutlinePage) {
            DiagramContentOutlinePage dcop = (DiagramContentOutlinePage) co.getCurrentPage();
            res = dcop.getEditor();
        }
    }
    return res;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) DiagramContentOutlinePage(org.jboss.tools.hibernate.ui.diagram.editors.DiagramContentOutlinePage)

Example 2 with DiagramViewer

use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer 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 3 with DiagramViewer

use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.

the class OpenMappingAction method run.

public void run() {
    DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
    ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
    DiagramViewer part = (DiagramViewer) getWorkbenchPart();
    Set<Shape> selectedElements = part.getSelectedElements();
    IEditorPart editorPart = null;
    Iterator<Shape> iterator = selectedElements.iterator();
    // open only first editor - no sense to open all of them
    while (iterator.hasNext() && editorPart == null) {
        Shape shape = iterator.next();
        Object selection = shape.getOrmElement();
        if (selection instanceof IProperty && ((IProperty) selection).getPersistentClass().isInstanceOfSpecialRootClass()) {
            IProperty compositSel = ((IProperty) selection);
            IProperty parentProperty = ((IPersistentClass) compositSel.getPersistentClass()).getProperty();
            try {
                editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, compositSel, parentProperty);
            } catch (CoreException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            } catch (FileNotFoundException e) {
                HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
            }
            continue;
        }
        if (selection instanceof IPersistentClass && ((IPersistentClass) selection).isInstanceOfSpecialRootClass()) {
            selection = ((IPersistentClass) selection).getProperty();
        }
        Shape shapeParent = null;
        Object selectionParent = null;
        if (selection instanceof IColumn) {
            shapeParent = (Shape) shape.getParent();
            selectionParent = shapeParent.getOrmElement();
        }
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, selection, selectionParent);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
        }
    }
}
Also used : DiagramEditorInput(org.jboss.tools.hibernate.ui.view.DiagramEditorInput) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) CoreException(org.eclipse.core.runtime.CoreException) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn)

Example 4 with DiagramViewer

use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.

the class OpenSourceAction method run.

public void run() {
    DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
    ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
    DiagramViewer part = (DiagramViewer) getWorkbenchPart();
    Set<Shape> selectedElements = part.getSelectedElements();
    IEditorPart editorPart = null;
    Iterator<Shape> iterator = selectedElements.iterator();
    // open only first editor - no sense to open all of them
    while (iterator.hasNext() && editorPart == null) {
        Shape shape = iterator.next();
        Object selection = shape.getOrmElement();
        if (selection instanceof IColumn || selection instanceof ITable) {
            Iterator<Connection> targetConnections = shape.getTargetConnections().iterator();
            while (targetConnections.hasNext()) {
                Connection connection = targetConnections.next();
                Shape sh1 = connection.getSource();
                Shape sh2 = connection.getTarget();
                if (shape == sh1 && sh2 != null) {
                    shape = sh2;
                    break;
                } else if (shape == sh2 && sh1 != null) {
                    shape = sh1;
                    break;
                }
            }
            selection = shape.getOrmElement();
        }
        IPersistentClass rootClass = null;
        if (selection instanceof IPersistentClass) {
            rootClass = (IPersistentClass) selection;
        } else if (selection instanceof IProperty) {
            rootClass = ((IProperty) selection).getPersistentClass();
        } else {
            continue;
        }
        // HibernateUtils.getPersistentClassName(rootClass);
        String fullyQualifiedName = rootClass.getClassName();
        /*if (fullyQualifiedName.indexOf("$") > 0) {
				fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
			}*/
        try {
            editorPart = org.hibernate.eclipse.console.actions.OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_open_source_file, e);
        } catch (FileNotFoundException e) {
            HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_find_source_file, e);
        }
    }
}
Also used : DiagramEditorInput(org.jboss.tools.hibernate.ui.view.DiagramEditorInput) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Shape(org.jboss.tools.hibernate.ui.diagram.editors.model.Shape) Connection(org.jboss.tools.hibernate.ui.diagram.editors.model.Connection) FileNotFoundException(java.io.FileNotFoundException) IEditorPart(org.eclipse.ui.IEditorPart) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) CoreException(org.eclipse.core.runtime.CoreException) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) ITable(org.jboss.tools.hibernate.runtime.spi.ITable)

Example 5 with DiagramViewer

use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.

the class PrintDiagramViewerAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
public void run() {
    GraphicalViewer viewer;
    viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class);
    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
    PrinterData data = dialog.open();
    if (data != null) {
        PrintDiagramViewerOperation op = new PrintDiagramViewerOperation(new Printer(data), viewer);
        DiagramViewer dv = (DiagramViewer) getWorkbenchPart();
        op.setZoom(dv.getZoom());
        if (Math.abs(dv.getZoom() - dv.getFitHeightZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_HEIGHT);
        } else if (Math.abs(dv.getZoom() - dv.getFitWidthZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_WIDTH);
        } else if (Math.abs(dv.getZoom() - dv.getFitPageZoomValue()) < 0.00000001) {
            op.setPrintMode(PrintGraphicalViewerOperation.FIT_PAGE);
        } else {
            op.setPrintMode(PrintGraphicalViewerOperation.TILE);
        }
        op.run(getWorkbenchPart().getTitle());
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Printer(org.eclipse.swt.printing.Printer) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) PrintDiagramViewerOperation(org.jboss.tools.hibernate.ui.diagram.print.PrintDiagramViewerOperation)

Aggregations

DiagramViewer (org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer)6 FileNotFoundException (java.io.FileNotFoundException)2 CoreException (org.eclipse.core.runtime.CoreException)2 IFigure (org.eclipse.draw2d.IFigure)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)2 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)2 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)2 Shape (org.jboss.tools.hibernate.ui.diagram.editors.model.Shape)2 DiagramEditorInput (org.jboss.tools.hibernate.ui.view.DiagramEditorInput)2 File (java.io.File)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)1 PrintDialog (org.eclipse.swt.printing.PrintDialog)1 Printer (org.eclipse.swt.printing.Printer)1