Search in sources :

Example 26 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisColumnSetTreeViewer method addItemElements.

private void addItemElements(final ModelElementIndicator[] elements) {
    // MOD qiongli 2011-1-27,change TdColumn to MetadataColumn for supporting delimited file.
    for (ModelElementIndicator element2 : elements) {
        final ModelElementIndicator meIndicator = element2;
        final ModelElement modelElement = RepositoryNodeHelper.getSubModelElement(meIndicator.getModelElementRepositoryNode());
        final TreeItem treeItem = new TreeItem(tree, SWT.NONE);
        MetadataHelper.setDefaultDataminingType(modelElement);
        columnSetMultiValueList.add(meIndicator.getModelElementRepositoryNode());
        treeItem.setImage(ImageLib.getImage(ImageLib.TD_COLUMN));
        treeItem.setText(0, getModelElemetnDisplayName(meIndicator));
        treeItem.setData(COLUMN_INDICATOR_KEY, modelElement);
        treeItem.setData(MODELELEMENT_INDICATOR_KEY, meIndicator);
        // MOD mzhao feature 13040 , 2010-05-21
        TreeEditor comboEditor = new TreeEditor(tree);
        final CCombo combo = new CCombo(tree, SWT.BORDER);
        for (DataminingType type : DataminingType.values()) {
            // MODSCA 2008-04-10 use literal
            combo.add(type.getLiteral());
        // for presentation
        }
        DataminingType dataminingType = MetadataHelper.getDataminingType(modelElement);
        if (dataminingType == null) {
            combo.select(0);
        } else {
            combo.setText(dataminingType.getLiteral());
        }
        combo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                MetadataHelper.setDataminingType(DataminingType.get(combo.getText()), modelElement);
                setDirty(true);
            }
        });
        combo.setEditable(false);
        comboEditor.minimumWidth = WIDTH1_CELL;
        comboEditor.setEditor(combo, treeItem, 1);
        TreeEditor addPatternEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label addPatternLabl = createTreeItemLabel(tree, ImageLib.ADD_PATTERN, "AnalysisColumnTreeViewer.addPattern");
        PatternMouseAdapter mouseAdapter = new PatternMouseAdapter(this, masterPage, meIndicator, treeItem);
        mouseAdapter.addFilter(new ViewerFilter() {

            @Override
            public boolean select(Viewer viewer, Object parentElement, Object element) {
                if (element instanceof IFolder) {
                    IFolder folder = (IFolder) element;
                    // $NON-NLS-1$
                    return !folder.getName().endsWith("SQL");
                }
                return true;
            }
        });
        addPatternLabl.addMouseListener(mouseAdapter);
        addPatternEditor.minimumWidth = addPatternLabl.getImage().getBounds().width;
        addPatternEditor.setEditor(addPatternLabl, treeItem, 2);
        TreeEditor delLabelEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisColumnTreeViewer.delete");
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                deleteColumnItems(meIndicator.getModelElementRepositoryNode());
                if (treeItem.getParentItem() != null && treeItem.getParentItem().getData(INDICATOR_UNIT_KEY) != null) {
                    setElements(modelElementIndicators);
                } else {
                    deleteIndicatorItems(meIndicator);
                    removeItemBranch(treeItem);
                    enabledButtons(false);
                }
                notifyObservers();
            }
        });
        delLabelEditor.minimumWidth = delLabel.getImage().getBounds().width;
        delLabelEditor.horizontalAlignment = SWT.CENTER;
        delLabelEditor.setEditor(delLabel, treeItem, 3);
        treeItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { comboEditor, addPatternEditor, delLabelEditor });
        if (meIndicator.hasIndicators()) {
            createIndicatorItems(treeItem, meIndicator.getIndicatorUnits());
        }
        delLabelEditor.layout();
        treeItem.setExpanded(false);
    }
    tree.layout();
    tree.redraw();
    this.setDirty(true);
    tree.forceFocus();
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Viewer(org.eclipse.jface.viewers.Viewer) DataminingType(org.talend.dataquality.indicators.DataminingType) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) CCombo(org.eclipse.swt.custom.CCombo) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) IFolder(org.eclipse.core.resources.IFolder)

