use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class ColumnsSelectionDialog method addCheckedListener.
/*
* (non-Javadoc)
*
* @seeorg.talend.dataprofiler.core.ui.dialog.TwoPartCheckSelectionDialog# addCheckedListener()
*/
@Override
protected void addCheckedListener() {
// When user checks a checkbox in the tree, check all its children
getTreeViewer().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
// Added TDQ-8718 20140506 yyin: should not load from db when checking
DQDBFolderRepositoryNode.setCallingFromColumnDialog(true);
DQDBFolderRepositoryNode.setLoadDBFromDialog(false);
try {
ColumnSelectionViewer columnViewer = (ColumnSelectionViewer) event.getSource();
TreePath treePath = new TreePath(new Object[] { event.getElement() });
columnViewer.setSelection(new TreeSelection(treePath));
setOutput(event.getElement());
RepositoryNode selectedNode = (RepositoryNode) event.getElement();
if (selectedNode instanceof DBTableRepNode || selectedNode instanceof DBViewRepNode || selectedNode instanceof DFTableRepNode) {
handleTreeElementsChecked(selectedNode, event.getChecked());
} else {
checkChildrenElements(selectedNode, event.getChecked());
}
getTreeViewer().setSubtreeChecked(event.getElement(), event.getChecked());
updateStatusBySelection();
} finally {
// Added TDQ-8718 20140506 yyin
DQDBFolderRepositoryNode.setCallingFromColumnDialog(false);
DQDBFolderRepositoryNode.setLoadDBFromDialog(true);
}
}
private void checkChildrenElements(RepositoryNode repNode, Boolean checkedFlag) {
Set<?> keySet = modelElementCheckedMap.keySet();
RepositoryNode[] repNodeArray = (RepositoryNode[]) modelElementCheckedMap.keySet().toArray(new RepositoryNode[keySet.size()]);
for (RepositoryNode reposNode : repNodeArray) {
RepositoryNode parentNode = reposNode.getParent();
while (parentNode != null) {
if (repNode.equals(parentNode)) {
handleTreeElementsChecked(reposNode, checkedFlag);
break;
} else {
parentNode = parentNode.getParent();
}
}
}
}
});
getTableViewer().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
handleTableElementsChecked((RepositoryNode) event.getElement(), event.getChecked());
updateStatusBySelection();
}
});
}
use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.
the class RemoveAnalysisAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
DQRespositoryView findView = CorePlugin.getDefault().getRepositoryView();
if (findView == null) {
return;
}
TreeSelection treeSelection = (TreeSelection) findView.getCommonViewer().getSelection();
TreePath[] paths = treeSelection.getPaths();
List<Analysis> analysisList;
Analysis analysisObj = null;
Map<TDQReportItem, List<Analysis>> removeMap = new HashMap<TDQReportItem, List<Analysis>>();
for (TreePath path : paths) {
Object lastSegment = path.getLastSegment();
if (!(lastSegment instanceof ReportAnalysisRepNode)) {
return;
}
// MOD sizhaoliu 2012-06-12 TDQ-5051 "Remove Anaysis" menu item is not in the right place
ReportAnalysisRepNode repNode = (ReportAnalysisRepNode) lastSegment;
analysisObj = repNode.getAnalysis();
TDQReportItem reportItem = repNode.getReportItem();
analysisList = removeMap.get(reportItem);
if (analysisList == null) {
analysisList = new ArrayList<Analysis>();
analysisList.add(analysisObj);
removeMap.put(reportItem, analysisList);
} else {
analysisList.add(analysisObj);
}
}
if (analysisObj == null) {
return;
}
String message = paths.length > 1 ? DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement0", // $NON-NLS-1$
paths.length) : // $NON-NLS-1$
DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement2", analysisObj.getName());
boolean openConfirm = MessageDialog.openConfirm(null, DefaultMessagesImpl.getString("RemoveAnalysisAction.confirmResourceDelete"), // $NON-NLS-1$
message);
if (openConfirm) {
Iterator<TDQReportItem> iterator = removeMap.keySet().iterator();
while (iterator.hasNext()) {
TDQReportItem reportItem = iterator.next();
ReportHelper.removeAnalyses((TdReport) reportItem.getReport(), removeMap.get(reportItem));
// save now modified resources (that contain the Dependency
// objects)
ElementWriterFactory.getInstance().createReportWriter().save(reportItem, true);
}
IFolder reportsFolder = ResourceManager.getReportsFolder();
try {
reportsFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
log.error(e, e);
}
findView.getCommonViewer().refresh();
}
}
use of org.eclipse.jface.viewers.TreePath in project titan.EclipsePlug-ins by eclipse.
the class WorkingDirectoryFilter method filter.
@Override
public Object[] filter(final Viewer viewer, final Object parent, final Object[] elements) {
workingDirectories = null;
Object tempParent = parent;
if (parent instanceof TreePath) {
tempParent = ((TreePath) parent).getLastSegment();
}
if (!(tempParent instanceof IResource)) {
return elements;
}
final IResource parentResource = (IResource) tempParent;
final IProject project = parentResource.getProject();
if (project == null) {
return elements;
}
workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
final int size = elements.length;
final List<Object> out = new ArrayList<Object>(size);
for (int i = 0; i < size; ++i) {
final Object element = elements[i];
if (specialSelect(viewer, tempParent, element)) {
out.add(element);
}
}
return out.toArray();
}
use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class GalleryViewerRow method getTreePath.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ViewerRow#getTreePath()
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public TreePath getTreePath() {
LinkedList path = new LinkedList();
path.add(item.getData());
GalleryItem curItem = item;
while (curItem.getParentItem() != null) {
path.addFirst(curItem.getParentItem().getData());
curItem = curItem.getParentItem();
}
return new TreePath(path.toArray());
}
use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class GalleryTreeViewer method remove.
/**
* Removes the element at the specified index of the parent. The selection
* is updated if required.
*
* @param parentOrTreePath
* the parent element, the input element, or a tree path to the
* parent element
* @param index
* child index
* @since 3.3
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void remove(final Object parentOrTreePath, final int index) {
// if (isBusy())
// return;
final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
preservingSelection(new Runnable() {
public void run() {
TreePath removedPath = null;
if (internalIsInputOrEmptyPath(parentOrTreePath)) {
Gallery gallery = (Gallery) getControl();
if (index < gallery.getItemCount()) {
GalleryItem item = gallery.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
} else {
Widget[] parentItems = internalFindItems(parentOrTreePath);
for (int i = 0; i < parentItems.length; i++) {
GalleryItem parentItem = (GalleryItem) parentItems[i];
if (index < parentItem.getItemCount()) {
GalleryItem item = parentItem.getItem(index);
if (item.getData() != null) {
removedPath = getTreePathFromItem(item);
disassociate(item);
}
item.dispose();
}
}
}
if (removedPath != null) {
boolean removed = false;
for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
TreePath path = (TreePath) it.next();
if (path.startsWith(removedPath, getComparer())) {
it.remove();
removed = true;
}
}
if (removed) {
setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
}
}
}
});
}
Aggregations