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