Search in sources :

Example 21 with ControlListener

use of org.eclipse.swt.events.ControlListener in project rap by entirej.

the class EJRWTMultiRecordBlockRenderer method buildGuiComponent.

@Override
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {
    EJFrameworkExtensionProperties appProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
    if (appProp != null) {
        EJFrameworkExtensionProperties propertyGroup = appProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
        if (propertyGroup != null) {
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_QUERY_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_INSERT_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_UPDATE_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_DELETE_KEY);
            addActionKeyinfo(propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY), EJRWTSingleRecordBlockDefinitionProperties.ACTION_REFRESH_KEY);
        }
    }
    EJBlockProperties blockProperties = _block.getProperties();
    EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.widthHint = mainScreenProperties.getWidth();
    gridData.heightHint = mainScreenProperties.getHeight();
    gridData.horizontalSpan = mainScreenProperties.getHorizontalSpan();
    gridData.verticalSpan = mainScreenProperties.getVerticalSpan();
    gridData.grabExcessHorizontalSpace = mainScreenProperties.canExpandHorizontally();
    gridData.grabExcessVerticalSpace = mainScreenProperties.canExpandVertically();
    if (gridData.grabExcessHorizontalSpace) {
        gridData.minimumWidth = mainScreenProperties.getWidth();
    }
    if (gridData.grabExcessVerticalSpace) {
        gridData.minimumHeight = mainScreenProperties.getHeight();
    }
    EJFrameworkExtensionProperties rendererProp = blockProperties.getBlockRendererProperties();
    blockCanvas.setLayoutData(gridData);
    EJFrameworkExtensionProperties sectionProperties = null;
    if (rendererProp != null) {
        sectionProperties = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR);
    }
    if (sectionProperties != null && sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP.equals(sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
        int style = ExpandableComposite.TITLE_BAR;
        String mode = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE);
        if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TWISTIE.equals(mode)) {
            style = style | ExpandableComposite.TWISTIE;
        } else if (EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_TREE_NODE.equals(mode)) {
            style = style | ExpandableComposite.TREE_NODE;
        }
        if (sectionProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
            style = style | ExpandableComposite.EXPANDED;
        }
        Section section = toolkit.createSection(blockCanvas, style);
        section.setLayoutData(gridData);
        String title = sectionProperties.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_TITLE);
        if (title != null) {
            section.setText(title);
        }
        String frameTitle = mainScreenProperties.getFrameTitle();
        EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(section, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setLayoutData(gridData);
            if (!mainScreenProperties.getDisplayFrame())
                _mainPane.cleanLayoutHorizontal();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            section.setClient(_mainPane);
        }
        final EJFrameworkExtensionPropertyList propertyList = sectionProperties.getPropertyList(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTIONS);
        if (propertyList != null && propertyList.getAllListEntries().size() > 0) {
            ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
            final ToolBar toolbar = toolBarManager.createControl(section);
            final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
            toolbar.setCursor(handCursor);
            // Cursor needs to be explicitly disposed
            toolbar.addDisposeListener(new DisposeListener() {

                @Override
                public void widgetDisposed(DisposeEvent e) {
                    if (handCursor != null && handCursor.isDisposed() == false) {
                        handCursor.dispose();
                    }
                }
            });
            List<EJFrameworkExtensionPropertyListEntry> allListEntries = propertyList.getAllListEntries();
            for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
                final String actionID = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_ID);
                String actionImage = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_IMAGE);
                String actionName = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_NAME);
                String actionTooltip = entry.getProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_ACTION_TOOLTIP);
                if (actionID != null) {
                    Action action = new Action(actionID, IAction.AS_PUSH_BUTTON) {

                        @Override
                        public void runWithEvent(Event event) {
                            _block.executeActionCommand(actionID, EJScreenType.MAIN);
                        }
                    };
                    if (actionName != null) {
                        action.setText(actionName);
                    }
                    if (actionTooltip != null) {
                        action.setDescription(actionTooltip);
                    }
                    if (actionImage != null && actionImage.length() > 0) {
                        action.setImageDescriptor((EJRWTImageRetriever.createDescriptor(actionImage)));
                    }
                    toolBarManager.add(action);
                }
            }
            toolBarManager.update(true);
            section.setTextClient(toolbar);
        }
    } else {
        String frameTitle = mainScreenProperties.getFrameTitle();
        if (mainScreenProperties.getDisplayFrame() && frameTitle != null && frameTitle.length() > 0) {
            Group group = new Group(blockCanvas, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            group.setLayout(new FillLayout());
            group.setLayoutData(gridData);
            hookKeyListener(group);
            group.setText(frameTitle);
            _mainPane = new EJRWTEntireJGridPane(group, 1);
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, 1, mainScreenProperties.getDisplayFrame() ? SWT.BORDER : SWT.NONE);
            _mainPane.setLayoutData(gridData);
            if (!mainScreenProperties.getDisplayFrame())
                _mainPane.cleanLayout();
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
        }
    }
    hookKeyListener(_mainPane);
    int style = SWT.VIRTUAL;
    if (!rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.HIDE_TABLE_BORDER, false)) {
        style = style | SWT.BORDER;
    }
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties().getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Table table;
    if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new GridLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                filterTree = new EJRWTAbstractFilteredTable(group, style) {

                    @Override
                    public void filter(String filter) {
                        if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
                            _filteredContentProvider.setFilter(filter);
                            filterText = filter;
                            getViewer().setInput(filter);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent, style);
                    }
                };
            } else {
                filterTree = new EJRWTAbstractFilteredTable(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style) {

                    @Override
                    public void filter(String filter) {
                        if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
                            _filteredContentProvider.setFilter(filter);
                            filterText = filter;
                            getViewer().setInput(filter);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent, style);
                    }
                };
                filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            filterTree = new EJRWTAbstractFilteredTable(_mainPane, style) {

                @Override
                public void filter(String filter) {
                    if (_filteredContentProvider != null && (filter == null && _filteredContentProvider.getFilter() != null || !filter.equals(_filteredContentProvider.getFilter()))) {
                        _filteredContentProvider.setFilter(filter);
                        filterText = filter;
                        getViewer().setInput(filter);
                        if (getFocusedRecord() == null) {
                            selectRow(0);
                        }
                        notifyStatus();
                    }
                }

                @Override
                protected TableViewer doCreateTableViewer(Composite parent, int style) {
                    return _tableViewer = new TableViewer(parent, style);
                }
            };
            filterTree.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        table = (_tableViewer = filterTree.getViewer()).getTable();
        defaultMessage = rendererProp.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_MESSAGE);
        if (defaultMessage != null)
            filterTree.getFilterControl().setMessage(defaultMessage);
    } else {
        filterTree = null;
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame() && displayProperties.getFrameTitle() != null && displayProperties.getFrameTitle().length() > 0) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                group.setText(displayProperties.getFrameTitle());
                group.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
                table = new Table(group, style);
            } else {
                table = new Table(_mainPane, displayProperties.dispayGroupFrame() ? style | SWT.BORDER : style);
                table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
            }
        } else {
            table = new Table(_mainPane, style);
            table.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        _tableViewer = new TableViewer(table);
    }
    table.setLinesVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_VERTICAL_LINES, true));
    table.setHeaderVisible(rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.SHOW_HEADING_PROPERTY, true));
    int fixedColumns = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.COLUMNS_FIXED, -1);
    if (fixedColumns > 0) {
        table.setData(EJ_RWT.FIXED_COLUMNS, fixedColumns);
    }
    int rowHeight = rendererProp.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_HEIGH_PROPERTY, -1);
    if (rowHeight > 0) {
        table.setData(EJ_RWT.CUSTOM_ITEM_HEIGHT, rowHeight);
    }
    Control[] children = table.getChildren();
    for (Control control : children) {
        hookKeyListener(control);
    }
    hookKeyListener(table);
    EJRWTTableViewerColumnFactory factory = new EJRWTTableViewerColumnFactory(_tableViewer);
    ColumnViewerToolTipSupport.enableFor(_tableViewer);
    boolean autoSize = false;
    final List<ColumnLabelProvider> nodeTextProviders = new ArrayList<ColumnLabelProvider>();
    table.setData(EJ_RWT.MARKUP_ENABLED, rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ENABLE_MARKUP, false));
    boolean markEscapeHtml = false;
    for (EJItemGroupProperties groupProperties : allItemGroupProperties) {
        Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
        autoSize = itemProperties.size() == 1;
        for (EJScreenItemProperties screenItemProperties : itemProperties) {
            EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) screenItemProperties;
            ColumnLabelProvider screenItem = createScreenItem(factory, mainScreenItemProperties);
            if (screenItem instanceof HtmlBaseColumnLabelProvider) {
                table.setData(EJ_RWT.MARKUP_ENABLED, true);
                markEscapeHtml = !rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ENABLE_MARKUP, false);
            }
            if (screenItem != null) {
                nodeTextProviders.add(screenItem);
                if (autoSize) {
                    EJFrameworkExtensionProperties itemBl = mainScreenItemProperties.getBlockRendererRequiredProperties();
                    autoSize = itemBl != null && itemBl.getIntProperty(EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0) <= 0;
                }
            }
        }
    }
    if (markEscapeHtml)
        for (ColumnLabelProvider columnLabelProvider : nodeTextProviders) {
            if (columnLabelProvider instanceof HtmlEscapeSupport) {
                HtmlEscapeSupport escapeSupport = (HtmlEscapeSupport) columnLabelProvider;
                escapeSupport.setEscape();
            }
        }
    if (autoSize) {
        table.addControlListener(new ControlListener() {

            @Override
            public void controlResized(ControlEvent e) {
                if (table.getSize().x > 10) {
                    table.getColumn(0).setWidth(table.getSize().x - 10);
                }
            }

            @Override
            public void controlMoved(ControlEvent e) {
            // TODO Auto-generated method stub
            }
        });
    }
    table.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent arg0) {
            setHasFocus(false);
        }

        @Override
        public void focusGained(FocusEvent arg0) {
            setHasFocus(true);
        }
    });
    _mainPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent arg0) {
            if (!table.isFocusControl()) {
                setHasFocus(true);
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent arg0) {
            if (!table.isFocusControl()) {
                setHasFocus(true);
            }
        }
    });
    _tableViewer.setContentProvider(_filteredContentProvider = new FilteredContentProvider() {

        boolean matchItem(EJDataRecord rec) {
            if (filter != null && filter.trim().length() > 0) {
                for (ColumnLabelProvider filterTextProvider : nodeTextProviders) {
                    String text = filterTextProvider.getText(rec);
                    if (text != null && text.toLowerCase().contains(filter.toLowerCase())) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
            _tableBaseRecords.clear();
            if (arg2 != null && arg2.equals(filter) && filter.trim().length() > 0) {
                // filter
                for (EJDataRecord record : _block.getBlock().getRecords()) {
                    if (matchItem(record)) {
                        _tableBaseRecords.add(record);
                    }
                }
            } else {
                filter = null;
                if (filterTree != null) {
                    filterTree.clearText();
                }
                _tableBaseRecords.addAll(_block.getBlock().getRecords());
            }
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object arg0) {
            return _tableBaseRecords.toArray();
        }
    });
    _tableViewer.setInput(new Object());
    selectRow(0);
    // add double click action
    final String doubleClickActionCommand = rendererProp.getStringProperty(EJRWTMultiRecordBlockDefinitionProperties.DOUBLE_CLICK_ACTION_COMMAND);
    if (doubleClickActionCommand != null) {
        _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent arg0) {
                _block.executeActionCommand(doubleClickActionCommand, EJScreenType.MAIN);
            }
        });
    }
    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent arg0) {
            EJDataRecord focusedRecord = getFocusedRecord();
            if (focusedRecord != null) {
                _block.newRecordInstance(focusedRecord);
            }
            notifyStatus();
        }
    });
    table.addListener(SWT.MouseDown, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Point pt = new Point(event.x, event.y);
            TableItem item = table.getItem(pt);
            if (item == null || item.isDisposed())
                return;
            for (int i = 0; i < table.getColumnCount(); i++) {
                if (item == null || item.isDisposed())
                    return;
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    TableColumn column = table.getColumn(i);
                    if (column != null && column.getData("ITEM") instanceof EJScreenItemController) {
                        ((EJScreenItemController) column.getData("ITEM")).executeActionCommand();
                    }
                }
            }
        }
    });
}
Also used : EJItemGroupProperties(org.entirej.framework.core.properties.interfaces.EJItemGroupProperties) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) Rectangle(org.eclipse.swt.graphics.Rectangle) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ControlListener(org.eclipse.swt.events.ControlListener) EJRWTTableViewerColumnFactory(org.entirej.applicationframework.rwt.table.EJRWTTableViewerColumnFactory) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJFrameworkExtensionPropertyList(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyList) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) HtmlEscapeSupport(org.entirej.applicationframework.rwt.table.HtmlEscapeSupport) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJMainScreenProperties(org.entirej.framework.core.properties.interfaces.EJMainScreenProperties) FocusListener(org.eclipse.swt.events.FocusListener) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane) Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) EJRWTDeleteAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTDeleteAction) EJRWTQueryAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTQueryAction) EJRWTUpdateAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTUpdateAction) EJRWTInsertAction(org.entirej.applicationframework.rwt.application.components.actions.EJRWTInsertAction) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ControlListener(org.eclipse.swt.events.ControlListener) EJRWTTableSortSelectionListener(org.entirej.applicationframework.rwt.table.EJRWTTableSortSelectionListener) Listener(org.eclipse.swt.widgets.Listener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FocusListener(org.eclipse.swt.events.FocusListener) KeyListener(org.eclipse.swt.events.KeyListener) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Table(org.eclipse.swt.widgets.Table) EJRWTAbstractFilteredTable(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) Section(org.eclipse.ui.forms.widgets.Section) Point(org.eclipse.swt.graphics.Point) HtmlBaseColumnLabelProvider(org.entirej.applicationframework.rwt.table.HtmlBaseColumnLabelProvider) FilteredContentProvider(org.entirej.applicationframework.rwt.table.EJRWTAbstractFilteredTable.FilteredContentProvider) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Example 22 with ControlListener

use of org.eclipse.swt.events.ControlListener in project tdq-studio-se by Talend.

the class SQLEditor method createToolbar.

/**
 * Creates the toolbar
 *
 * @param parent
 */
private void createToolbar(final Composite parent) {
    toolBar = new SQLEditorToolBar(parent, this);
    toolBar.addResizeListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            parent.getParent().layout(true);
            parent.layout(true);
        }
    });
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) SQLEditorToolBar(net.sourceforge.sqlexplorer.sqleditor.actions.SQLEditorToolBar)

