use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart 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.AbstractBaseEditPart 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.AbstractBaseEditPart 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.AbstractBaseEditPart 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);
}
use of org.csstudio.opibuilder.editparts.AbstractBaseEditPart in project yamcs-studio by yamcs.
the class ChangeOrderAction method fillWidgetMap.
/**
* @param widgetMap
*/
private void fillWidgetMap(Map<AbstractContainerModel, List<IndexedWidget>> widgetMap) {
for (Object selection : getSelectedObjects()) {
if (selection instanceof AbstractBaseEditPart) {
AbstractBaseEditPart widgetEditpart = (AbstractBaseEditPart) selection;
AbstractWidgetModel widgetModel = (AbstractWidgetModel) widgetEditpart.getModel();
if (widgetEditpart.getParent() != null && widgetModel.getParent() != null) {
AbstractContainerModel containerModel = (AbstractContainerModel) widgetEditpart.getParent().getModel();
if (!widgetMap.containsKey(containerModel)) {
widgetMap.put(containerModel, new LinkedList<IndexedWidget>());
}
widgetMap.get(containerModel).add(new IndexedWidget(containerModel.getIndexOf(widgetModel), widgetModel));
}
}
}
}
Aggregations