use of org.csstudio.opibuilder.editparts.DisplayEditpart 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;
}
use of org.csstudio.opibuilder.editparts.DisplayEditpart in project yamcs-studio by yamcs.
the class CopyWidgetsAction method getSelectedWidgetModels.
/**
* Gets the widget models of all currently selected EditParts.
*
* @return a list with all widget models that are currently selected.
* The order of the selected widgets was kept.
*/
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
List<?> selection = getSelectedObjects();
List<AbstractWidgetModel> sameParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
AbstractContainerModel parent = null;
for (Object o : selection) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = (AbstractWidgetModel) ((EditPart) o).getModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentModels.add(widgetModel);
else
differentParentModels.add(widgetModel);
}
}
// sort widgets to its original order
if (sameParentModels.size() > 1) {
AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {
@Override
public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentModels.size() > 0)
result.addAll(differentParentModels);
return result;
}
if (differentParentModels.size() > 0)
sameParentModels.addAll(differentParentModels);
return sameParentModels;
}
use of org.csstudio.opibuilder.editparts.DisplayEditpart in project yamcs-studio by yamcs.
the class OPIEditor method updateStatusLine.
private void updateStatusLine(IStatusLineManager statusLine) {
List<AbstractBaseEditPart> selectedWidgets = new ArrayList<>();
for (Object editpart : getGraphicalViewer().getSelectedEditParts()) {
if (editpart instanceof AbstractBaseEditPart && !(editpart instanceof DisplayEditpart))
selectedWidgets.add((AbstractBaseEditPart) editpart);
}
if (selectedWidgets.size() == 1)
statusLine.setMessage(// $NON-NLS-1$
selectedWidgets.get(0).getWidgetModel().getName() + "(" + selectedWidgets.get(0).getWidgetModel().getType() + // $NON-NLS-1$
")");
else if (selectedWidgets.size() >= 1)
statusLine.setMessage(selectedWidgets.size() + " widgets were selected");
else
statusLine.setMessage("No widget was selected");
}
use of org.csstudio.opibuilder.editparts.DisplayEditpart in project yamcs-studio by yamcs.
the class CreateGroupAction method getSelectedWidgetModels.
// /**
// * Gets the widget models of all currently selected EditParts.
// *
// * @return a list with all widget models that are currently selected
// */
// protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
//
// List<AbstractWidgetModel> selectedWidgetModels = new ArrayList<AbstractWidgetModel>();
//
// for (Object o : selection.toList()) {
// if (o instanceof AbstractBaseEditPart) {
// selectedWidgetModels.add(((AbstractBaseEditPart) o)
// .getWidgetModel());
// }
// }
// return selectedWidgetModels;
// }
//
/**
* Gets the widget models of all currently selected EditParts.
*
* @return a list with all widget models that are currently selected.
* The order of the selected widgets was kept.
*/
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
// List selection = getSelectedObjects();
List<AbstractWidgetModel> sameParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
AbstractContainerModel parent = null;
for (Object o : selection.toList()) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentModels.add(widgetModel);
else
differentParentModels.add(widgetModel);
}
}
// sort widgets to its original order
if (sameParentModels.size() > 1) {
AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {
@Override
public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentModels.size() > 0)
result.addAll(differentParentModels);
return result;
}
if (differentParentModels.size() > 0)
sameParentModels.addAll(differentParentModels);
return sameParentModels;
}
use of org.csstudio.opibuilder.editparts.DisplayEditpart in project yamcs-studio by yamcs.
the class FillParentContainerAction method run.
@Override
public void run(IAction action) {
AbstractBaseEditPart widget = (AbstractBaseEditPart) selection.getFirstElement();
AbstractContainerEditpart containerEditpart = getParentContainerEditpart();
Dimension size = null;
if (containerEditpart instanceof DisplayEditpart)
size = ((DisplayEditpart) containerEditpart).getWidgetModel().getSize();
else
size = containerEditpart.getFigure().getClientArea().getSize();
Command cmd = new SetBoundsCommand(widget.getWidgetModel(), new Rectangle(0, 0, size.width, size.height));
execute(cmd);
}
Aggregations