Example usage for org.eclipse.jface.resource ImageDescriptor createFromImage

List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createFromImage.

Prototype

public static ImageDescriptor createFromImage(Image img) 

Source Link

Document

Creates and returns a new image descriptor for the given image.

Usage

From source file:org.eclipse.wst.sse.sieditor.ui.Activator.java

License:Open Source License

public Image getImage(Image originalImage, int severity) {
    if (severity == IStatus.OK || severity == IStatus.INFO) {
        return originalImage;
    }/*from www . jav a 2  s.c om*/

    final String fullKey = originalImage.hashCode() + UIConstants.UNDERSCORE + severity;
    Image image = getImageRegistry().get(fullKey);
    if (image == null) {
        String decorationId = null;
        switch (severity) {
        case IStatus.ERROR:
            decorationId = FieldDecorationRegistry.DEC_ERROR;
            break;
        case IStatus.WARNING:
            decorationId = FieldDecorationRegistry.DEC_WARNING;
            break;
        }

        final Image errImage = FieldDecorationRegistry.getDefault().getFieldDecoration(decorationId).getImage();
        if (errImage == null) {
            return originalImage;
        }

        DecorationOverlayIcon overlay;

        overlay = new DecorationOverlayIcon(originalImage, ImageDescriptor.createFromImage(errImage),
                IDecoration.BOTTOM_LEFT);
        image = overlay.createImage();
        getImageRegistry().put(fullKey, image);
    }

    return image;
}

From source file:org.eclipse.wst.xml.ui.internal.tabletree.XMLEditorPluginImageHelper.java

License:Open Source License

private static void initializeRegistry() {
    // Taken from org.eclipse.ui.internal.WorkbenchImages
    Display d = Display.getCurrent();/*ww w  .  j a v  a  2  s  .  c  o  m*/

    Image viewMenu = new Image(d, 11, 16);
    Image viewMenuMask = new Image(d, 11, 16);

    GC gc = new GC(viewMenu);
    GC maskgc = new GC(viewMenuMask);
    drawViewMenu(gc, maskgc);
    gc.dispose();
    maskgc.dispose();

    ImageData data = viewMenu.getImageData();
    data.transparentPixel = data.getPixel(0, 0);

    Image vm2 = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
    viewMenu.dispose();
    viewMenuMask.dispose();

    getImageRegistry().put(EDITOR_MENU, vm2);
    getImageDescriptorRegistry().put(EDITOR_MENU, ImageDescriptor.createFromImage(vm2));
}

From source file:org.eclipse.xtext.graphview.view.config.SelectDiagramConfigurationAction.java

License:Open Source License

@Inject
protected void setImages(PluginImageHelper pluginImageHelper) {
    setImageDescriptor(ImageDescriptor.createFromImage(pluginImageHelper.getImage("elcl16/configure.gif")));
}

From source file:org.eclipse.xtext.graphview.view.RelayoutAction.java

License:Open Source License

@Inject
protected void setImages(PluginImageHelper imageHelper) {
    setImageDescriptor(ImageDescriptor.createFromImage(imageHelper.getImage("elcl16/arrangeall.gif")));
    setDisabledImageDescriptor(ImageDescriptor.createFromImage(imageHelper.getImage("dlcl16/arrangeall.gif")));
}

From source file:org.eclipse.xtext.graphview.view.ResetAction.java

License:Open Source License

@Inject
protected void setImages(PluginImageHelper imageHelper) {
    setImageDescriptor(ImageDescriptor.createFromImage(imageHelper.getImage("elcl16/refresh_nav.gif")));
    setDisabledImageDescriptor(ImageDescriptor.createFromImage(imageHelper.getImage("dlcl16/refresh_nav.gif")));
}

From source file:org.eclipse.xtext.ui.PluginImageHelper.java

License:Open Source License

/**
 * @since 2.4//from www  .j a  v a 2  s  . c  o m
 */
@Override
public ImageDescriptor getImageDescriptor(Image image) {
    for (Map.Entry<ImageDescriptor, Image> entry : registry.entrySet()) {
        if (entry.getValue().equals(image))
            return entry.getKey();
    }
    ImageDescriptor newDescriptor = ImageDescriptor.createFromImage(image);
    registry.put(newDescriptor, image);
    return newDescriptor;
}

From source file:org.emonic.base.actions.DefaultCSharpSourceAction.java

License:Open Source License

