Search in sources :

Example 1 with Canvas

use of org.eclipse.swt.widgets.Canvas in project tdi-studio-se by Talend.

the class ConnectionCreateAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    IMetadataTable meta = null;
    IMetadataTable newMetadata = null;
    String connectionName = null;
    if (getSelectedObjects().isEmpty()) {
        return;
    }
    List parts = getSelectedObjects();
    if (parts.size() == 1) {
        Object o = parts.get(0);
        if (!(o instanceof NodePart)) {
            return;
        }
        nodePart = (NodePart) o;
    } else {
        return;
    }
    Node node = (Node) nodePart.getModel();
    if (curNodeConnector.isMultiSchema()) {
        if (getText().equals(getNewOutputMenuName())) {
        // boolean nameOk = false;
        // while (!nameOk) {
        //
        // if (node.isELTComponent()) {
        // connectionName = "Default";
        // } else {
        // connectionName = askForConnectionName(node.getLabel(), connectionName);
        // }
        // if (connectionName.equals("")) { //$NON-NLS-1$
        // return;
        // }
        // if (connecType.equals(EConnectionType.TABLE) ||
        // node.getProcess().checkValidConnectionName(connectionName)) {
        // nameOk = true;
        // } else {
        // String message = Messages.getString("ConnectionCreateAction.errorCreateConnectionName",
        // connectionName); //$NON-NLS-1$
        // MessageDialog.openError(getWorkbenchPart().getSite().getShell(), Messages
        // .getString("ConnectionCreateAction.error"), message); //$NON-NLS-1$
        // }
        // }
        //
        // if (connecType.equals(EConnectionType.TABLE)) {
        // meta = new MetadataTable();
        // meta.setTableName(connectionName);
        // meta.setLabel(connectionName);
        // // meta.setTableId(node.getMetadataList().size());
        // newMetadata = meta;
        // } else {
        // boolean metaExist = false;
        // for (int i = 0; i < node.getMetadataList().size(); i++) {
        // if ((node.getMetadataList().get(i)).getTableName().equals(connectionName)) {
        // metaExist = true;
        // }
        // }
        // if (!metaExist) {
        // meta = new MetadataTable();
        // meta.setTableName(connectionName);
        // newMetadata = meta;
        // }
        // }
        } else {
            String tableName;
            // int tableId = -1;
            if (connecType == EConnectionType.TABLE) {
                int end = getText().length() - 1;
                //$NON-NLS-1$
                int start = getText().lastIndexOf("(") + 1;
                tableName = getText().substring(start, end);
                // table = Integer.parseInt(stringId);
                // tableName = getText().substring(0, start - 2);
                meta = node.getMetadataTable(tableName);
                // meta = (IMetadataTable) node.getMetadataList().get(tableId);
                connectionName = meta.getLabel();
            } else {
                tableName = getText();
                // tableId = -1;
                meta = node.getMetadataTable(tableName);
                // for (int i = 0; i < node.getMetadataList().size(); i++) {
                // IMetadataTable table = (IMetadataTable) node.getMetadataList().get(i);
                // if (table.getTableName().equals(tableName)) {
                // meta = (IMetadataTable) node.getMetadataList().get(i);
                // }
                // }
                connectionName = meta.getTableName();
            }
        }
        // for built-in only:
        if (meta != null) {
            meta.setAttachedConnector(curNodeConnector.getName());
        }
    } else {
        if (connecType == EConnectionType.TABLE) {
            if (getText().equals(getDefaultTableName())) {
                //$NON-NLS-1$
                int end = getText().lastIndexOf("(") - 1;
                int start = 0;
                if (end >= start) {
                    connectionName = getText().substring(start, end);
                    meta = node.getMetadataList().get(0);
                    meta.setAttachedConnector(curNodeConnector.getName());
                } else if (getText().endsWith(".")) {
                    connectionName = askForConnectionName(node.getLabel(), null);
                    if (connectionName != null && !"".equals(connectionName)) {
                        connectionName = getText() + connectionName;
                    }
                    meta = node.getMetadataList().get(0);
                    meta.setAttachedConnector(curNodeConnector.getName());
                }
            } else if (getText().equals(getNewOutputMenuName()) && getDefaultTableName() != null) {
                if (node.getComponent().getName().equals("tELTOracleInput")) {
                    //$NON-NLS-1$
                    connectionName = askForConnectionNameAndSchema(node.getLabel(), null);
                } else {
                    connectionName = askForConnectionName(node.getLabel(), null);
                }
            } else {
                // if (node.isELTComponent() && node.getComponentName().endsWith("Input"))
                if (node.getComponent().getName().equals("tELTOracleInput")) {
                    //$NON-NLS-1$
                    connectionName = askForConnectionNameAndSchema(node.getLabel(), getDefaultSchemaName());
                } else {
                    connectionName = askForConnectionName(node.getLabel(), null);
                }
            }
        } else {
            if (connecType.hasConnectionCategory(IConnectionCategory.FLOW)) {
                connectionName = node.getProcess().generateUniqueConnectionName(Process.DEFAULT_ROW_CONNECTION_NAME);
            } else if (connecType.hasConnectionCategory(IConnectionCategory.CAMEL)) {
                connectionName = ConnectionUtil.generateUniqueConnectionName(connecType, node.getProcess(), curNodeConnector);
            } else {
                connectionName = curNodeConnector.getLinkName();
            }
        }
        if (node.getMetadataList().size() == 0) {
            meta = null;
        } else {
            meta = node.getMetadataFromConnector(curNodeConnector.getName());
        }
    }
    /**
         * Create a mouse down event that thinks it is over the blob and dispatch it. This is a bit of a fudge to mimic
         * what the user ought to do.
         */
    Point point = null;
    point = nodePart.getFigure().getClientArea().getCenter();
    Point p = point;
    nodePart.getFigure().translateToAbsolute(p);
    Canvas canvas = (Canvas) nodePart.getViewer().getControl();
    Event event = new Event();
    event.button = 1;
    event.count = 0;
    event.detail = 0;
    event.end = 0;
    event.height = 0;
    event.keyCode = 0;
    event.start = 0;
    event.stateMask = 0;
    // any old time... doesn't matter
    event.time = 9516624;
    event.type = 3;
    event.widget = canvas;
    event.width = 0;
    event.x = p.x + 3;
    event.y = p.y + 3;
    /**
         * Set the connection tool to be the current tool
         */
    listArgs = new ArrayList<Object>();
    if (connecType.equals(EConnectionType.FLOW_MAIN) || connecType.equals(EConnectionType.FLOW_REF) || connecType.equals(EConnectionType.TABLE)) {
        if (meta == null) {
            listArgs.add(null);
        } else {
            listArgs.add(meta.getTableName());
        }
    } else {
        listArgs.add(node.getUniqueName());
    }
    String baseName = node.getConnectionName();
    String fromConnectionName = null;
    if (node.getProcess().checkValidConnectionName(baseName)) {
        fromConnectionName = node.getProcess().generateUniqueConnectionName(baseName);
    }
    if (fromConnectionName != null && connecType.hasConnectionCategory(IConnectionCategory.FLOW) && node.getProcess().checkValidConnectionName(fromConnectionName, false) && !curNodeConnector.isMultiSchema()) {
        listArgs.add(fromConnectionName);
    } else {
        listArgs.add(connectionName);
    }
    listArgs.add(newMetadata);
    TalendConnectionCreationTool myConnectTool = new TalendConnectionCreationTool(new CreationFactory() {

        @Override
        public Object getNewObject() {
            return listArgs;
        }

        @Override
        public Object getObjectType() {
            return curNodeConnector.getName();
        }
    }, true);
    myConnectTool.performConnectionStartWith(nodePart);
    nodePart.getViewer().getEditDomain().setActiveTool(myConnectTool);
    canvas.notifyListeners(3, event);
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) Canvas(org.eclipse.swt.widgets.Canvas) CreationFactory(org.eclipse.gef.requests.CreationFactory) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) List(java.util.List) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Example 2 with Canvas

