use of org.eclipse.jface.util.LocalSelectionTransfer in project tdi-studio-se by Talend.
the class ComponentChooseDialog method getSelection.
private IStructuredSelection getSelection() {
LocalSelectionTransfer transfer = (LocalSelectionTransfer) getTransfer();
IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
return selection;
}
use of org.eclipse.jface.util.LocalSelectionTransfer in project tesb-studio-se by Talend.
the class CamelEditorDropTargetListener method checkSelectionSource.
/**
* Routelet and context types are validated
*
* @return true if validated
*/
private boolean checkSelectionSource() {
isContextSource = false;
selectSourceList.clear();
boolean isRouteletSource = false;
LocalSelectionTransfer transfer = (LocalSelectionTransfer) getTransfer();
IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
selectSourceList.add(obj);
isRouteletSource = true;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
selectSourceList.add(obj);
isContextSource = true;
}
} else if (obj instanceof PaletteEditPart) {
selectSourceList.add(obj);
Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
if (newObject != null && newObject instanceof INode) {
if (((INode) newObject).getComponent().getComponentType() == EComponentType.JOBLET) {
selectSourceList.add(newObject);
isRouteletSource = true;
}
}
}
}
if (selectSourceList.size() == 0) {
return false;
}
if (isRouteletSource) {
List<String> routeletList = new ArrayList<String>();
for (INode node : editor.getProcess().getGraphicalNodes()) {
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
routeletList.add(node.getComponent().getName());
}
}
boolean isDuplicateRoutelet = false;
String duplicatesName = "";
for (Object object : selectSourceList) {
if (object instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) object;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
if (routeletList.contains(sourceNode.getProperties(EProperties.LABEL))) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + sourceNode.getProperties(EProperties.LABEL);
}
}
} else if (object instanceof INode) {
INode node = (INode) object;
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
if (routeletList.contains(node.getComponent().getName())) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + node.getComponent().getName();
}
}
}
}
if (isDuplicateRoutelet) {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
editor.getEditorSite().getShell(), //$NON-NLS-1$
"Adding Routelet", //$NON-NLS-1$
"Do not allow duplicate Routelets\nRoutelet \"" + duplicatesName.substring(2) + "\" already exist.");
return false;
}
}
return true;
}
use of org.eclipse.jface.util.LocalSelectionTransfer in project bndtools by bndtools.
the class BundleCalculatedImportsPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
// CREATE COMPONENTS
section.setText(Messages.BundleCalculatedImportsPart_title);
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem showSelfImportsItem = new ToolItem(toolbar, SWT.CHECK);
showSelfImportsItem.setImage(imgShowSelfImports);
showSelfImportsItem.setToolTipText(Messages.BundleCalculatedImportsPart_tooltipShowSelfImports);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// toolkit.createLabel(composite,
// Messages.BundleCalculatedImportsPart_description, SWT.WRAP);
tree = toolkit.createTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
viewer = new TreeViewer(tree);
viewer.setContentProvider(new CapReqMapContentProvider());
viewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
ColumnViewerToolTipSupport.enableFor(viewer);
nonPkgFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof RequirementWrapper)
return PackageNamespace.PACKAGE_NAMESPACE.equals(((RequirementWrapper) element).requirement.getNamespace());
return true;
}
};
hideSelfImportsFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof RequirementWrapper)
return !((RequirementWrapper) element).resolved;
return true;
}
};
viewer.setFilters(new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter });
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getManagedForm().fireSelectionChanged(BundleCalculatedImportsPart.this, event.getSelection());
}
});
viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
if (transfer.isSupportedType(event.dataType))
transfer.setSelection(viewer.getSelection());
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
Object item = iter.next();
if (item instanceof Clazz) {
Clazz importUsedBy = (Clazz) item;
String className = importUsedBy.getFQN();
IType type = null;
IFile file = getEditorFile();
if (file != null) {
IJavaProject javaProject = JavaCore.create(file.getProject());
try {
type = javaProject.findType(className);
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, Messages.BundleCalculatedImportsPart_errorFindingType, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
try {
if (type != null)
JavaUI.openInEditor(type, true, true);
} catch (PartInitException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningJavaEditor, className), e));
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
}
}
});
// LISTENERS
showSelfImportsItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean showSelfImports = showSelfImportsItem.getSelection();
ViewerFilter[] filters = showSelfImports ? new ViewerFilter[] { nonPkgFilter } : new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter };
viewer.setFilters(filters);
}
});
// LAYOUT
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 2;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 75;
gd.widthHint = 75;
tree.setLayoutData(gd);
}
Aggregations