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;
}
}
});
}
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);
}
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;
}
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);
}
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;
}
}
}
}
}
}
}
}
Aggregations