Search in sources :

Example 21 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.

the class PrintDisplayAction method run.

/**
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    final GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    viewer.getControl().getDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            final ImageLoader loader = new ImageLoader();
            ImageData[] imageData;
            try {
                imageData = loader.load(ResourceUtil.getScreenshotFile(viewer));
                if (imageData.length > 0) {
                    PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
                    final PrinterData data = dialog.open();
                    if (data != null) {
                        Printer printer = new Printer(data);
                        // Calculate the scale factor between the screen resolution
                        // and printer
                        // resolution in order to correctly size the image for the
                        // printer
                        Point screenDPI = viewer.getControl().getDisplay().getDPI();
                        Point printerDPI = printer.getDPI();
                        int scaleFactor = printerDPI.x / screenDPI.x;
                        // Determine the bounds of the entire area of the printer
                        Rectangle trim = printer.computeTrim(0, 0, 0, 0);
                        Image printerImage = new Image(printer, imageData[0]);
                        if (printer.startJob("Printing OPI")) {
                            if (printer.startPage()) {
                                GC gc = new GC(printer);
                                Rectangle printArea = printer.getClientArea();
                                if (imageData[0].width * scaleFactor <= printArea.width) {
                                    printArea.width = imageData[0].width * scaleFactor;
                                    printArea.height = imageData[0].height * scaleFactor;
                                } else {
                                    printArea.height = printArea.width * imageData[0].height / imageData[0].width;
                                }
                                gc.drawImage(printerImage, 0, 0, imageData[0].width, imageData[0].height, -trim.x, -trim.y, printArea.width, printArea.height);
                                gc.dispose();
                                printer.endPage();
                            }
                        }
                        printer.endJob();
                        printer.dispose();
                        printerImage.dispose();
                    }
                }
            } catch (Exception e) {
                ErrorHandlerUtil.handleError("Failed to print OPI", e);
                return;
            }
        }
    });
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) PrintDialog(org.eclipse.swt.printing.PrintDialog) PrinterData(org.eclipse.swt.printing.PrinterData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Printer(org.eclipse.swt.printing.Printer) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 22 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project cubrid-manager by CUBRID.

the class ReplicationEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new PartFactory(this));
    ZoomManager manager = rootEditPart.getZoomManager();
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    double[] zoomLevels = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
    manager.setZoomLevels(zoomLevels);
    List<String> zoomContributions = new ArrayList<String>();
    zoomContributions.add(ZoomManager.FIT_ALL);
    zoomContributions.add(ZoomManager.FIT_HEIGHT);
    zoomContributions.add(ZoomManager.FIT_WIDTH);
    manager.setZoomLevelContributions(zoomContributions);
    KeyHandler keyHandler = new KeyHandler();
    if (isEditable) {
        keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    }
    keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    keyHandler.put(KeyStroke.getPressed('a', 97, 0), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    ContextMenuProvider provider = new ReplEditorContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) PartFactory(com.cubrid.cubridmanager.ui.replication.editor.parts.PartFactory) ScalableRootEditPart(org.eclipse.gef.editparts.ScalableRootEditPart) ArrayList(java.util.ArrayList) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ZoomManager(org.eclipse.gef.editparts.ZoomManager) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction)

Example 23 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project tdi-studio-se by Talend.

the class ProcessLayoutEditPolicy method getConnectionAndEndCommands.

protected Command getConnectionAndEndCommands(CreateConnectionRequest request) {
    CompoundCommand cc = new CompoundCommand("CreateNodeCommand");
    ProcessPart processPart = (ProcessPart) this.getHost();
    final GraphicalViewer graphicalViewer = (GraphicalViewer) processPart.getViewer();
    final CommandStack commandStack = processPart.getViewer().getEditDomain().getCommandStack();
    final String categoryName = ComponentsFactoryProvider.getInstance().getComponentsHandler().extractComponentsCategory().getName();
    final IProcess2 process = (IProcess2) processPart.getModel();
    TalendEditorConnectionTargetAssist assist = new TalendEditorConnectionTargetAssist(categoryName, graphicalViewer, commandStack, process);
    char start = '*';
    assist.showComponentCreationAssist(start);
    ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
    if (assist.getComponentName() == null) {
        assist.releaseText();
        return cmd;
    }
    IComponent component = TalendEditorComponentCreationUtil.getComponentsInCategory(categoryName).get(assist.getComponentName());
    if (component == null) {
        assist.releaseText();
        return cmd;
    }
    assist.releaseText();
    Node newNode = new Node(component);
    NodeContainer nodeContainer = ((Process) newNode.getProcess()).loadNodeContainer(newNode, false);
    CreateNodeContainerCommand command = new CreateNodeContainerCommand((org.talend.designer.core.ui.editor.process.Process) newNode.getProcess(), nodeContainer, request.getLocation());
    cc.add(command);
    cmd.setTarget(newNode);
    cc.add(cmd);
    return cc;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) IProcess2(org.talend.core.model.process.IProcess2) TalendEditorConnectionTargetAssist(org.talend.designer.core.assist.TalendEditorConnectionTargetAssist)

Example 24 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project tdi-studio-se by Talend.

the class TalendEditorComponentCreationUtil method addComponentCreationAssist.

public static void addComponentCreationAssist(AbstractTalendEditor talendEditor) {
    final GraphicalViewer graphicalViewer = (GraphicalViewer) talendEditor.getAdapter(GraphicalViewer.class);
    final CommandStack commandStack = (CommandStack) talendEditor.getAdapter(CommandStack.class);
    final String categoryName = talendEditor.getComponenentsHandler().extractComponentsCategory().getName();
    final IProcess2 process = talendEditor.getProcess();
    KeyListener listener = new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (Character.isISOControl(e.character) || Character.isSpaceChar(e.character)) {
                return;
            }
            TalendEditorComponentCreationAssist assist = new TalendEditorComponentCreationAssist(categoryName, graphicalViewer, commandStack, process);
            assist.showComponentCreationAssist(e.character);
        }
    };
    graphicalViewer.getControl().addKeyListener(listener);
    graphicalViewer.getControl().setData(COMPONENT_CREATION_ASSIST_LISTENER, listener);
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IProcess2(org.talend.core.model.process.IProcess2) KeyListener(org.eclipse.swt.events.KeyListener)

Example 25 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method selectNode.

/**
     * DOC bqian Comment method "selectNode".
     * 
     * @param node
     */