public DefaultCSharpSourceAction(CSharpEditor editor, String id, String label, String imgName) {
    this.editor = editor;
    //setId(getCSharpActionId());
    setId(id);//from  w  w w  .  ja  v a  2s. c  o m
    setText(label);
    Image imge = EMonoPlugin.imageDescriptorFromPlugin(imgName).createImage();
    setImageDescriptor(ImageDescriptor.createFromImage(imge));
}

From source file:org.entirej.applicationframework.rwt.renderers.blocks.EJRWTMultiRecordBlockRenderer.java

License:Apache License

@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(/*from  w w w  . j  a v  a2  s . co  m*/
                    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);
        }
        EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
        if (mainScreenProperties.getDisplayFrame()) {
            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);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                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);
            _mainPane.setLayoutData(gridData);
            _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(
                                ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
                    }
                    toolBarManager.add(action);
                }
            }

            toolBarManager.update(true);
            section.setTextClient(toolbar);
        }
    } else {
        if (mainScreenProperties.getDisplayFrame()) {
            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);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                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);
            _mainPane.setLayoutData(gridData);
            _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;
    }

    if (rendererProp.getBooleanProperty(EJRWTMultiRecordBlockDefinitionProperties.ROW_SELECTION_PROPERTY,
            true)) {
        style = style | SWT.FULL_SELECTION;
    } else {
        style = style | SWT.HIDE_SELECTION;
    }
    Collection<EJItemGroupProperties> allItemGroupProperties = _block.getProperties()
            .getScreenItemGroupContainer(EJScreenType.MAIN).getAllItemGroupProperties();
    final Table table;
    final boolean hideSelection = (style & SWT.HIDE_SELECTION) != 0;
    final EJRWTAbstractFilteredTable filterTree;
    if (rendererProp.getBooleanProperty(EJRWTTreeBlockDefinitionProperties.FILTER, false)) {
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame()) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                if (displayProperties.getFrameTitle() != null
                        && displayProperties.getFrameTitle().length() > 0) {
                    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);
                            getViewer().setInput(filter);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent) {
                            private static final long serialVersionUID = 5803610958722645987L;

                            @Override
                            public void setSelection(ISelection selection) {
                                if (hideSelection) {
                                    selection = new StructuredSelection();
                                }
                                super.setSelection(selection);
                            }

                            @Override
                            public void setSelection(ISelection selection, boolean reveal) {
                                if (hideSelection) {
                                    selection = new StructuredSelection();
                                }
                                super.setSelection(selection, reveal);
                            }
                        };
                    }
                };
            } 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);
                            getViewer().setInput(filter);
                            if (getFocusedRecord() == null) {
                                selectRow(0);
                            }
                            notifyStatus();
                        }
                    }

                    @Override
                    protected TableViewer doCreateTableViewer(Composite parent, int style) {
                        return _tableViewer = new TableViewer(parent) {
                            private static final long serialVersionUID = 5803610958722645987L;

                            @Override
                            public void setSelection(ISelection selection) {
                                if (hideSelection) {
                                    selection = new StructuredSelection();
                                }
                                super.setSelection(selection);
                            }

                            @Override
                            public void setSelection(ISelection selection, boolean reveal) {
                                if (hideSelection) {
                                    selection = new StructuredSelection();
                                }
                                super.setSelection(selection, reveal);
                            }
                        };
                    }
                };
                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);
                        getViewer().setInput(filter);
                        if (getFocusedRecord() == null) {
                            selectRow(0);
                        }
                        notifyStatus();
                    }
                }

                @Override
                protected TableViewer doCreateTableViewer(Composite parent, int style) {
                    return _tableViewer = new TableViewer(parent) {
                        private static final long serialVersionUID = 5803610958722645987L;

                        @Override
                        public void setSelection(ISelection selection) {
                            if (hideSelection) {
                                selection = new StructuredSelection();
                            }
                            super.setSelection(selection);
                        }

                        @Override
                        public void setSelection(ISelection selection, boolean reveal) {
                            if (hideSelection) {
                                selection = new StructuredSelection();
                            }
                            super.setSelection(selection, reveal);
                        }
                    };
                }
            };

            filterTree.setLayoutData(
                    new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
        }
        table = (_tableViewer = filterTree.getViewer()).getTable();
    } else {
        filterTree = null;
        if (allItemGroupProperties.size() > 0) {
            EJItemGroupProperties displayProperties = allItemGroupProperties.iterator().next();
            if (displayProperties.dispayGroupFrame()) {
                Group group = new Group(_mainPane, SWT.NONE);
                group.setLayout(new FillLayout());
                if (displayProperties.getFrameTitle() != null
                        && displayProperties.getFrameTitle().length() > 0) {
                    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, 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) {
            @Override
            public void setSelection(ISelection selection) {
                if (hideSelection) {
                    selection = new StructuredSelection();
                }
                super.setSelection(selection);
            }

            @Override
            public void setSelection(ISelection selection, boolean reveal) {
                if (hideSelection) {
                    selection = new StructuredSelection();
                }
                super.setSelection(selection, reveal);
            }
        };
    }

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

    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 != null) {
                nodeTextProviders.add(screenItem);
                if (autoSize) {
                    EJFrameworkExtensionProperties itemBl = mainScreenItemProperties
                            .getBlockRendererRequiredProperties();

                    autoSize = itemBl != null && itemBl.getIntProperty(
                            EJRWTMultiRecordBlockDefinitionProperties.DISPLAY_WIDTH_PROPERTY, 0) <= 0;

                }
            }

        }
    }

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

}