use of org.eclipse.swt.widgets.Canvas in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createNewComponent.

public void createNewComponent(DropTargetEvent event1) {
    boolean quickCreateInput = event1.detail == DND.DROP_LINK;
    boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
    Iterator iterator = getSelection().iterator();
    List<TempStore> list = new ArrayList<TempStore>();
    List<IComponent> components = new ArrayList<IComponent>();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) obj;
            if (equalsJobInCurrentEditor(sourceNode)) {
                continue;
            }
            Item item = sourceNode.getObject().getProperty().getItem();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
                    continue;
                }
            }
            ERepositoryObjectType type = sourceNode.getObjectType();
            if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
                // RulesItem
                return;
            }
            {
            /**
                     * Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
                     * this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
                     * will cause some bugs when d&d salseforce connection, then maybe need to review
                     */
            // if (item instanceof SalesforceSchemaConnectionItem && type ==
            // ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
            // return;
            // }
            }
            TempStore store = new TempStore();
            store.seletetedNode = sourceNode;
            getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
            if (store.component != null) {
                list.add(store);
            } else {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
            }
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        /*
             * translate to Canvas coordinate
             */
        swtLocation = canvas.toControl(swtLocation);
        org.eclipse.swt.graphics.Point size = canvas.getSize();
        /*
             * translate to Viewport coordinate with zoom
             */
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        /*
             * calcule the view port position. Take into acounte the scroll position
             */
        ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
        IFigure targetFigure = part.getFigure();
        translateAbsolateToRelative(targetFigure, draw2dPosition);
        //$NON-NLS-1$
        String lastUniqname = "";
        // creates every node
        for (TempStore store : list) {
            RepositoryNode selectedNode = store.seletetedNode;
            IComponent element = store.component;
            if (!components.contains(element)) {
                components.add(element);
            }
            Node node = new Node(element);
            // for bug4564(metadata label format)
            // IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            // if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
            // node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
            // }
            IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
                String LabelValue = null;
                RepositoryNode repositoryNode = null;
                repositoryNode = (RepositoryNode) getSelection().getFirstElement();
                // dnd a table
                IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
                boolean hasDbTableField = dbTableParam != null;
                if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
                    LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
                    // dnd a job
                    LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
                } else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
                    LabelValue = element.getName();
                } else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
                    // dnd a default
                    LabelValue = selectedNode.getObject().getLabel();
                }
                if (LabelValue != null) {
                    node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
                }
            }
            processSpecificDBTypeIfSameProduct(store.componentName, node);
            NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
            ;
            // create component on link
            boolean executed = false;
            if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
                executed = createComponentOnLink(node, draw2dPosition);
            }
            if (!executed) {
                // create the node on the design sheet
                execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
            }
            // initialize the propertiesView
            CompoundCommand cc = new CompoundCommand();
            createRefreshingPropertiesCommand(cc, selectedNode, node);
            execCommandStack(cc);
            // for (Command command : commands) {
            // }
            propaHadoopCfgChanges(selectedNode);
            draw2dPosition = draw2dPosition.getCopy();
            draw2dPosition.x += TalendEditor.GRID_SIZE;
            draw2dPosition.y += TalendEditor.GRID_SIZE;
            node.checkNode();
            lastUniqname = node.getUniqueName();
        }
    // setselecte(part, lastUniqname);
    }
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
Also used : IComponent(org.talend.core.model.components.IComponent) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) Iterator(java.util.Iterator) IElementParameter(org.talend.core.model.process.IElementParameter) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFigure(org.eclipse.draw2d.IFigure) Point(org.eclipse.draw2d.geometry.Point) Canvas(org.eclipse.swt.widgets.Canvas) Point(org.eclipse.draw2d.geometry.Point) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 3 with Canvas

