Search in sources :

Example 21 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addFrameWidgetHandler.

/**
     * Registers a listener that adjusts selection state in response to
     * widget additions or removals
     */
protected void addFrameWidgetHandler() {
    AlertHandler frameWidgetHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.WidgetChange chg = (Frame.WidgetChange) alert;
            IWidget chgWidget = chg.getChangeElement();
            if (chg != null) {
                // Check what action was performed
                switch(chg.action) {
                    // Switch the selection to the newly-added widget
                    case Frame.WidgetChange.ELEMENT_ADD:
                        {
                            GraphicalWidget<?> gw = frameUI.getWidgetFigure(chgWidget);
                            gw.addChangeHandler(widgetChangeHandler, Widget.WidgetChange.class);
                            gw.addChangeHandler(widgetChangeHandler, IAttributed.AttributeChange.class);
                            gw.addChangeHandler(widgetChangeHandler, IAttributed.AuthorityChange.class);
                            delayedWidgetSelection.addToSelection(chgWidget, gw);
                            view.requestRename();
                            break;
                        }
                    // Reflect the change in selection state
                    case Frame.WidgetChange.ELEMENT_DELETE:
                        {
                            // Cannot depend on the frameUI to have removed
                            // this widget's graphical version.
                            // Call deselect with the model itself.
                            selection.deselectElement(chgWidget);
                            delayedWidgetSelection.removeFromSelection(chgWidget);
                            // call to clean up any resize handles.
                            delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
                            break;
                        }
                }
            }
        }
    };
    frame.addHandler(this, Frame.WidgetChange.class, frameWidgetHandler);
    AlertHandler frameEltHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
        }
    };
    // Do the above for both widget and association changes!
    frame.addHandler(this, Frame.ElementChange.class, frameEltHandler);
    AlertHandler frameAssocHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.FrameEltGrpChange chg = (Frame.FrameEltGrpChange) alert;
            if (chg.action == Frame.FrameEltGrpChange.ELEMENT_DELETE) {
                selection.deselectElement(chg.getChangeElement());
            } else if (chg.action == Frame.FrameEltGrpChange.ELEMENT_ADD) {
                selection.setSelectedSelnFig(uiModel.getGroupHalo(chg.getChangeElement()));
            }
        }
    };
    frame.addHandler(this, Frame.FrameEltGrpChange.class, frameAssocHandler);
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) EventObject(java.util.EventObject) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventObject (java.util.EventObject)21 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)3 Set (java.util.Set)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)2 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)2 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)2 PERTChartSelectionState (edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 StructureViewUIModel (edu.cmu.cs.hcii.cogtool.uimodel.StructureViewUIModel)2 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)2 ActionPropertySet (edu.cmu.cs.hcii.cogtool.view.ActionPropertySet)2 SWTList (edu.cmu.cs.hcii.cogtool.view.SWTList)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2