From source file:org.entirej.applicationframework.rwt.renderers.blocks.EJRWTSingleRecordBlockRenderer.java

License:Apache License

@Override
public void buildGuiComponent(EJRWTEntireJGridPane blockCanvas) {

    EJBlockProperties blockProperties = _block.getProperties();
    EJMainScreenProperties mainScreenProperties = blockProperties.getMainScreenProperties();

    EJFrameworkExtensionProperties brendererProperties = blockProperties.getBlockRendererProperties();

    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();
    }/*w w w.  j  av a 2s  . c  o  m*/
    if (gridData.grabExcessVerticalSpace) {
        gridData.minimumHeight = mainScreenProperties.getHeight();
    }
    blockCanvas.setLayoutData(gridData);

    EJFrameworkExtensionProperties sectionProperties = null;
    if (brendererProperties != null) {
        sectionProperties = brendererProperties
                .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);
        }

        EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);

        if (mainScreenProperties.getDisplayFrame()) {
            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);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                group.setText(frameTitle);
            }
            _mainPane = new EJRWTEntireJGridPane(group, mainScreenProperties.getNumCols());
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

            section.setClient(group);
        } else {
            _mainPane = new EJRWTEntireJGridPane(section, mainScreenProperties.getNumCols());
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

            _mainPane.setLayoutData(gridData);
            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(
                                ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
                    }
                    toolBarManager.add(action);
                }
            }
            toolBarManager.update(true);
            section.setTextClient(toolbar);
        }
    } else {
        if (mainScreenProperties.getDisplayFrame()) {
            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);
            String frameTitle = mainScreenProperties.getFrameTitle();
            if (frameTitle != null && frameTitle.length() > 0) {
                group.setText(frameTitle);
            }
            _mainPane = new EJRWTEntireJGridPane(group, mainScreenProperties.getNumCols());

        } else {
            _mainPane = new EJRWTEntireJGridPane(blockCanvas, mainScreenProperties.getNumCols());
            _mainPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

            _mainPane.setLayoutData(gridData);
        }
    }

    EJFrameworkExtensionProperties rendererProp = EJCoreProperties.getInstance()
            .getApplicationDefinedProperties();
    if (rendererProp != null) {
        EJFrameworkExtensionProperties propertyGroup = rendererProp
                .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);

        }
    }

    hookKeyListener(_mainPane);
    hookFocusListener(_mainPane);
    _mainPane.cleanLayout();
    EJDataRecord registeredRecord = _mainItemRegister.getRegisteredRecord();
    _mainItemRegister.resetRegister();
    EJItemGroupPropertiesContainer container = blockProperties.getScreenItemGroupContainer(EJScreenType.MAIN);
    Collection<EJItemGroupProperties> itemGroupProperties = container.getAllItemGroupProperties();
    for (EJItemGroupProperties ejItemGroupProperties : itemGroupProperties) {
        createItemGroup(_mainPane, ejItemGroupProperties);
    }

    _mainItemRegister.clearRegisteredValues();
    if (registeredRecord == null) {
        registeredRecord = getFirstRecord();
    }
    if (registeredRecord != null) {

        _mainItemRegister.register(registeredRecord);
    }
    _mainPane.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent arg0) {
            setHasFocus(true);
        }
    });
}

