use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class OPIRunnerContextMenuProvider method addWidgetActionToMenu.
/**
* Adds the defined {@link AbstractWidgetAction}s to the given {@link IMenuManager}.
*
* @param menu
* The {@link IMenuManager}
*/
private void addWidgetActionToMenu(final IMenuManager menu) {
List<?> selectedEditParts = ((IStructuredSelection) getViewer().getSelection()).toList();
if (selectedEditParts.size() == 1) {
if (selectedEditParts.get(0) instanceof AbstractBaseEditPart) {
AbstractBaseEditPart editPart = (AbstractBaseEditPart) selectedEditParts.get(0);
AbstractWidgetModel widget = editPart.getWidgetModel();
// add menu Open, Open in New Tab and Open in New Window
List<AbstractWidgetAction> hookedActions = editPart.getHookedActions();
if (hookedActions != null && hookedActions.size() == 1) {
AbstractWidgetAction hookedAction = hookedActions.get(0);
if (hookedAction instanceof OpenDisplayAction) {
final OpenDisplayAction original_action = (OpenDisplayAction) hookedAction;
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.DEFAULT));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_TAB));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_WINDOW));
menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_SHELL));
}
}
ActionsInput ai = widget.getActionsInput();
if (ai != null) {
List<AbstractWidgetAction> widgetActions = ai.getActionsList();
if (!widgetActions.isEmpty()) {
MenuManager actionMenu = new MenuManager("Actions", "actions");
for (AbstractWidgetAction action : widgetActions) {
actionMenu.add(new WidgetActionMenuAction(action));
}
menu.add(actionMenu);
}
}
}
}
}
use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class OPIRunnerContextMenuProvider method addSettingPropertiesAction.
private void addSettingPropertiesAction(final IMenuManager menu) {
List<?> selectedEditParts = ((IStructuredSelection) getViewer().getSelection()).toList();
if (selectedEditParts.size() == 1) {
if (selectedEditParts.get(0) instanceof AbstractBaseEditPart) {
AbstractBaseEditPart editPart = (AbstractBaseEditPart) selectedEditParts.get(0);
AbstractWidgetModel widget = editPart.getWidgetModel();
if (widget.getRuntimePropertyList() != null) {
menu.add(new ConfigureRuntimePropertiesAction(getViewer().getControl().getShell(), widget));
}
}
}
}
use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method createChangeConstraintCommand.
@Override
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
return super.createChangeConstraintCommand(request, child, constraint);
AbstractBaseEditPart part = (AbstractBaseEditPart) child;
AbstractWidgetModel widgetModel = part.getWidgetModel();
IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(widgetModel.getTypeID());
Command cmd = null;
if (feedbackFactory != null)
cmd = feedbackFactory.createChangeBoundsCommand(widgetModel, request, (Rectangle) constraint);
if (cmd == null)
cmd = new WidgetSetConstraintCommand(widgetModel, request, (Rectangle) constraint);
List<ConnectionModel> allConnections = new ArrayList<ConnectionModel>(part.getWidgetModel().getSourceConnections());
allConnections.addAll(part.getWidgetModel().getTargetConnections());
if (part.getWidgetModel() instanceof AbstractContainerModel) {
for (AbstractWidgetModel d : ((AbstractContainerModel) part.getWidgetModel()).getAllDescendants()) {
allConnections.addAll(d.getSourceConnections());
allConnections.addAll(d.getTargetConnections());
}
}
if (allConnections.size() > 0) {
CompoundCommand reRouteCmd = new CompoundCommand();
for (ConnectionModel srcConn : allConnections) {
reRouteCmd.add(new SetWidgetPropertyCommand(srcConn, ConnectionModel.PROP_POINTS, new PointList()));
}
cmd = cmd.chain(reRouteCmd);
}
if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
} else if (GuideUtil.getInstance().getGuide(widgetModel, true) != null) {
// SnapToGuides didn't provide a horizontal guide, but
// this part is attached
// to a horizontal guide. Now we check to see if the
// part is attached to
// the guide along the edge being resized. If that is
// the case, we need to
// detach the part from the guide; otherwise, we leave
// it alone.
int alignment = GuideUtil.getInstance().getGuide(widgetModel, true).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, true));
}
}
}
if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
} else if (GuideUtil.getInstance().getGuide(widgetModel, false) != null) {
int alignment = GuideUtil.getInstance().getGuide(widgetModel, false).getAlignment(widgetModel);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
cmd = cmd.chain(new ChangeGuideCommand(widgetModel, false));
}
}
}
if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
cmd = chainGuideAttachmentCommand(request, part, cmd, true);
cmd = chainGuideAttachmentCommand(request, part, cmd, false);
cmd = chainGuideDetachmentCommand(request, part, cmd, true);
cmd = chainGuideDetachmentCommand(request, part, cmd, false);
}
return cmd;
}
use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method getCloneCommand.
@SuppressWarnings("deprecation")
@Override
protected Command getCloneCommand(ChangeBoundsRequest request) {
CloneCommand clone = new CloneCommand((AbstractContainerModel) getHost().getModel());
for (AbstractBaseEditPart part : sortSelectedWidgets(request.getEditParts())) {
clone.addPart((AbstractWidgetModel) part.getModel(), (Rectangle) getConstraintForClone(part, request));
}
// Attach to horizontal guide, if one is given
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
if (guidePos != null) {
int hAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_ANCHOR)).intValue();
clone.setGuide(findGuideAt(guidePos.intValue(), true), hAlignment, true);
}
// Attach to vertical guide, if one is given
guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
int vAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue();
clone.setGuide(findGuideAt(guidePos.intValue(), false), vAlignment, false);
}
return clone;
}
use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class WidgetXYLayoutEditPolicy method sortSelectedWidgets.
/**
* Sort the selected widget as they were in their parents
*
* @return a list with all widget editpart that are currently selected
*/
private final List<AbstractBaseEditPart> sortSelectedWidgets(List<?> selection) {
List<AbstractBaseEditPart> sameParentWidgets = new ArrayList<AbstractBaseEditPart>();
List<AbstractBaseEditPart> differentParentWidgets = new ArrayList<AbstractBaseEditPart>();
List<AbstractBaseEditPart> result = new ArrayList<AbstractBaseEditPart>();
AbstractContainerModel parent = null;
for (Object o : selection) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentWidgets.add((AbstractBaseEditPart) o);
else
differentParentWidgets.add((AbstractBaseEditPart) o);
}
}
// sort widgets to its original order
if (sameParentWidgets.size() > 1) {
AbstractBaseEditPart[] modelArray = sameParentWidgets.toArray(new AbstractBaseEditPart[0]);
Arrays.sort(modelArray, new Comparator<AbstractBaseEditPart>() {
@Override
public int compare(AbstractBaseEditPart o1, AbstractBaseEditPart o2) {
if (o1.getWidgetModel().getParent().getChildren().indexOf(o1.getWidgetModel()) > o2.getWidgetModel().getParent().getChildren().indexOf(o2.getWidgetModel()))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentWidgets.size() > 0)
result.addAll(differentParentWidgets);
return result;
}
if (differentParentWidgets.size() > 0)
sameParentWidgets.addAll(differentParentWidgets);
return sameParentWidgets;
}
Aggregations