Search in sources :

Example 11 with IFigure

use of org.eclipse.draw2d.IFigure 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 12 with IFigure

use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.

the class ZoneContentLayout method layout.

@Override
public void layout(IFigure parent) {
    Rectangle vBounds = null;
    if (parent.getParent() instanceof Viewport) {
        vBounds = ((Viewport) parent.getParent()).getBounds();
    }
    int wHint = -1;
    int hHint = -1;
    if (isHorizontal()) {
        hHint = parent.getClientArea(Rectangle.SINGLETON).height;
    } else {
        wHint = parent.getClientArea(Rectangle.SINGLETON).width;
    }
    List children = parent.getChildren();
    int numChildren = children.size();
    Rectangle clientArea = transposer.t(parent.getClientArea());
    int x = clientArea.x;
    int y = clientArea.y;
    int availableHeight = clientArea.height;
    Dimension[] prefSizes = new Dimension[numChildren];
    Dimension[] minSizes = new Dimension[numChildren];
    IFigure child;
    int totalHeight = 0;
    int totalMinHeight = 0;
    int prefMinSumHeight = 0;
    int connSize = 0;
    // boolean isLookupConnMax = true;
    for (int i = 0; i < numChildren; i++) {
        child = (IFigure) children.get(i);
        prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
        minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
        totalHeight += prefSizes[i].height;
        totalMinHeight += minSizes[i].height;
        if (child instanceof AbstractTableContainer) {
            connSize = getLookupConnectionSize((AbstractTableContainer) child);
        }
    }
    totalHeight += (numChildren - 1) * spacing;
    totalMinHeight += (numChildren - 1) * spacing;
    prefMinSumHeight = totalHeight - totalMinHeight;
    int defaultSize = DEFAULT_OFFSET;
    for (int i = 0; i < numChildren; i++) {
        int amntShrinkCurrentHeight = 0;
        int prefHeight = prefSizes[i].height;
        int minHeight = minSizes[i].height;
        int prefWidth = prefSizes[i].width;
        int minWidth = minSizes[i].width;
        child = (IFigure) children.get(i);
        Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
        if (connSize > 0) {
            newBounds = new Rectangle(x + (connSize - 1) * defaultSize, y, prefWidth, prefHeight);
        }
        Border border = parent.getBorder();
        Insets insets = border.getInsets(child);
        if (vBounds != null) {
            newBounds.width = vBounds.width - insets.left - insets.right;
            if (connSize > 0) {
                newBounds.width = newBounds.width - (connSize - 1) * defaultSize;
            }
        }
        newBounds.height -= amntShrinkCurrentHeight;
        child.setBounds(transposer.t(newBounds));
        prefMinSumHeight -= (prefHeight - minHeight);
        y += newBounds.height + spacing;
    }
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractTableContainer(org.talend.designer.gefabstractmap.figures.table.AbstractTableContainer) Border(org.eclipse.draw2d.Border) IFigure(org.eclipse.draw2d.IFigure)

Example 13 with IFigure

use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.

the class ZoneToolBarLayout method layout.

@Override
public void layout(IFigure parent) {
    List children = parent.getChildren();
    int numChildren = children.size();
    Rectangle clientArea = parent.getClientArea();
    int x = clientArea.x + spacing;
    int y = clientArea.y;
    Dimension[] prefSizes = new Dimension[numChildren];
    Dimension[] minSizes = new Dimension[numChildren];
    int wHint = -1;
    int hHint = -1;
    if (isHorizontal()) {
        hHint = parent.getClientArea(Rectangle.SINGLETON).height;
    } else {
        wHint = parent.getClientArea(Rectangle.SINGLETON).width;
    }
    IFigure child;
    int totalHeight = 0;
    int totalMinHeight = 0;
    int maxHeight = 0;
    for (int i = 0; i < numChildren; i++) {
        child = (IFigure) children.get(i);
        prefSizes[i] = getChildPreferredSize(child, wHint, hHint);
        minSizes[i] = getChildMinimumSize(child, wHint, hHint);
        totalHeight += prefSizes[i].height;
        totalMinHeight += minSizes[i].height;
        maxHeight = Math.max(maxHeight, prefSizes[i].height);
    }
    totalHeight += (numChildren - 1) * spacing;
    totalMinHeight += (numChildren - 1) * spacing;
    y = y + (clientArea.height - maxHeight) / 2;
    for (int i = 0; i < numChildren; i++) {
        int prefHeight = prefSizes[i].height;
        int minHeight = minSizes[i].height;
        int prefWidth = prefSizes[i].width;
        Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
        child = (IFigure) children.get(i);
        child.setBounds(newBounds);
        x = x + newBounds.width + spacing;
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) IFigure(org.eclipse.draw2d.IFigure)

Example 14 with IFigure

use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.

the class RowSelectionEditPolicy method getLocatorFigure.

private IFigure getLocatorFigure(GraphicalEditPart owner) {
    IFigure figure = owner.getFigure();
    if (owner instanceof TableEntityPart) {
        TableEntityFigure treeNodeFigure = (TableEntityFigure) figure;
        // table figure to restrict the width
        MapperTablePart abstractInOutTreePart = MapperUtils.getMapperTablePart((TableEntityPart) owner);
        IFigure parentFigure = ((GraphicalEditPart) abstractInOutTreePart).getFigure();
        Rectangle treeBounds = parentFigure.getBounds();
        Rectangle rowBounds = treeNodeFigure.getElement().getBounds();
        Rectangle treeNodeBounds = figure.getBounds();
        figure = new Figure();
        if (treeBounds.x + 1 != treeNodeBounds.x || treeNodeBounds.width > treeBounds.width) {
            figure.setBounds(new Rectangle(treeBounds.x + 1, treeNodeBounds.y, treeBounds.width - 2, rowBounds.height));
            return figure;
        } else {
            figure.setBounds(owner.getFigure().getBounds().getCopy());
            figure.getBounds().height = rowBounds.height;
            return figure;
        }
    } else if (figure instanceof VarEntityFigure) {
        Rectangle copy = figure.getBounds().getCopy();
        figure = new Figure();
        figure.setBounds(copy);
        return figure;
    }
    return owner.getFigure();
}
Also used : VarEntityFigure(org.talend.designer.gefabstractmap.figures.var.VarEntityFigure) TableEntityPart(org.talend.designer.gefabstractmap.part.TableEntityPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) MapperTablePart(org.talend.designer.gefabstractmap.part.MapperTablePart) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure) TableEntityFigure(org.talend.designer.gefabstractmap.figures.table.entity.TableEntityFigure) IFigure(org.eclipse.draw2d.IFigure) VarEntityFigure(org.talend.designer.gefabstractmap.figures.var.VarEntityFigure) Figure(org.eclipse.draw2d.Figure)

Example 15 with IFigure

use of org.eclipse.draw2d.IFigure in project tdi-studio-se by Talend.

the class TableTreeEntityFigure method getContents.

@Override
public TreeAnimatingLayer getContents() {
    if (this.contentPane == null) {
        contentPane = new TreeAnimatingLayer() {

            public void setBounds(Rectangle rect) {
                int x = bounds.x, y = bounds.y;
                boolean resize = (rect.width != bounds.width) || (rect.height != bounds.height), translate = (rect.x != x) || (rect.y != y);
                if (isVisible() && (resize || translate))
                    erase();
                if (translate) {
                    int dx = rect.x - x;
                    int dy = rect.y - y;
                    primTranslate(dx, dy);
                }
                bounds.width = rect.width;
                bounds.height = rect.height;
                if (resize)
                    invalidate();
                if (resize || translate) {
                    fireFigureMoved();
                    fireCoordinateSystemChanged();
                    repaint();
                }
            }
        };
        ToolbarLayout layout = new ToolbarLayout() {

            @Override
            public void layout(IFigure parent) {
                TreeAnimation.recordInitialState(parent);
                if (TreeAnimation.playbackState(parent)) {
                    return;
                }
                super.layout(parent);
            }

            @Override
            protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
                return super.calculatePreferredSize(container, wHint, hHint);
            }
        };
        layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
        contentPane.setLayoutManager(layout);
        this.add(contentPane);
    // ///////test
    // contentPane.setOpaque(true);
    // contentPane.setBackgroundColor(ColorConstants.yellow);
    }
    return contentPane;
}
Also used : ToolbarLayout(org.eclipse.draw2d.ToolbarLayout) TreeAnimatingLayer(org.talend.commons.ui.swt.geftree.layout.TreeAnimatingLayer) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IFigure (org.eclipse.draw2d.IFigure)440 Rectangle (org.eclipse.draw2d.geometry.Rectangle)120 Point (org.eclipse.draw2d.geometry.Point)77 Dimension (org.eclipse.draw2d.geometry.Dimension)56 Figure (org.eclipse.draw2d.Figure)38 List (java.util.List)37 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)35 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)32 Graphics (org.eclipse.draw2d.Graphics)17 Iterator (java.util.Iterator)15 ArrayList (java.util.ArrayList)14 EditPart (org.eclipse.gef.EditPart)13 StackLayout (org.eclipse.draw2d.StackLayout)12 DefaultSizeNodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure)12 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)12 Insets (org.eclipse.draw2d.geometry.Insets)11 INodeFigure (org.whole.lang.ui.figures.INodeFigure)11 MarginBorder (org.eclipse.draw2d.MarginBorder)10 ToolbarLayout (org.eclipse.draw2d.ToolbarLayout)10 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)10