use of org.eclipse.swt.widgets.Canvas in project tdi-studio-se by Talend.

the class CreateRelationAction method run.

@Override
public void run() {
    if (getSelectedObjects().isEmpty()) {
        return;
    }
    List parts = getSelectedObjects();
    if (parts.size() == 1) {
        Object o = parts.get(0);
        if (!(o instanceof ColumnPart)) {
            return;
        }
        columnPart = (ColumnPart) o;
    } else {
        return;
    }
    /**
         * Create a mouse down event that thinks it is over the blob and dispatch it. This is a bit of a fudge to mimic
         * what the user ought to do.
         */
    Point point = null;
    point = columnPart.getFigure().getClientArea().getCenter();
    Point p = point;
    columnPart.getFigure().translateToAbsolute(p);
    Canvas canvas = (Canvas) columnPart.getViewer().getControl();
    Event event = new Event();
    event.button = 1;
    event.count = 0;
    event.detail = 0;
    event.end = 0;
    event.height = 0;
    event.keyCode = 0;
    event.start = 0;
    event.stateMask = 0;
    // any old time... doesn't matter
    event.time = 9516624;
    event.type = 3;
    event.widget = canvas;
    event.width = 0;
    event.x = p.x + 3;
    event.y = p.y + 3;
    WhereConnectionCreationTool tool = new WhereConnectionCreationTool(new CreationFactory() {

        public Object getNewObject() {
            return null;
        }

        public Object getObjectType() {
            return null;
        }
    });
    columnPart.getViewer().getEditDomain().setActiveTool(tool);
    canvas.notifyListeners(3, event);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) CreationFactory(org.eclipse.gef.requests.CreationFactory) ColumnPart(org.talend.sqlbuilder.erdiagram.ui.parts.ColumnPart) Event(org.eclipse.swt.widgets.Event) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point)