From source file:org.entirej.applicationframework.rwt.renderers.blocks.EJRWTSingleRecordBlockRenderer.java

License:Apache License

private void createItemGroup(Composite parent, EJItemGroupProperties groupProperties) {
    EJRWTEntireJGridPane groupPane;/*  ww w.  j  a v  a 2 s .co  m*/
    String frameTitle = groupProperties.getFrameTitle();
    EJFrameworkExtensionProperties rendererProperties = groupProperties.getRendererProperties();
    boolean hasGroup = groupProperties.dispayGroupFrame() && frameTitle != null && frameTitle.length() > 0;
    if (hasGroup) {

        if (rendererProperties != null
                && rendererProperties.getStringProperty(
                        EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE) != null
                && !EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE_GROUP
                        .equals(rendererProperties.getStringProperty(
                                EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_MODE))) {
            int style = ExpandableComposite.TITLE_BAR;

            String mode = rendererProperties
                    .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 (rendererProperties.getBooleanProperty(
                    EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_TITLE_BAR_EXPANDED, true)) {
                style = style | ExpandableComposite.EXPANDED;
            }
            Section section = toolkit.createSection(parent, style);
            section.setText(frameTitle);
            EJRWTImageRetriever.getGraphicsProvider().rendererSection(section);
            section.setLayoutData(createItemGroupGridData(groupProperties));
            parent = section;
            hookKeyListener(section);
            section.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent arg0) {
                    setHasFocus(true);
                }
            });
            groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols());
            groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

            String customCSSKey = rendererProperties
                    .getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);

            if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            }

            //                groupPane.getLayout().marginRight = 5;
            //                groupPane.getLayout().marginLeft = 5;
            section.setClient(groupPane);

            final EJFrameworkExtensionPropertyList propertyList = rendererProperties
                    .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(
                                    ImageDescriptor.createFromImage(EJRWTImageRetriever.get(actionImage)));
                        }
                        toolBarManager.add(action);
                    }

                }
                toolBarManager.update(true);
                section.setTextClient(toolbar);
            }
        } else {
            Group group = new Group(parent, SWT.NONE);
            group.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);
            String customCSSKey = rendererProperties
                    .getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);

            if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                group.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            }
            group.setLayout(new FillLayout());
            group.setLayoutData(createItemGroupGridData(groupProperties));
            group.setText(frameTitle);
            parent = group;
            hookKeyListener(group);
            group.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent arg0) {
                    setHasFocus(true);
                }
            });
            groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols());
            groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

            if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            }
            //                groupPane.getLayout().marginRight = 5;
            //                groupPane.getLayout().marginLeft = 5;
        }
    } else {
        groupPane = new EJRWTEntireJGridPane(parent, groupProperties.getNumCols(),
                groupProperties.dispayGroupFrame() ? SWT.BORDER : SWT.NONE);
        groupPane.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_GROUP);

        if (rendererProperties != null) {
            String customCSSKey = rendererProperties
                    .getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ITEM_GROUP_CSS_KEY);

            if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                groupPane.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            }
        }

        if (groupProperties.dispayGroupFrame()) {
            //                groupPane.getLayout().marginRight = 5;
            //                groupPane.getLayout().marginLeft = 5;
        }
    }

    groupPane.getLayout().verticalSpacing = 1;
    hookKeyListener(groupPane);
    groupPane.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent arg0) {
            setHasFocus(true);
        }
    });

    groupPane.setPaneName(groupProperties.getName());
    if (!hasGroup) {
        groupPane.setLayoutData(createItemGroupGridData(groupProperties));
    }
    // items adding
    Collection<EJScreenItemProperties> itemProperties = groupProperties.getAllItemProperties();
    for (EJScreenItemProperties screenItemProperties : itemProperties) {
        createScreenItem(groupPane, (EJCoreMainScreenItemProperties) screenItemProperties);
    }

    // build sub groups
    EJItemGroupPropertiesContainer groupPropertiesContainer = groupProperties.getChildItemGroupContainer();
    Collection<EJItemGroupProperties> itemGroupProperties = groupPropertiesContainer
            .getAllItemGroupProperties();
    for (EJItemGroupProperties ejItemGroupProperties : itemGroupProperties) {
        createItemGroup(groupPane, ejItemGroupProperties);
    }
}