Example 27 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisColumnTreeViewer method addItemElements.

private void addItemElements(final ModelElementIndicator[] elements, boolean isExpandAll) {
    for (ModelElementIndicator element : elements) {
        final TreeItem treeItem = new TreeItem(tree, SWT.NONE);
        treeItem.setImage(ImageLib.getImage(ImageLib.TD_COLUMN));
        final ModelElementIndicator meIndicator = element;
        treeItem.setText(0, ModelElementIndicatorHelper.getModelElementDisplayName(meIndicator));
        treeItem.setData(MODELELEMENT_INDICATOR_KEY, meIndicator);
        TreeEditor comboEditor = new TreeEditor(tree);
        final CCombo combo = new CCombo(tree, SWT.BORDER);
        for (DataminingType type : DataminingType.values()) {
            // MODSCA 2008-04-10 use literal
            combo.add(type.getLiteral());
        // for presentation
        }
        final ModelElement modelElement = RepositoryNodeHelper.getSubModelElement(meIndicator.getModelElementRepositoryNode());
        DataminingType dataminingType = MetadataHelper.getDataminingType(modelElement);
        // MOD qiongli 2010-11-15 feature 16796
        if (meIndicator instanceof DelimitedFileIndicator) {
            dataminingType = MetadataHelper.getDefaultDataminingType(meIndicator.getJavaType());
        }
        if (dataminingType == null) {
            combo.select(0);
        } else {
            combo.setText(dataminingType.getLiteral());
        }
        combo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                MetadataHelper.setDataminingType(DataminingType.get(combo.getText()), modelElement);
                setDirty(true);
            }
        });
        combo.setEditable(false);
        comboEditor.minimumWidth = WIDTH1_CELL;
        comboEditor.setEditor(combo, treeItem, 1);
        TreeEditor addPatternEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label addPatternLabl = createTreeItemLabel(tree, ImageLib.ADD_PATTERN, "AnalysisColumnTreeViewer.addPattern");
        // MOD mzhao feature:13040, 2010-05-21
        addPatternLabl.addMouseListener(new PatternMouseAdapter(this, masterPage, meIndicator, treeItem));
        addPatternEditor.minimumWidth = addPatternLabl.getImage().getBounds().width;
        addPatternEditor.setEditor(addPatternLabl, treeItem, 2);
        // ADD xqliu 2010-02-23 feature 11617
        TreeEditor addUdiEditor = addColumnUdi(treeItem, meIndicator, 3);
        // ~
        TreeEditor delLabelEditor = new TreeEditor(tree);
        // $NON-NLS-1$
        Label delLabel = createTreeItemLabel(tree, ImageLib.DELETE_ACTION, "AnalysisColumnTreeViewer.delete");
        delLabel.setData(treeItem);
        delLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                // // here is the delLable which is behind of column, so need to remove current column and it's all
                // of
                TreeItem currentTreeItem = (TreeItem) e.widget.getData();
                removeSelectedElements(new TreeItem[] { currentTreeItem });
                notifyObservers();
            }
        });
        delLabelEditor.minimumWidth = delLabel.getImage().getBounds().width;
        delLabelEditor.horizontalAlignment = SWT.CENTER;
        delLabelEditor.setEditor(delLabel, treeItem, 4);
        treeItem.setData(ITEM_EDITOR_KEY, new TreeEditor[] { comboEditor, delLabelEditor, addPatternEditor, addUdiEditor });
        if (meIndicator.hasIndicators()) {
            createIndicatorItems(treeItem, meIndicator.getIndicatorUnits());
        }
        treeItem.setExpanded(isExpandAll);
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DataminingType(org.talend.dataquality.indicators.DataminingType) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) CCombo(org.eclipse.swt.custom.CCombo) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 28 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisColumnTreeViewer method addColumnUdi.