Example 23 with ControlListener

use of org.eclipse.swt.events.ControlListener in project gemoc-studio by eclipse.

the class AbstractTimelineView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final Composite container;
    if (hasDetailViewer()) {
        final SashForm mainSashForm = new SashForm(parent, SWT.HORIZONTAL);
        container = mainSashForm;
        detailViewer = createDetailViewer(container);
    } else {
        container = parent;
    }
    timelineViewer = new ScrollingGraphicalViewer();
    Composite timelineComposite = new Composite(container, SWT.NONE);
    timelineComposite.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));
    if (hasDetailViewer()) {
        ((SashForm) container).setWeights(new int[] { DETAIL_RATIO, TIMELINE_RATIO });
    }
    GridLayout layout = new GridLayout(1, false);
    timelineComposite.setLayout(layout);
    timelineViewer.createControl(timelineComposite);
    timelineSlider = new Slider(timelineComposite, SWT.HORIZONTAL);
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    timelineSlider.setLayoutData(gridData);
    gridData.grabExcessHorizontalSpace = true;
    rootEditPart = new ScalableFreeformRootEditPart();
    rootEditPart.setViewer(timelineViewer);
    timelineViewer.setRootEditPart(rootEditPart);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = SWT.FILL;
    gridData.grabExcessVerticalSpace = true;
    timelineViewer.getControl().setLayoutData(gridData);
    timelineViewer.setEditPartFactory(getTimelineEditPartFactory());
    timelineWindow = new TimelineWindow(provider);
    timelineViewer.setContents(timelineWindow);
    timelineSlider.setPageIncrement(timelineWindow.getLength());
    timelineSlider.setThumb(timelineWindow.getLength());
    timelineSlider.setSelection(timelineWindow.getStart());
    if (provider != null) {
        timelineSlider.setMaximum(timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
        timelineSlider.setVisible(timelineWindow.getLength() < timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
    } else {
        timelineSlider.setVisible(false);
    }
    timelineSlider.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }
    });
    timelineWindowListener = new TimelineWindowListener();
    timelineWindow.addTimelineWindowListener(timelineWindowListener);
    if (provider != null) {
        provider.addTimelineListener(timelineWindowListener);
    }
    timelineViewer.getControl().setBackground(ColorConstants.listBackground);
    if (hasDetailViewer()) {
        timelineViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                final ISelection selection = event.getSelection();
                if (selection instanceof IStructuredSelection) {
                    final Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                    if (firstElement instanceof PossibleStepEditPart) {
                        final PossibleStepEditPart possibleStepEditPart = (PossibleStepEditPart) firstElement;
                        detailViewer.setInput(possibleStepEditPart.getModel().getPossibleStep());
                    }
                }
            }
        });
    }
    timelineViewer.getControl().addKeyListener(new TimelineKeyListener());
    final TimelineMouseListener listener = new TimelineMouseListener();
    timelineViewer.getControl().addMouseListener(listener);
    timelineViewer.getControl().addMouseMoveListener(listener);
    timelineViewer.getControl().addMouseWheelListener(new TimelineMouseWheelListener());
    rootEditPart.getZoomManager().addZoomListener(new ZoomListener() {

        @Override
        public void zoomChanged(double zoom) {
            timelineWindow.setLength(getWindowLength());
        }
    });
    timelineViewer.getControl().addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            timelineWindow.setLength(getWindowLength());
            final Canvas canevas = (Canvas) timelineViewer.getControl();
            canevas.getHorizontalBar().setVisible(false);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // nothing to do here
        }
    });
    final ICommandService cmdService = (ICommandService) getSite().getService(ICommandService.class);
    String commandID = getFollowCommandID();
    if (commandID != null) {
        final Command followCommand = cmdService.getCommand(commandID);
        if (followCommand != null) {
            final State state = followCommand.getState(RegistryToggleState.STATE_ID);
            follow = state != null && ((Boolean) state.getValue()).booleanValue();
        }
    }
    createMenuManager();
}
Also used : Slider(org.eclipse.swt.widgets.Slider) TimelineWindow(org.eclipse.gemoc.timeline.model.TimelineWindow) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICommandService(org.eclipse.ui.commands.ICommandService) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ControlListener(org.eclipse.swt.events.ControlListener) PossibleStepEditPart(org.eclipse.gemoc.timeline.editpart.PossibleStepEditPart) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FigureCanvas(org.eclipse.draw2d.FigureCanvas) Canvas(org.eclipse.swt.widgets.Canvas) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) ZoomListener(org.eclipse.gef.editparts.ZoomListener) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent) ITimelineWindowListener(org.eclipse.gemoc.timeline.model.ITimelineWindowListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 24 with ControlListener

use of org.eclipse.swt.events.ControlListener in project BiglyBT by BiglySoftware.

the class SB_Dashboard method build.

protected void build(Composite dashboard_composite) {
    try {
        building++;
        if (dashboard_composite == null) {
            return;
        }
        Utils.disposeComposite(dashboard_composite, false);
        int[][] layout = getDashboardLayout();
        layout = compactLayout(layout, 0, 0);
        Map<Integer, DashboardItem> item_map = new HashMap<>();
        for (DashboardItem item : items) {
            item_map.put(item.getUID(), item);
        }
        for (int[] row : layout) {
            for (int i = 0; i < row.length; i++) {
                int c = row[i];
                if (!item_map.containsKey(c)) {
                    row[i] = -1;
                }
            }
        }
        boolean use_tabs = getUseTabs();
        final List<SashForm> sashes = new ArrayList<>();
        List<Control> controls = new ArrayList<>();
        build(item_map, dashboard_composite, use_tabs, sashes, controls, layout, 0, 0, layout.length, layout.length);
        int[][] sash_weights = getSashWeights();
        if (sash_weights.length == sashes.size()) {
            for (int i = 0; i < sash_weights.length; i++) {
                int[] weights = sash_weights[i];
                SashForm sf = sashes.get(i);
                int[] sf_weights = sf.getWeights();
                if (sf_weights.length == weights.length) {
                    try {
                        sf.setWeights(weights);
                    } catch (Throwable e) {
                        // in case something borks
                        Debug.out(e);
                    }
                }
                sf.setData(sf_weights.length);
            }
        } else {
            // something's changed
            setSashWeights(new int[0][0]);
            for (SashForm sf : sashes) {
                int[] weights = sf.getWeights();
                sf.setData(weights.length);
            }
        }
        for (Control c : controls) {
            c.addControlListener(new ControlListener() {

                @Override
                public void controlResized(ControlEvent arg0) {
                    if (building > 0) {
                        return;
                    }
                    int[][] weights = new int[sashes.size()][];
                    for (int i = 0; i < sashes.size(); i++) {
                        SashForm sf = sashes.get(i);
                        if (sf.isDisposed()) {
                            return;
                        }
                        weights[i] = sf.getWeights();
                        Object d = sf.getData();
                        if (d == null || ((Integer) d) != weights[i].length) {
                            return;
                        }
                    }
                    setSashWeights(weights);
                }

                @Override
                public void controlMoved(ControlEvent arg0) {
                // TODO Auto-generated method stub
                }
            });
        }
        dashboard_composite.getParent().layout(true, true);
    } finally {
        SimpleTimer.addEvent("delayer", SystemTime.getOffsetTime(2500), new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        building--;
                    }
                });
            }
        });
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) Control(org.eclipse.swt.widgets.Control) TimerEventPerformer(com.biglybt.core.util.TimerEventPerformer) ControlListener(org.eclipse.swt.events.ControlListener) TimerEvent(com.biglybt.core.util.TimerEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 25 with ControlListener

use of org.eclipse.swt.events.ControlListener in project netxms by netxms.

the class ChildObjectListDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    AbstractObject object = ((NXCSession) ConsoleSharedData.getSession()).findObjectById(parentObject);
    AbstractObject[] sourceObjects = (object != null) ? object.getChildsAsArray() : new AbstractObject[0];
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    dialogArea.setLayout(layout);
    // Create filter area
    Composite filterArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    filterArea.setLayout(layout);
    filterArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label filterLabel = new Label(filterArea, SWT.NONE);
    filterLabel.setText(Messages.get().ChildObjectListDialog_Filter);
    filterText = new Text(filterArea, SWT.BORDER);
    filterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            filter.setFilterString(filterText.getText());
            objectList.refresh(false);
            AbstractObject obj = filter.getLastMatch();
            if (obj != null) {
                objectList.setSelection(new StructuredSelection(obj), true);
                objectList.reveal(obj);
            }
        }
    });
    // Create object list
    objectList = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    TableColumn tc = new TableColumn(objectList.getTable(), SWT.LEFT);
    tc.setText(Messages.get().ChildObjectListDialog_Name);
    tc.setWidth(280);
    objectList.getTable().setHeaderVisible(false);
    objectList.setContentProvider(new ArrayContentProvider());
    objectList.setLabelProvider(new WorkbenchLabelProvider());
    objectList.setComparator(new ViewerComparator());
    filter = new ObjectFilter(null, sourceObjects, classFilter);
    objectList.addFilter(filter);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    objectList.getControl().setLayoutData(gd);
    objectList.getTable().addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            Table table = objectList.getTable();
            int w = table.getSize().x - table.getBorderWidth() * 2;
            ScrollBar sc = table.getVerticalBar();
            if ((sc != null) && sc.isVisible())
                w -= sc.getSize().x;
            table.getColumn(0).setWidth(w);
        }
    });
    if (object != null)
        objectList.setInput(sourceObjects);
    filterText.setFocus();
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) NXCSession(org.netxms.client.NXCSession) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) ObjectFilter(org.netxms.ui.eclipse.objectbrowser.widgets.internal.ObjectFilter) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)54 ControlListener (org.eclipse.swt.events.ControlListener)54 GridData (org.eclipse.swt.layout.GridData)21 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Control (org.eclipse.swt.widgets.Control)12 FocusListener (org.eclipse.swt.events.FocusListener)11 MouseEvent (org.eclipse.swt.events.MouseEvent)11 GridLayout (org.eclipse.swt.layout.GridLayout)11 Composite (org.eclipse.swt.widgets.Composite)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 ArrayList (java.util.ArrayList)9 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)9 DisposeEvent (org.eclipse.swt.events.DisposeEvent)9 DisposeListener (org.eclipse.swt.events.DisposeListener)9 KeyEvent (org.eclipse.swt.events.KeyEvent)9 Point (org.eclipse.swt.graphics.Point)9 Event (org.eclipse.swt.widgets.Event)8 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)6 Listener (org.eclipse.swt.widgets.Listener)6 Table (org.eclipse.swt.widgets.Table)6