use of org.eclipse.gef.EditPart in project knime-core by knime.
the class PortGraphicalRoleEditPolicy method getConnectionCompleteCommand.
/**
* This tries to complete the command to create a connection.
*
* {@inheritDoc}
*/
@Override
protected Command getConnectionCompleteCommand(final CreateConnectionRequest request) {
// get the previously started command
CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
if (cmd == null) {
return null;
}
EditPart target = request.getTargetEditPart();
if ((target instanceof NodeOutPortEditPart) || target instanceof WorkflowInPortEditPart) {
return null;
} else if (target instanceof NodeInPortEditPart || target instanceof WorkflowOutPortEditPart) {
cmd.setTargetPortID(((AbstractPortEditPart) target).getIndex());
cmd.setTargetNode((ConnectableEditPart) target.getParent());
} else if (target instanceof NodeContainerEditPart) {
if (cmd.wasStartedOnOutPort()) {
cmd.setTargetPortID(-1);
cmd.setTargetNode((NodeContainerEditPart) target);
} else {
cmd.setSourcePortID(-1);
cmd.setSourceNode((NodeContainerEditPart) target);
}
} else {
return null;
}
return cmd;
}
use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.
the class RuntimePatchedSelectionTool method handleButtonUp.
/**
* Intercept middle clicks and restore original cursor if it has changed.
*/
@Override
protected boolean handleButtonUp(int button) {
if (button == 2) {
EditPart editPart = getTargetEditPart();
if (editPart instanceof AbstractPVWidgetEditPart) {
AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
IFigure figure = apvwep.getFigure();
if (cursorChanged) {
figure.setCursor(oldCursor);
oldCursor = null;
cursorChanged = false;
}
}
return true;
} else {
return super.handleButtonUp(button);
}
}
use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.
the class RuntimePatchedSelectionTool method handleButtonDown.
/**
* Intercept middle clicks and copy PV name to pastebuffer if available.
* Change cursor to copy symbol.
*/
@Override
protected boolean handleButtonDown(int button) {
if (button == 2) {
EditPart editPart = getTargetEditPart();
if (editPart instanceof AbstractPVWidgetEditPart) {
AbstractPVWidgetEditPart apvwep = (AbstractPVWidgetEditPart) editPart;
String pvName = ((AbstractPVWidgetModel) editPart.getModel()).getPVName();
if (pvName != "" && pvName != null) {
Display display = Display.getCurrent();
Clipboard clipboard = new Clipboard(display);
// Copies to middle button paste buffer,
// to be pasted via another middle-button click
clipboard.setContents(new Object[] { pvName }, new Transfer[] { TextTransfer.getInstance() }, DND.SELECTION_CLIPBOARD);
// Copies to normal clipboard,
// to be pasted via Ctrl-V or Edit/Paste
clipboard.setContents(new String[] { pvName }, new Transfer[] { TextTransfer.getInstance() });
clipboard.dispose();
IFigure figure = apvwep.getFigure();
oldCursor = figure.getCursor();
figure.setCursor(ResourceUtil.getCopyPvCursor());
cursorChanged = true;
}
}
return true;
} else {
return super.handleButtonDown(button);
}
}
use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.
the class AbstractContainerEditpart method registerBasePropertyChangeHandlers.
@Override
protected void registerBasePropertyChangeHandlers() {
super.registerBasePropertyChangeHandlers();
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
MacrosInput macrosInput = (MacrosInput) newValue;
LinkedHashMap<String, String> macrosMap = new LinkedHashMap<String, String>();
if (macrosInput.isInclude_parent_macros()) {
macrosMap.putAll(getWidgetModel().getParentMacroMap());
}
macrosMap.putAll(macrosInput.getMacrosMap());
getWidgetModel().setMacroMap(macrosMap);
return false;
}
};
setPropertyChangeHandler(AbstractContainerModel.PROP_MACROS, handler);
layout();
childrenPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getOldValue() instanceof Integer) {
addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
layout();
} else if (evt.getOldValue() instanceof AbstractWidgetModel) {
EditPart child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
if (child != null) {
removeChild(child);
layout();
}
} else
refreshChildren();
}
};
getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
selectionPropertyChangeListener = new PropertyChangeListener() {
@SuppressWarnings("unchecked")
@Override
public void propertyChange(PropertyChangeEvent evt) {
List<AbstractWidgetModel> widgets = (List<AbstractWidgetModel>) evt.getNewValue();
List<EditPart> widgetEditparts = new ArrayList<EditPart>();
for (AbstractWidgetModel w : widgets) {
EditPart e = (EditPart) getViewer().getEditPartRegistry().get(w);
if (e != null)
widgetEditparts.add(e);
}
if (!(Boolean) evt.getOldValue()) {
// append
getViewer().deselectAll();
}
for (EditPart editpart : widgetEditparts) {
if (editpart.isSelectable())
getViewer().appendSelection(editpart);
}
}
};
getWidgetModel().getSelectionProperty().addPropertyChangeListener(selectionPropertyChangeListener);
}
}
use of org.eclipse.gef.EditPart in project yamcs-studio by yamcs.
the class WidgetEditPartFactory method createEditPart.
@Override
public EditPart createEditPart(EditPart context, Object model) {
EditPart part = getPartForModel(model);
if (part != null) {
part.setModel(model);
if (part instanceof AbstractBaseEditPart) {
((AbstractBaseEditPart) part).setExecutionMode(executionMode);
((AbstractBaseEditPart) part).setSite(site);
} else if (part instanceof WidgetConnectionEditPart)
((WidgetConnectionEditPart) part).setExecutionMode(executionMode);
}
return part;
}
Aggregations