Search in sources :

Example 6 with AbstractBaseEditPart

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;
}
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 7 with AbstractBaseEditPart

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

Example 8 with AbstractBaseEditPart

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;
}
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 9 with AbstractBaseEditPart

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);
}
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)

Example 10 with AbstractBaseEditPart

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

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)16 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)8 ArrayList (java.util.ArrayList)6 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 GraphicalViewer (org.eclipse.gef.GraphicalViewer)4 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PointList (org.eclipse.draw2d.geometry.PointList)3 EditPart (org.eclipse.gef.EditPart)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 EventObject (java.util.EventObject)2 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)2 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2