Search in sources :

Example 1 with IGraphicalFeedbackFactory

use of org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method showSizeOnDropFeedback.

@Override
protected void showSizeOnDropFeedback(CreateRequest request) {
    String typeId = determineTypeIdFromRequest(request);
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
    if (feedbackFactory != null) {
        IFigure feedbackFigure = getSizeOnDropFeedback(request);
        feedbackFactory.showSizeOnDropFeedback(request, feedbackFigure, getCreationFeedbackOffset(request));
    // feedbackFigure.repaint();
    } else {
        super.showSizeOnDropFeedback(request);
    }
}
Also used : IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with IGraphicalFeedbackFactory

use of org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory 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;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ArrayList(java.util.ArrayList) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand)

Example 3 with IGraphicalFeedbackFactory

use of org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method getCreateCommand.

@Override
protected Command getCreateCommand(CreateRequest request) {
    String typeId = determineTypeIdFromRequest(request);
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
    Command widgetCreateCommand = createWidgetCreateCommand(request);
    if (widgetCreateCommand == null)
        return null;
    if (feedbackFactory != null) {
        CompoundCommand compoundCommand = new CompoundCommand();
        compoundCommand.add(widgetCreateCommand);
        Command initialBoundsCommand = feedbackFactory.createInitialBoundsCommand((AbstractWidgetModel) request.getNewObject(), request, (Rectangle) getConstraintFor(request));
        if (initialBoundsCommand != null)
            compoundCommand.add(initialBoundsCommand);
        return compoundCommand;
    } else
        return widgetCreateCommand;
}
Also used : WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 4 with IGraphicalFeedbackFactory

use of org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method createSizeOnDropFeedback.

/**
 * Override to provide custom feedback figure for the given create request.
 *
 * @param request
 *            the create request
 * @return custom feedback figure
 */
@Override
protected IFigure createSizeOnDropFeedback(final CreateRequest request) {
    String typeId = determineTypeIdFromRequest(request);
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
    if (feedbackFactory != null) {
        Shape feedbackFigure = feedbackFactory.createSizeOnDropFeedback(request);
        if (feedbackFigure != null) {
            addFeedback(feedbackFigure);
            return feedbackFigure;
        }
    }
    return super.createSizeOnDropFeedback(request);
}
Also used : Shape(org.eclipse.draw2d.Shape) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)

Example 5 with IGraphicalFeedbackFactory

use of org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory in project yamcs-studio by yamcs.

the class OPIEditorPaletteFactory method createPaletteContents.

private static void createPaletteContents(PaletteRoot palette) {
    Map<String, List<String>> categoriesMap = WidgetsService.getInstance().getAllCategoriesMap();
    String[] hiddenWidgets = PreferencesHelper.getHiddenWidgets();
    List<String> hiddenWidgetsList = null;
    if (hiddenWidgets != null)
        hiddenWidgetsList = Arrays.asList(hiddenWidgets);
    for (final Map.Entry<String, List<String>> entry : categoriesMap.entrySet()) {
        PaletteDrawer categoryDrawer = new PaletteDrawer(entry.getKey());
        for (String typeId : entry.getValue()) {
            if (hiddenWidgetsList != null && hiddenWidgetsList.indexOf(typeId) >= 0)
                continue;
            WidgetDescriptor widgetDescriptor = WidgetsService.getInstance().getWidgetDescriptor(typeId);
            ImageDescriptor icon = CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(widgetDescriptor.getPluginId(), widgetDescriptor.getIconPath());
            CombinedTemplateCreationEntry widgetEntry = new CombinedTemplateCreationEntry(widgetDescriptor.getName(), widgetDescriptor.getDescription(), new WidgetCreationFactory(widgetDescriptor), icon, icon);
            IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(widgetDescriptor.getTypeID());
            if (feedbackFactory != null && feedbackFactory.getCreationTool() != null) {
                widgetEntry.setToolClass(feedbackFactory.getCreationTool());
            }
            categoryDrawer.add(widgetEntry);
        }
        palette.add(categoryDrawer);
    }
}
Also used : WidgetDescriptor(org.csstudio.opibuilder.util.WidgetDescriptor) PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) List(java.util.List) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Map(java.util.Map) CombinedTemplateCreationEntry(org.eclipse.gef.palette.CombinedTemplateCreationEntry)

Aggregations

IGraphicalFeedbackFactory (org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)5 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)2 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)2 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)1 WidgetDescriptor (org.csstudio.opibuilder.util.WidgetDescriptor)1 IFigure (org.eclipse.draw2d.IFigure)1 Shape (org.eclipse.draw2d.Shape)1 PointList (org.eclipse.draw2d.geometry.PointList)1