Search in sources :

Example 1 with KeyStroke

use of org.eclipse.scout.rt.client.ui.action.keystroke.KeyStroke in project scout.rt by eclipse.

the class AbstractTable method initConfig.

protected void initConfig() {
    m_eventHistory = createEventHistory();
    m_eventBuffer = createEventBuffer();
    m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(createUIFacade(), ModelContext.copyCurrent());
    m_contributionHolder = new ContributionComposite(this);
    setEnabled(true);
    setLoading(false);
    setGroupingStyle(getConfiguredGroupingStyle());
    setTitle(getConfiguredTitle());
    setAutoDiscardOnDelete(getConfiguredAutoDiscardOnDelete());
    setSortEnabled(getConfiguredSortEnabled());
    setDefaultIconId(getConfiguredDefaultIconId());
    setCssClass((getConfiguredCssClass()));
    setRowIconVisible(getConfiguredRowIconVisible());
    setHeaderVisible(getConfiguredHeaderVisible());
    setHeaderEnabled(getConfiguredHeaderEnabled());
    setAutoResizeColumns(getConfiguredAutoResizeColumns());
    setCheckable(getConfiguredCheckable());
    setMultiCheck(getConfiguredMultiCheck());
    setMultiSelect(getConfiguredMultiSelect());
    setInitialMultilineText(getConfiguredMultilineText());
    setMultilineText(getConfiguredMultilineText());
    setKeyboardNavigation(getConfiguredKeyboardNavigation());
    setDragType(getConfiguredDragType());
    setDropType(getConfiguredDropType());
    setDropMaximumSize(getConfiguredDropMaximumSize());
    setScrollToSelection(getConfiguredScrollToSelection());
    setTableStatusVisible(getConfiguredTableStatusVisible());
    if (getTableCustomizer() == null) {
        setTableCustomizer(createTableCustomizer());
    }
    // columns
    createColumnsInternal();
    // table controls
    createTableControlsInternal();
    // menus
    initMenus();
    // key strokes
    List<Class<? extends IKeyStroke>> ksClasses = getConfiguredKeyStrokes();
    List<IKeyStroke> ksList = new ArrayList<IKeyStroke>(ksClasses.size());
    for (Class<? extends IKeyStroke> clazz : ksClasses) {
        IKeyStroke ks = ConfigurationUtility.newInnerInstance(this, clazz);
        ks.initAction();
        if (ks.getKeyStroke() != null) {
            ksList.add(ks);
        }
    }
    // add ENTER key stroke when default menu is used or execRowAction has an override
    Class<? extends IMenu> defaultMenuType = getDefaultMenuInternal();
    if (defaultMenuType != null || ConfigurationUtility.isMethodOverwrite(AbstractTable.class, "execRowAction", new Class[] { ITableRow.class }, this.getClass())) {
        ksList.add(new KeyStroke("ENTER") {

            @Override
            protected void execAction() {
                fireRowAction(getSelectedRow());
            }
        });
    }
    // add keystroke contributions
    List<IKeyStroke> contributedKeyStrokes = m_contributionHolder.getContributionsByClass(IKeyStroke.class);
    ksList.addAll(contributedKeyStrokes);
    setKeyStrokes(ksList);
    m_tableOrganizer = BEANS.get(ITableOrganizerProvider.class).createTableOrganizer(this);
    // add Convenience observer for drag & drop callbacks, event history and ui sort possible check
    addTableListener(new TableAdapter() {

        @Override
        public void tableChanged(TableEvent e) {
            // event history
            IEventHistory<TableEvent> h = getEventHistory();
            if (h != null) {
                h.notifyEvent(e);
            }
            // dnd
            switch(e.getType()) {
                case TableEvent.TYPE_ROWS_DRAG_REQUEST:
                    {
                        if (e.getDragObject() == null) {
                            try {
                                e.setDragObject(interceptDrag(e.getRows()));
                            } catch (RuntimeException ex) {
                                BEANS.get(ExceptionHandler.class).handle(ex);
                            }
                        }
                        break;
                    }
                case TableEvent.TYPE_ROW_DROP_ACTION:
                    {
                        if (e.getDropObject() != null && isEnabled()) {
                            try {
                                interceptDrop(e.getFirstRow(), e.getDropObject());
                            } catch (RuntimeException ex) {
                                BEANS.get(ExceptionHandler.class).handle(ex);
                            }
                        }
                        break;
                    }
                case TableEvent.TYPE_ROWS_COPY_REQUEST:
                    {
                        if (e.getCopyObject() == null) {
                            try {
                                e.setCopyObject(interceptCopy(e.getRows()));
                            } catch (RuntimeException ex) {
                                BEANS.get(ExceptionHandler.class).handle(ex);
                            }
                        }
                        break;
                    }
                case TableEvent.TYPE_ALL_ROWS_DELETED:
                case TableEvent.TYPE_ROWS_DELETED:
                case TableEvent.TYPE_ROWS_INSERTED:
                case TableEvent.TYPE_ROWS_UPDATED:
                    {
                        if (isValueChangeTriggerEnabled()) {
                            try {
                                interceptContentChanged();
                            } catch (RuntimeException ex) {
                                BEANS.get(ExceptionHandler.class).handle(ex);
                            }
                        }
                        break;
                    }
                case TableEvent.TYPE_ROWS_CHECKED:
                    try {
                        interceptRowsChecked(e.getRows());
                    } catch (RuntimeException ex) {
                        BEANS.get(ExceptionHandler.class).handle(ex);
                    }
                    break;
                case TableEvent.TYPE_COLUMN_HEADERS_UPDATED:
                case TableEvent.TYPE_COLUMN_STRUCTURE_CHANGED:
                    checkIfColumnPreventsUiSortForTable();
                    break;
            }
        }
    });
}
Also used : ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) ArrayList(java.util.ArrayList) IEventHistory(org.eclipse.scout.rt.client.ui.IEventHistory) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) ExceptionHandler(org.eclipse.scout.rt.platform.exception.ExceptionHandler) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) KeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.KeyStroke)