@SuppressWarnings("unchecked")
public void selectNode(String nodeName) {
    GraphicalViewer viewer = designerEditor.getViewer();
    Object object = viewer.getRootEditPart().getChildren().get(0);
    if (object instanceof ProcessPart) {
        // ProcessPart < SubjobContainerPart < NodeContainerPart < NodePart
        for (EditPart editPart : (List<EditPart>) ((ProcessPart) object).getChildren()) {
            if (editPart instanceof SubjobContainerPart) {
                SubjobContainerPart subjobPart = (SubjobContainerPart) editPart;
                for (EditPart part : (List<EditPart>) subjobPart.getChildren()) {
                    if (part instanceof NodeContainerPart) {
                        EditPart nodePart = (EditPart) part.getChildren().get(0);
                        if (nodePart instanceof NodePart) {
                            if (((Node) ((NodePart) nodePart).getModel()).getLabel().equals(nodeName)) {
                                viewer.select(nodePart);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) EditPart(org.eclipse.gef.EditPart) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) ArrayList(java.util.ArrayList) List(java.util.List) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Aggregations

GraphicalViewer (org.eclipse.gef.GraphicalViewer)36 ArrayList (java.util.ArrayList)11 List (java.util.List)10 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)10 EditPart (org.eclipse.gef.EditPart)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)7 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)6 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)5 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)4 ZoomManager (org.eclipse.gef.editparts.ZoomManager)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IProcess (org.talend.core.model.process.IProcess)4 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)4 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Process (org.talend.designer.core.ui.editor.process.Process)4 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 PlatformObject (org.eclipse.core.runtime.PlatformObject)3