/**
 * DOC xqliu Comment method "addColumnUdi". ADD xqliu 2010-02-23 feature 11617
 *
 * @param treeItem
 * @param meIndicator
 * @param columnIndex
 * @return
 */
private TreeEditor addColumnUdi(final TreeItem treeItem, final ModelElementIndicator meIndicator, int columnIndex) {
    TreeEditor addUdiEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    Label addUdiLabl = createTreeItemLabel(tree, ImageLib.ADD_IND_DEFINITION, "AnalysisColumnTreeViewer.addUdi");
    addUdiLabl.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            DataManager dm = getAnalysis().getContext().getConnection();
            if (dm == null) {
                masterPage.doSave(null);
            }
            CheckedTreeSelectionDialog dialog = UDIUtils.createUdiCheckedTreeSelectionDialog(meIndicator);
            if (dialog.open() == Window.OK) {
                // MOD qiongli 2012-10-24 TDQ-6308,just remove some deselected indicatorUnit then set dirty to
                // true,just create new indicatorUnit for some new added UDI then set dirty to true.
                List<IndicatorDefinition> allSelectedIndicatorDefinitions = new ArrayList<IndicatorDefinition>();
                Set<String> allSelectedIndNames = new HashSet<String>();
                for (Object obj : dialog.getResult()) {
                    if (obj instanceof SysIndicatorDefinitionRepNode) {
                        IndicatorDefinition udid = ((SysIndicatorDefinitionRepNode) obj).getIndicatorDefinition();
                        allSelectedIndicatorDefinitions.add(udid);
                        if (udid != null) {
                            allSelectedIndNames.add(udid.getName());
                        }
                    }
                }
                Set<String> oldSelectedIndNames = new HashSet<String>();
                for (IndicatorUnit indicatorUnit : meIndicator.getIndicatorUnits()) {
                    Indicator indicator = indicatorUnit.getIndicator();
                    if (indicator instanceof UserDefIndicator) {
                        if (allSelectedIndNames.contains(indicator.getName())) {
                            oldSelectedIndNames.add(indicator.getName());
                        } else {
                            // remove the UDI from UI need to insert this UDI into removeList
                            deleteIndicatorItems(meIndicator, indicatorUnit);
                            if (!isDirty()) {
                                setDirty(true);
                            }
                        }
                    }
                }
                treeItem.removeAll();
                for (IndicatorDefinition udid : allSelectedIndicatorDefinitions) {
                    if (udid != null && oldSelectedIndNames.contains(udid.getName())) {
                        continue;
                    }
                    IndicatorUnit[] addIndicatorUnits = null;
                    try {
                        addIndicatorUnits = UDIUtils.createIndicatorUnit(udid, meIndicator, getAnalysis());
                    } catch (Throwable e1) {
                        log.warn(e1, e1);
                    }
                    if (addIndicatorUnits != null && addIndicatorUnits.length > 0) {
                        for (IndicatorUnit unit : addIndicatorUnits) {
                            createOneUnit(treeItem, unit);
                        }
                        if (!isDirty()) {
                            setDirty(true);
                        }
                    }
                }
                treeItem.setExpanded(true);
                masterPage.refreshTheTree(masterPage.getCurrentModelElementIndicators());
            }
        }
    });
    addUdiEditor.minimumWidth = addUdiLabl.getImage().getBounds().width;
    addUdiEditor.setEditor(addUdiLabl, treeItem, columnIndex);
    return addUdiEditor;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) Set(java.util.Set) HashSet(java.util.HashSet) TreeEditor(org.eclipse.swt.custom.TreeEditor) CheckedTreeSelectionDialog(org.eclipse.ui.dialogs.CheckedTreeSelectionDialog) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) DelimitedFileIndicator(org.talend.dataprofiler.core.model.DelimitedFileIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Indicator(org.talend.dataquality.indicators.Indicator) CompositeIndicator(org.talend.dataquality.indicators.CompositeIndicator) SysIndicatorDefinitionRepNode(org.talend.dq.nodes.SysIndicatorDefinitionRepNode) List(java.util.List) ArrayList(java.util.ArrayList) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) MetadataXmlElementTypeRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataXmlElementTypeRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator)