Example 2 with KeyStroke

use of org.eclipse.scout.rt.client.ui.action.keystroke.KeyStroke in project scout.rt by eclipse.

the class AbstractTree method initConfig.

protected void initConfig() {
    // default enabled
    m_enabled = NamedBitMaskHelper.ALL_BITS_SET;
    m_eventHistory = createEventHistory();
    m_eventBuffer = createEventBuffer();
    m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(createUIFacade(), ModelContext.copyCurrent());
    m_contributionHolder = new ContributionComposite(this);
    setEnabled(true);
    setTitle(getConfiguredTitle());
    setIconId(getConfiguredIconId());
    setDefaultIconId(getConfiguredDefaultIconId());
    setCssClass(getConfiguredCssClass());
    setAutoTitle(getConfiguredAutoTitle());
    setCheckable(getConfiguredCheckable());
    setNodeHeightHint(getConfiguredNodeHeightHint());
    setMultiCheck(getConfiguredMultiCheck());
    setMultiSelect(getConfiguredMultiSelect());
    setAutoDiscardOnDelete(getConfiguredAutoDiscardOnDelete());
    setDragEnabled(getConfiguredDragEnabled());
    setDragType(getConfiguredDragType());
    setDropType(getConfiguredDropType());
    setDropMaximumSize(getConfiguredDropMaximumSize());
    setRootNodeVisible(getConfiguredRootNodeVisible());
    setRootHandlesVisible(getConfiguredRootHandlesVisible());
    setScrollToSelection(getConfiguredScrollToSelection());
    setSaveAndRestoreScrollbars(getConfiguredSaveAndRestoreScrollbars());
    setAutoCheckChildNodes(getConfiguredAutoCheckChildNodes());
    setLazyExpandingEnabled(getConfiguredLazyExpandingEnabled());
    setDisplayStyle(getConfiguredDisplayStyle());
    setToggleBreadcrumbStyleEnabled(getConfiguredToggleBreadcrumbStyleEnabled());
    setRootNode(new AbstractTreeNode() {
    });
    // add Convenience observer for drag & drop callbacks and event history
    addTreeListener(new TreeAdapter() {

        @Override
        public void treeChanged(TreeEvent e) {
            // event history
            IEventHistory<TreeEvent> h = getEventHistory();
            if (h != null) {
                h.notifyEvent(e);
            }
            // dnd
            switch(e.getType()) {
                case TreeEvent.TYPE_NODES_DRAG_REQUEST:
                    {
                        m_lastSeenDropNode = null;
                        if (e.getDragObject() == null) {
                            try {
                                TransferObject transferObject = interceptDrag(e.getNode());
                                if (transferObject == null) {
                                    transferObject = interceptDrag(e.getNodes());
                                }
                                e.setDragObject(transferObject);
                            } catch (Exception t) {
                                LOG.error("Drag", t);
                            }
                        }
                        break;
                    }
                case TreeEvent.TYPE_NODE_DROP_ACTION:
                    {
                        m_lastSeenDropNode = null;
                        if (e.getDropObject() != null) {
                            try {
                                interceptDrop(e.getNode(), e.getDropObject());
                            } catch (Exception t) {
                                LOG.error("Drop", t);
                            }
                        }
                        break;
                    }
                case TreeEvent.TYPE_NODES_SELECTED:
                    {
                        rebuildKeyStrokesInternal();
                        break;
                    }
                case TreeEvent.TYPE_NODES_CHECKED:
                    {
                        try {
                            interceptNodesChecked(CollectionUtility.arrayList(e.getNodes()));
                        } catch (RuntimeException ex) {
                            BEANS.get(ExceptionHandler.class).handle(ex);
                        }
                        break;
                    }
                case TreeEvent.TYPE_NODE_DROP_TARGET_CHANGED:
                    {
                        try {
                            if (m_lastSeenDropNode == null || m_lastSeenDropNode != e.getNode()) {
                                m_lastSeenDropNode = e.getNode();
                                interceptDropTargetChanged(e.getNode());
                            }
                        } catch (RuntimeException ex) {
                            LOG.error("DropTargetChanged", ex);
                        }
                        break;
                    }
                case TreeEvent.TYPE_DRAG_FINISHED:
                    {
                        m_lastSeenDropNode = null;
                    }
            }
        }
    });
    // key shortcuts
    List<Class<? extends IKeyStroke>> configuredKeyStrokes = getConfiguredKeyStrokes();
    List<IKeyStroke> ksList = new ArrayList<IKeyStroke>(configuredKeyStrokes.size());
    for (Class<? extends IKeyStroke> keystrokeClazz : configuredKeyStrokes) {
        ksList.add(ConfigurationUtility.newInnerInstance(this, keystrokeClazz));
    }
    // ticket 87370: add ENTER key stroke when execNodeAction has an override
    if (ConfigurationUtility.isMethodOverwrite(AbstractTree.class, "execNodeAction", new Class[] { ITreeNode.class }, this.getClass())) {
        ksList.add(new KeyStroke("ENTER") {

            @Override
            protected void execAction() {
                fireNodeAction(getSelectedNode());
            }
        });
    }
    List<IKeyStroke> contributedKeyStrokes = m_contributionHolder.getContributionsByClass(IKeyStroke.class);
    contributedKeyStrokes.addAll(contributedKeyStrokes);
    m_baseKeyStrokes = ksList;
    setKeyStrokesInternal(m_baseKeyStrokes);
    // menus
    List<Class<? extends IMenu>> declaredMenus = getDeclaredMenus();
    List<IMenu> contributedMenus = m_contributionHolder.getContributionsByClass(IMenu.class);
    OrderedCollection<IMenu> menus = new OrderedCollection<IMenu>();
    for (Class<? extends IMenu> menuClazz : declaredMenus) {
        IMenu menu = ConfigurationUtility.newInnerInstance(this, menuClazz);
        menus.addOrdered(menu);
    }
    try {
        injectMenusInternal(menus);
    } catch (Exception e) {
        LOG.error("Error occured while dynamically contributing menus.", e);
    }
    menus.addAllOrdered(contributedMenus);
    new MoveActionNodesHandler<IMenu>(menus).moveModelObjects();
    TreeContextMenu contextMenu = new TreeContextMenu(this, menus.getOrderedList());
    setContextMenuInternal(contextMenu);
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) ArrayList(java.util.ArrayList) IEventHistory(org.eclipse.scout.rt.client.ui.IEventHistory) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) TransferObject(org.eclipse.scout.rt.client.ui.dnd.TransferObject) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) KeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.KeyStroke) TreeContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.internal.TreeContextMenu) ITreeContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ITreeContextMenu)

Aggregations

ArrayList (java.util.ArrayList)2 IEventHistory (org.eclipse.scout.rt.client.ui.IEventHistory)2 IKeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)2 KeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.KeyStroke)2 ContributionComposite (org.eclipse.scout.rt.shared.extension.ContributionComposite)2 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 ITreeContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.ITreeContextMenu)1 TreeContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.internal.TreeContextMenu)1 TransferObject (org.eclipse.scout.rt.client.ui.dnd.TransferObject)1 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)1 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)1