Search in sources :

Example 1 with DisplayEditpart

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;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 2 with DisplayEditpart

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;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 3 with DisplayEditpart

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");
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) EventObject(java.util.EventObject) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 4 with DisplayEditpart

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;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 5 with DisplayEditpart

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);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Command(org.eclipse.gef.commands.Command) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Dimension(org.eclipse.draw2d.geometry.Dimension) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)6 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)6 ArrayList (java.util.ArrayList)4 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)3 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)3 EventObject (java.util.EventObject)1 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)1 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 Command (org.eclipse.gef.commands.Command)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1