Example 29 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class AnalysisTableTreeViewer method removeItemBranch.

@Override
protected void removeItemBranch(TreeItem item) {
    if (item == null) {
        return;
    }
    TreeEditor[] editors = (TreeEditor[]) item.getData(ITEM_EDITOR_KEY);
    if (editors != null) {
        for (TreeEditor editor : editors) {
            editor.getEditor().dispose();
            editor.dispose();
        }
    }
    if (item.getItemCount() == 0) {
        item.dispose();
        this.setDirty(true);
        return;
    }
    TreeItem[] items = item.getItems();
    for (TreeItem item2 : items) {
        removeItemBranch(item2);
        removeTreeItem(item2);
    }
    item.dispose();
    this.setDirty(true);
}
Also used : TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 30 with TreeEditor

use of org.eclipse.swt.custom.TreeEditor in project tdq-studio-se by Talend.

the class IndicatorsComp method createOneUnit.

/**
 * create element on the tree by indicatorUnit
 *
 * @param indicator
 */
public void createOneUnit(ColumnSetIndicatorUnit indicatorUnit) {
    final TreeItem indicatorItem = new TreeItem(this.tree, SWT.NONE);
    indicatorItem.setData(INDICATOR_KEY, indicatorUnit);
    indicatorItem.setImage(0, ImageLib.getImage(ImageLib.IND_DEFINITION));
    String indicatorName = indicatorUnit.getIndicatorName();
    // $NON-NLS-1$
    String label = indicatorName == null ? "unknown indicator" : indicatorName;
    indicatorItem.setText(0, label);
    TreeEditor optionEditor;
    optionEditor = new TreeEditor(tree);
    // $NON-NLS-1$
    final Label optionLabel = createTreeItemLabel(tree, ImageLib.OPTION, "AnalysisColumnTreeViewer.options");
    optionLabel.setData(indicatorUnit);
    optionLabel.addMouseListener(new MouseAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt .events.MouseEvent)
             */
        @Override
        public void mouseDown(MouseEvent e) {
            if (openIndicatorOptionDialog(Display.getCurrent().getActiveShell(), indicatorItem)) {
                optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
            }
        }
    });
    optionEditor.minimumWidth = optionLabel.getImage().getBounds().width;
    optionEditor.horizontalAlignment = SWT.CENTER;
    optionEditor.setEditor(optionLabel, indicatorItem, 1);
    if (hasIndicatorParameters(indicatorUnit.getIndicator())) {
        optionLabel.setImage(ImageLib.getImage(ImageLib.INDICATOR_OPTION_CHECKED));
    }
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeEditor(org.eclipse.swt.custom.TreeEditor) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter)

Aggregations

TreeEditor (org.eclipse.swt.custom.TreeEditor)37 TreeItem (org.eclipse.swt.widgets.TreeItem)24 MouseEvent (org.eclipse.swt.events.MouseEvent)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 MouseAdapter (org.eclipse.swt.events.MouseAdapter)10 FocusEvent (org.eclipse.swt.events.FocusEvent)8 KeyEvent (org.eclipse.swt.events.KeyEvent)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Point (org.eclipse.swt.graphics.Point)8 Label (org.eclipse.swt.widgets.Label)8 CCombo (org.eclipse.swt.custom.CCombo)5 Control (org.eclipse.swt.widgets.Control)5 FocusAdapter (org.eclipse.swt.events.FocusAdapter)4 KeyAdapter (org.eclipse.swt.events.KeyAdapter)4 Text (org.eclipse.swt.widgets.Text)4 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CTabFolderEvent (org.eclipse.swt.custom.CTabFolderEvent)3 DragSourceEvent (org.eclipse.swt.dnd.DragSourceEvent)3