use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project yamcs-studio by yamcs.
the class OPIRuntimeDelegate method createGUI.
public void createGUI(Composite parent) {
viewer = new PatchedScrollingGraphicalViewer();
if (displayModel != null) {
displayModel.setOpiRuntime(opiRuntime);
displayModel.setViewer(viewer);
}
ScalableFreeformRootEditPart root = new PatchedScalableFreeformRootEditPart() {
// In Run mode, clicking the Display or container should de-select
// all widgets.
@Override
public DragTracker getDragTracker(Request req) {
return new DragEditPartsTracker(this);
}
@Override
public boolean isSelectable() {
return false;
}
};
// set clipping strategy for connection layer of connection can be hide
// when its source or target is not showing.
ConnectionLayer connectionLayer = (ConnectionLayer) root.getLayer(LayerConstants.CONNECTION_LAYER);
connectionLayer.setClippingStrategy(new PatchedConnectionLayerClippingStrategy(connectionLayer));
viewer.createControl(parent);
viewer.setRootEditPart(root);
viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.RUN_MODE, site));
// viewer.addDropTargetListener(new
// ProcessVariableNameTransferDropPVTargetListener(viewer));
// viewer.addDropTargetListener(new
// TextTransferDropPVTargetListener(viewer));
// Add drag listener will make click feel stagnant.
// viewer.addDragSourceListener(new DragPVSourceListener(viewer));
// this will make viewer as a selection provider
EditDomain editDomain = new EditDomain() {
@Override
public void loadDefaultTool() {
setActiveTool(new RuntimePatchedSelectionTool());
}
};
editDomain.addViewer(viewer);
// connect the CSS menu
ContextMenuProvider cmProvider = new OPIRunnerContextMenuProvider(viewer, opiRuntime);
viewer.setContextMenu(cmProvider);
opiRuntime.getSite().registerContextMenu(cmProvider, viewer);
if (displayModelFilled) {
viewer.setContents(displayModel);
displayModel.setViewer(viewer);
displayModel.setOpiRuntime(opiRuntime);
updateEditorTitle();
}
zoomManager = root.getZoomManager();
if (zoomManager != null) {
List<String> zoomLevels = new ArrayList<>(3);
zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_ALL);
zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_WIDTH);
zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_HEIGHT);
zoomManager.setZoomLevelContributions(zoomLevels);
zoomManager.setZoomLevels(createZoomLevels());
// IAction zoomIn = new ZoomInAction(zoomManager);
// IAction zoomOut = new ZoomOutAction(zoomManager);
// getActionRegistry().registerAction(zoomIn);
// getActionRegistry().registerAction(zoomOut);
}
/* scroll-wheel zoom */
viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
/*
* When Figure instance which corresponds to RootEditPart is updated, calculate the frame rate and set the
* measured rate to "frame_rate" property of the corresponding DisplayModel instance.
*
* By default, org.eclipse.draw2d.DeferredUpdateManager is used. This update manager queues update requests from
* figures and others, and it repaints requested figures at once when GUI thread is ready to repaint.
* notifyPainting() method of UpdateLister is called when it repaints. The frame rate is calculated based on the
* timing of notifyPainting().
*
* Note that the update manager repaints only requested figures. It does not repaint all figures at once. For
* example, if there are only two widgets in one display, these widgets might be repainted alternately. In that
* case, the frame rate indicates the inverse of the time between the repainting of one widget and the
* repainting of the other widget, which is different from our intuition. Thus, you have to be careful about the
* meaning of "frame rate" calculated by the following code.
*/
if (displayModelFilled && displayModel.isFreshRateEnabled()) {
UpdateManager updateManager = root.getFigure().getUpdateManager();
updateManager.addUpdateListener(new UpdateListener() {
// in milliseconds
private long updateCycle = -1;
private Date previousDate = null;
@Override
public void notifyPainting(Rectangle damage, @SuppressWarnings("rawtypes") Map dirtyRegions) {
Date currentDate = new Date();
if (previousDate == null) {
previousDate = currentDate;
return;
}
synchronized (previousDate) {
updateCycle = currentDate.getTime() - previousDate.getTime();
displayModel.setFrameRate(1000.0 / updateCycle);
previousDate = currentDate;
}
}
@Override
public void notifyValidating() {
// Do nothing
}
});
}
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project jbosstools-hibernate by jbosstools.
the class ExportImageAction method run.
public void run() {
boolean createdSaveDialog = false;
if (saveDialog == null) {
saveDialog = new SaveAsDialog(getDiagramViewer().getSite().getWorkbenchWindow().getShell());
createdSaveDialog = true;
}
saveDialog.setOriginalName(getDiagramViewer().getStoreFileName());
saveDialog.open();
final IPath pathSave = saveDialog.getResult();
saveDialog = null;
if (pathSave == null) {
return;
}
final IFigure fig = ((ScalableFreeformRootEditPart) getDiagramViewer().getEditPartViewer().getRootEditPart()).getLayer(LayerConstants.PRINTABLE_LAYERS);
int imageTypeTmp = SWT.IMAGE_BMP;
String ext = pathSave.getFileExtension();
if (ext != null) {
ext = ext.toLowerCase();
if (ext.endsWith("jpg")) {
// $NON-NLS-1$
imageTypeTmp = SWT.IMAGE_JPEG;
} else if (ext.endsWith("png")) {
// $NON-NLS-1$
imageTypeTmp = SWT.IMAGE_PNG;
} else if (ext.endsWith("gif")) {
// $NON-NLS-1$
imageTypeTmp = SWT.IMAGE_GIF;
} else if (ext.endsWith("bmp")) {
// $NON-NLS-1$
imageTypeTmp = SWT.IMAGE_BMP;
}
}
IPath pathTmp = pathSave;
if (ext == null) {
// $NON-NLS-1$
pathTmp = pathTmp.addFileExtension("bmp");
}
final IPath path = pathTmp;
final int imageType = imageTypeTmp;
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
public void execute(final IProgressMonitor monitor) {
ByteArrayInputStream inputStream = null;
try {
if (file != null) {
byte[] imageData = createImage(fig, imageType);
if (file.exists()) {
file.delete(true, null);
}
if (!file.exists()) {
inputStream = new ByteArrayInputStream(imageData);
file.create(inputStream, true, null);
}
}
} catch (CoreException e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("ExportImageAction", e);
if (showErrDialog) {
MessageDialog.openInformation(getDiagramViewer().getSite().getShell(), DiagramViewerMessages.ExportImageAction_error, DiagramViewerMessages.ExportImageAction_failed_to_export_image + e.getMessage());
}
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
};
try {
new ProgressMonitorDialog(createdSaveDialog ? getDiagramViewer().getSite().getWorkbenchWindow().getShell() : null).run(false, true, op);
} catch (InvocationTargetException e) {
} catch (InterruptedException e) {
}
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart 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();
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project jbosstools-hibernate by jbosstools.
the class AbstractGraphViewPart method initActions.
private void initActions() {
ScalableFreeformRootEditPart root = ((ScalableFreeformRootEditPart) viewer.getRootEditPart());
this.actionGroup = new GraphViewActionGroup(this, ConsolePreferencesConstants.ENTITY_MODEL_LAYOUT, root);
IActionBars actionBars = getViewSite().getActionBars();
this.actionGroup.fillActionBars(actionBars);
List<String> zoomLevels = new ArrayList<String>(3);
zoomLevels.add(ZoomManager.FIT_ALL);
zoomLevels.add(ZoomManager.FIT_WIDTH);
zoomLevels.add(ZoomManager.FIT_HEIGHT);
root.getZoomManager().setZoomLevelContributions(zoomLevels);
root.getZoomManager().setZoomLevels(new double[] { .067, .125, .25, .5, .75, 1.0, 1.5, 2.0, 2.5, 3, 4 });
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project jbosstools-hibernate by jbosstools.
the class AbstractGraphViewPart method createPartControl.
public void createPartControl(Composite parent) {
viewer = new ScrollingGraphicalViewer();
viewer.createControl(parent);
viewer.setRootEditPart(new ScalableFreeformRootEditPart());
viewer.getControl().setBackground(ColorConstants.white);
viewer.setEditPartFactory(createEditPartFactory());
editDomain.addViewer(viewer);
getSite().setSelectionProvider(viewer);
setupListener();
initActions();
}
Aggregations