use of org.eclipse.gef.editparts.ZoomManager in project tdi-studio-se by Talend.
the class ComponentChooseDialog method dragOver.
@Override
public void dragOver(DropTargetEvent event) {
// multi-drag for job,context, sqlPattern.
IStructuredSelection selection = getSelection();
if (selection.size() > 1) {
boolean allowed = true;
Item temItem = null;
Iterator iter = selection.iterator();
while (iter.hasNext()) {
Object next = iter.next();
if (next instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) next;
IRepositoryViewObject object = sourceNode.getObject();
if (object != null) {
Item selectItem = object.getProperty().getItem();
if (temItem == null) {
temItem = selectItem;
continue;
}
if (selectItem instanceof ProcessItem && !(temItem instanceof ProcessItem)) {
allowed = false;
} else if (selectItem instanceof ContextItem && !(temItem instanceof ContextItem)) {
allowed = false;
} else if (selectItem instanceof SQLPatternItem && !(temItem instanceof SQLPatternItem)) {
allowed = false;
}
}
}
}
if (!allowed) {
event.detail = DND.DROP_NONE;
}
} else {
CreateRequest req = ((CreateRequest) getTargetRequest());
Object o = null;
try {
o = req.getNewObject();
} catch (Exception e) {
return;
}
if (!(o instanceof Node)) {
return;
}
RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
Point viewOriginalPosition = new Point();
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
Viewport viewport = (Viewport) root.getFigure();
viewOriginalPosition = viewport.getViewLocation();
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event.x + viewOriginalPosition.x, event.y + viewOriginalPosition.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
swtLocation = canvas.toControl(swtLocation);
// System.out.println("topLeft:" + topLeftpoint + " / event:" + swtLocation);
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
double zoom = 1.0;
if (editor.getViewer().getRootEditPart() instanceof TalendScalableFreeformRootEditPart) {
ZoomManager zoomManager = ((TalendScalableFreeformRootEditPart) editor.getViewer().getRootEditPart()).getZoomManager();
zoom = zoomManager.getZoom();
}
List<ConnectionPart> connectionParts = CreateComponentOnLinkHelper.getConnectionParts(editor.getProcessPart(), draw2dPosition, (Node) o);
double minDistance = 1000000000;
for (ConnectionPart part : connectionParts) {
if (part.getFigure() instanceof PolylineConnection) {
PolylineConnection connection = (PolylineConnection) part.getFigure();
double distance = CreateComponentOnLinkHelper.getDistanceOrthogonal(draw2dPosition.x, draw2dPosition.y, connection, zoom);
if (distance < minDistance) {
selectedConnectionPart = part;
minDistance = Math.min(distance, minDistance);
}
}
}
if (selectedConnectionPart != null && minDistance < 15) {
for (Object child : editor.getProcessPart().getChildren()) {
if (child instanceof SubjobContainerPart) {
CreateComponentOnLinkHelper.unselectAllConnections((SubjobContainerPart) child);
}
}
CreateComponentOnLinkHelper.selectConnection(selectedConnectionPart);
} else {
if (selectedConnectionPart != null) {
CreateComponentOnLinkHelper.unselectConnection(selectedConnectionPart);
}
selectedConnectionPart = null;
}
}
}
use of org.eclipse.gef.editparts.ZoomManager in project dbeaver by dbeaver.
the class ERDEditorPart method configureGraphicalViewer.
@Override
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
this.getGraphicalViewer().getControl().setBackground(UIUtils.getColorRegistry().get(ERDConstants.COLOR_ERD_DIAGRAM_BACKGROUND));
GraphicalViewer graphicalViewer = getGraphicalViewer();
/*
MenuManager manager = new MenuManager(getClass().getName(), getClass().getName());
manager.setRemoveAllWhenShown(true);
getEditorSite().registerContextMenu(getClass().getName() + ".EditorContext", manager, graphicalViewer, true); //$NON-NLS-1$
*/
IPreferenceStore store = ERDActivator.getDefault().getPreferenceStore();
graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(store.getInt(ERDConstants.PREF_GRID_WIDTH), store.getInt(ERDConstants.PREF_GRID_HEIGHT)));
// initialize actions
createActions();
// Setup zoom manager
ZoomManager zoomManager = rootPart.getZoomManager();
List<String> zoomLevels = new ArrayList<>(3);
zoomLevels.add(ZoomManager.FIT_ALL);
zoomLevels.add(ZoomManager.FIT_WIDTH);
zoomLevels.add(ZoomManager.FIT_HEIGHT);
zoomManager.setZoomLevelContributions(zoomLevels);
zoomManager.setZoomLevels(new double[] { .1, .25, .5, .75, 1.0, 1.5, 2.0, 2.5, 3, 4 });
IAction zoomIn = new ZoomInAction(zoomManager);
IAction zoomOut = new ZoomOutAction(zoomManager);
addAction(zoomIn);
addAction(zoomOut);
graphicalViewer.addSelectionChangedListener(event -> {
String status;
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection.isEmpty()) {
status = "";
} else if (selection.size() == 1) {
status = CommonUtils.toString(selection.getFirstElement());
} else {
status = String.valueOf(selection.size()) + " objects";
}
progressControl.setInfo(status);
updateActions(editPartActionIDs);
});
}
use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.
the class WorkflowEditor method setZoomfactor.
private void setZoomfactor(final double z) {
ZoomManager zoomManager = this.getZoomManager();
zoomManager.setZoom(z);
}
use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.
the class WorkflowEditorDropTargetListener method getInsertLocation.
/**
* Computes the location of the new node and also determines if some node should be moved.
*
* A successor node is selected for the move action if the distance between this node and the successor is
* smaller than the {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE} and if they overlap vertically.
*
* @return point where the new node should be inserted and sets
* {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget}
*/
private Point getInsertLocation() {
ZoomManager zoomManager = (ZoomManager) getViewer().getProperty(ZoomManager.class.toString());
double zoom = zoomManager.getZoom();
int adjustedMinimumNodeDistance = (int) (MINIMUM_NODE_DISTANCE * zoom);
double adjustedMinimumNodeDistanceBeforeInsertion = MINIMUM_NODE_DISTANCE_BEFORE_INSERTION * zoom;
Point dropLocation = getDropLocation();
Point insertLocation = dropLocation;
int[] sourceBounds = null;
int[] targetBounds = null;
int sourceAnnotationHeight = 0;
int targetAnnotationHeight = 0;
EditPart source = m_edge.getSource().getParent();
EditPart target = m_edge.getTarget().getParent();
NodeContainerEditPart nextNode = null;
if (source instanceof WorkflowInPortBarEditPart && target instanceof NodeContainerEditPart) {
// metanode start --> first node in metanode
WorkflowInPortBarEditPart sourceBar = ((WorkflowInPortBarEditPart) source);
NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
Rectangle bounds = sourceBar.getFigure().getBounds();
org.eclipse.swt.graphics.Point p = getViewer().getControl().toControl(bounds.x, bounds.y);
sourceBounds = new int[] { p.x, p.y, bounds.width, bounds.height };
targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
nextNode = targetNode;
} else if (source instanceof NodeContainerEditPart && target instanceof WorkflowOutPortBarEditPart) {
// last node in metanode --> metanode end
NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
Rectangle bounds = targetBar.getFigure().getBounds();
targetBounds = new int[] { bounds.x, bounds.y, bounds.width, bounds.height };
sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
} else if (source instanceof WorkflowInPortBarEditPart && target instanceof WorkflowOutPortBarEditPart) {
// metanode start --> metanode end
WorkflowInPortBarEditPart sourceBar = (WorkflowInPortBarEditPart) source;
WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
sourceBounds = sourceBar.getNodeContainer().getUIInformation().getBounds();
targetBounds = targetBar.getNodeContainer().getUIInformation().getBounds();
} else if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
// node --> node
NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
nextNode = targetNode;
}
if (sourceBounds != null && targetBounds != null) {
sourceBounds = recomputeBounds(sourceBounds);
targetBounds = recomputeBounds(targetBounds);
if (0 <= targetBounds[0] - sourceBounds[0] && targetBounds[0] - sourceBounds[0] >= adjustedMinimumNodeDistanceBeforeInsertion) {
m_distanceToMoveTarget = 0;
} else {
m_distanceToMoveTarget = adjustedMinimumNodeDistance + (sourceBounds[0] + adjustedMinimumNodeDistance - targetBounds[0]);
m_distanceToMoveTarget = (int) (m_distanceToMoveTarget / zoom);
}
insertLocation = new Point(getXLocation(dropLocation.x, sourceBounds[0], zoom), getYLocation(dropLocation.y, sourceBounds[1], targetBounds[1], zoom));
if (WorkflowEditor.getActiveEditorSnapToGrid()) {
insertLocation = WorkflowEditor.getActiveEditorClosestGridLocation(insertLocation);
}
getViewer().getSelectionManager().deselectAll();
if (nextNode != null && selectSuccessor(sourceBounds[0], targetBounds[0], sourceBounds[1], sourceBounds[1] + sourceBounds[3] + sourceAnnotationHeight, targetBounds[1], targetBounds[1] + targetBounds[3] + targetAnnotationHeight, zoom)) {
selectNodes(nextNode, zoom);
}
}
return insertLocation;
}
use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.
the class AddAnnotationCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// adapt location to the viewport location and the zoom factor
// this seems to be a workaround for a bug in the framework
ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
// adjust the location according to the viewport position
// seems to be a workaround for a bug in the framework
// (should imediately deliver the correct view position and not
// the position of the viewport)
PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
WorkflowEditor.adaptZoom(zoomManager, location, true);
m_anno = new WorkflowAnnotation();
AnnotationData data = new AnnotationData();
// it is a workflow annotation
data.setBgColor(INITIAL_FLOWANNO_COLOR);
data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
data.setBorderColor(INITAL_FLOWBORDER_COLOR);
data.setText(INITIAL_FLOWANNO_TEXT);
data.setStyleRanges(new AnnotationData.StyleRange[0]);
m_anno.copyFrom(data, true);
WorkflowManager hostWFM = getHostWFM();
hostWFM.addWorkflowAnnotation(m_anno);
m_viewer.deselectAll();
// select the new ones....
if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
}
}
Aggregations