Example 4 with Canvas

use of org.eclipse.swt.widgets.Canvas in project dbeaver by serge-rider.

the class ERDOutlinePage method createControl.

/* (non-Javadoc)
     * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
     */
@Override
public void createControl(Composite parent) {
    // create canvas and lws
    overview = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(overview);
    // create thumbnail
    thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Example 5 with Canvas

use of org.eclipse.swt.widgets.Canvas in project translationstudio8 by heartsome.

the class NatCombo method createTextControl.

private void createTextControl() {
    text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
    text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(gridData);
    text.forceFocus();
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = dropdownList.getSelectionIndex();
                selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
                if (selectionIndex < 0) {
                    selectionIndex = 0;
                }
                dropdownList.select(selectionIndex);
                text.setText(dropdownList.getSelection()[0]);
            }
        }
    });
    iconImage = GUIHelper.getImage("down_2");
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = iconImage.getBounds();
            return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
        }
    };
    gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
    iconCanvas.setLayoutData(gridData);
    iconCanvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
            Color originalFg = gc.getForeground();
            gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
            gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
            gc.setForeground(originalFg);
        }
    });
    iconCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showDropdownControl();
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) GC(org.eclipse.swt.graphics.GC)

Aggregations

Canvas (org.eclipse.swt.widgets.Canvas)111 GridData (org.eclipse.swt.layout.GridData)47 GridLayout (org.eclipse.swt.layout.GridLayout)38 Composite (org.eclipse.swt.widgets.Composite)38 PaintEvent (org.eclipse.swt.events.PaintEvent)36 PaintListener (org.eclipse.swt.events.PaintListener)35 Point (org.eclipse.swt.graphics.Point)32 Rectangle (org.eclipse.swt.graphics.Rectangle)32 Label (org.eclipse.swt.widgets.Label)31 Text (org.eclipse.swt.widgets.Text)24 Button (org.eclipse.swt.widgets.Button)22 Color (org.eclipse.swt.graphics.Color)20 Shell (org.eclipse.swt.widgets.Shell)20 MouseEvent (org.eclipse.swt.events.MouseEvent)18 GC (org.eclipse.swt.graphics.GC)17 FillLayout (org.eclipse.swt.layout.FillLayout)17 Event (org.eclipse.swt.widgets.Event)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)16 Listener (org.eclipse.swt.widgets.Listener)16 Display (org.eclipse.swt.widgets.Display)15