public boolean validateDrop(Object target, int operation, TransferData transferType) { if (transferType != null && ResourceTransfer.getInstance().isSupportedType(transferType)) { return true; } return super.validateDrop(target, operation, transferType); }
/** Implementation of method defined on <code>IAction</code>. */ @Override public void run() { // try a resource transfer ResourceTransfer resTransfer = ResourceTransfer.getInstance(); IResource[] resourceData = (IResource[]) clipboard.getContents(resTransfer); if (resourceData != null && resourceData.length > 0) { if (resourceData[0].getType() == IResource.PROJECT) { // enablement checks for all projects for (int i = 0; i < resourceData.length; i++) { CopyProjectOperation operation = new CopyProjectOperation(shell); operation.copyProject((IProject) resourceData[i]); } } else { // enablement should ensure that we always have access to a container IContainer container = getContainer(); CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell); operation.copyResources(resourceData, container); } return; } // try a file transfer FileTransfer fileTransfer = FileTransfer.getInstance(); String[] fileData = (String[]) clipboard.getContents(fileTransfer); if (fileData != null) { // enablement should ensure that we always have access to a container IContainer container = getContainer(); CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell); operation.copyFiles(fileData, container); } }
@Override public Transfer[] getSupportedTransferTypes() { return new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), EditorInputTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }; }
/** Configure outline viewer. */ protected void configureOutlineViewer() { final EditPartViewer viewer = getViewer(); viewer.setEditDomain(editor.getEditDomain()); viewer.setEditPartFactory(getEditPartFactory()); ContextMenuProvider provider = getMenuContentProvider(); viewer.setContextMenu(provider); viewer.addDropTargetListener(new JSSTemplateTransferDropTargetListener(viewer)); viewer.addDragSourceListener( new TemplateTransferDragSourceListener(viewer) { @Override protected Object getTemplate() { List<Object> models = new ArrayList<Object>(); Object obj = super.getTemplate(); if (obj == null) { List<?> selection = getViewer().getSelectedEditParts(); for (Object it : selection) { if (it instanceof EditPart) { Object model = ((EditPart) it).getModel(); if (model instanceof IDragable) { models.add(model); } if (model instanceof MBand) { BandTypeEnum bandType = ((MBand) model).getBandType(); if (BandTypeEnum.DETAIL.equals(bandType) || BandTypeEnum.GROUP_FOOTER.equals(bandType) || BandTypeEnum.GROUP_HEADER.equals(bandType)) { models.add(model); } } } } } return models; } }); // Add images drop listeners viewer.addDropTargetListener( new ImageResourceDropTargetListener(viewer, ResourceTransfer.getInstance())); viewer.addDropTargetListener( new ImageResourceDropTargetListener(viewer, FileTransfer.getInstance())); viewer.addDropTargetListener( new ImageResourceDropTargetListener(viewer, ImageURLTransfer.getInstance())); IPageSite site = getSite(); site.registerContextMenu(provider.getId(), provider, site.getSelectionProvider()); IToolBarManager tbm = site.getActionBars().getToolBarManager(); registerToolbarAction(tbm); showPage(ID_ACTION_OUTLINE); }
/** * Set the clipboard contents. Prompt to retry if clipboard is busy. * * @param resources the resources to copy to the clipboard * @param fileNames file names of the resources to copy to the clipboard * @param names string representation of all names */ private void setClipboard(IResource[] resources, String[] fileNames, String names) { try { // set the clipboard contents if (fileNames.length > 0) { clipboard.setContents( new Object[] {resources, fileNames, names}, new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() }); } else { clipboard.setContents( new Object[] {resources, names}, new Transfer[] {ResourceTransfer.getInstance(), TextTransfer.getInstance()}); } } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) throw e; if (MessageDialog.openQuestion( shell, CViewMessages.CopyToClipboardProblemDialog_title, CViewMessages.CopyToClipboardProblemDialog_message)) setClipboard(resources, fileNames, names); } }
/* * (non-Javadoc) * * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent, * org.eclipse.jface.viewers.IStructuredSelection) */ public boolean setDragData(DragSourceEvent anEvent, IStructuredSelection aSelection) { IResource[] resources = getSelectedResources(aSelection); if (resources.length > 0) { if (ResourceTransfer.getInstance().isSupportedType(anEvent.dataType)) { anEvent.data = resources; if (Policy.DEBUG_DND) { System.out.println( "ResourceDragAdapterAssistant.dragSetData set ResourceTransfer"); //$NON-NLS-1$ } return true; } if (FileTransfer.getInstance().isSupportedType(anEvent.dataType)) { // Get the path of each file and set as the drag data final int length = resources.length; int actualLength = 0; String[] fileNames = new String[length]; for (int i = 0; i < length; i++) { IPath location = resources[i].getLocation(); // location may be null. See bug 29491. if (location != null) { fileNames[actualLength++] = location.toOSString(); } } if (actualLength > 0) { // was one or more of the locations null? if (actualLength < length) { String[] tempFileNames = fileNames; fileNames = new String[actualLength]; for (int i = 0; i < actualLength; i++) fileNames[i] = tempFileNames[i]; } anEvent.data = fileNames; if (Policy.DEBUG_DND) System.out.println( "ResourceDragAdapterAssistant.dragSetData set FileTransfer"); //$NON-NLS-1$ return true; } } } return false; }
/** * Clients may reference this class in the <b>dragAssistant</b> element of a * <b>org.eclipse.ui.navigator.viewer</b> extension point. * * <p>Clients may not extend or instantiate this class for any purpose other than {@link * INavigatorDnDService#bindDragAssistant(CommonDragAdapterAssistant)}. Clients may have no direct * dependencies on the contract of this class. * * @since 3.2 * @noextend This class is not intended to be subclassed by clients. */ public class ResourceDragAdapterAssistant extends CommonDragAdapterAssistant { private static final Transfer[] SUPPORTED_TRANSFERS = new Transfer[] {ResourceTransfer.getInstance(), FileTransfer.getInstance()}; private static final Class<IResource> IRESOURCE_TYPE = IResource.class; /* * (non-Javadoc) * * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes() */ public Transfer[] getSupportedTransferTypes() { return SUPPORTED_TRANSFERS; } /* * (non-Javadoc) * * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent, * org.eclipse.jface.viewers.IStructuredSelection) */ public boolean setDragData(DragSourceEvent anEvent, IStructuredSelection aSelection) { IResource[] resources = getSelectedResources(aSelection); if (resources.length > 0) { if (ResourceTransfer.getInstance().isSupportedType(anEvent.dataType)) { anEvent.data = resources; if (Policy.DEBUG_DND) { System.out.println( "ResourceDragAdapterAssistant.dragSetData set ResourceTransfer"); //$NON-NLS-1$ } return true; } if (FileTransfer.getInstance().isSupportedType(anEvent.dataType)) { // Get the path of each file and set as the drag data final int length = resources.length; int actualLength = 0; String[] fileNames = new String[length]; for (int i = 0; i < length; i++) { IPath location = resources[i].getLocation(); // location may be null. See bug 29491. if (location != null) { fileNames[actualLength++] = location.toOSString(); } } if (actualLength > 0) { // was one or more of the locations null? if (actualLength < length) { String[] tempFileNames = fileNames; fileNames = new String[actualLength]; for (int i = 0; i < actualLength; i++) fileNames[i] = tempFileNames[i]; } anEvent.data = fileNames; if (Policy.DEBUG_DND) System.out.println( "ResourceDragAdapterAssistant.dragSetData set FileTransfer"); //$NON-NLS-1$ return true; } } } return false; } private IResource[] getSelectedResources(IStructuredSelection aSelection) { Set<IResource> resources = new LinkedHashSet<IResource>(); IResource resource = null; for (Iterator<?> iter = aSelection.iterator(); iter.hasNext(); ) { Object selected = iter.next(); resource = adaptToResource(selected); if (resource != null) { resources.add(resource); } } return resources.toArray(new IResource[resources.size()]); } private IResource adaptToResource(Object selected) { IResource resource; if (selected instanceof IResource) { resource = (IResource) selected; } else if (selected instanceof IAdaptable) { resource = (IResource) ((IAdaptable) selected).getAdapter(IRESOURCE_TYPE); } else { resource = (IResource) Platform.getAdapterManager().getAdapter(selected, IRESOURCE_TYPE); } return resource; } }
@Override public void createPartControl(Composite parent) { fileManager = new FileManager(new SetupContextHelper()); parent.setLayout(new GridLayout()); viewer = new TableViewer(parent); viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); viewer.setLabelProvider(new ViewLabelProvider()); viewer.setContentProvider(new BasicContentProvider()); viewer.setInput(fileManager); viewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (event.getSelection() instanceof StructuredSelection) { inputData = null; eventManager.sendInputDataUpdate(null); selectedFile = (String) ((StructuredSelection) event.getSelection()).getFirstElement(); update(currentOperation); } } }); ColumnViewerToolTipSupport.enableFor(viewer); DropTargetAdapter dropListener = new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { Object dropData = event.data; if (dropData instanceof TreeSelection) { TreeSelection selectedNode = (TreeSelection) dropData; Object obj[] = selectedNode.toArray(); List<String> paths = new ArrayList<String>(); for (int i = 0; i < obj.length; i++) { if (obj[i] instanceof IFile) { IFile file = (IFile) obj[i]; paths.add(file.getLocation().toOSString()); } } if (!paths.isEmpty()) fileManager.addFiles(paths.toArray(new String[paths.size()])); } else if (dropData instanceof String[]) { fileManager.addFiles((String[]) dropData); } viewer.setInput(fileManager); } }; DropTarget dt = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_DEFAULT | DND.DROP_COPY); dt.setTransfer( new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }); dt.addDropListener(dropListener); csw = new ChangeSliceWidget(parent); csw.addSliceChangeListener( new ISliceChangeListener() { @Override public void sliceChanged(SliceChangeEvent event) { inputData = null; eventManager.sendInputDataUpdate(null); String ss = Slice.createString(csw.getCurrentSlice()); currentSliceLabel.setText("Current slice of data: [" + ss + "]"); currentSliceLabel.getParent().layout(true); update(currentOperation); } }); csw.disable(); final MenuManager rightClick = new MenuManager(); createActions(rightClick); viewer.getControl().setMenu(rightClick.createContextMenu(viewer.getControl())); getSite() .getPage() .addSelectionListener( "org.dawnsci.processing.ui.processingView", new ISelectionListener() { @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof StructuredSelection && ((StructuredSelection) selection).getFirstElement() instanceof OperationDescriptor) { OperationDescriptor des = (OperationDescriptor) ((StructuredSelection) selection).getFirstElement(); try { currentOperation = des.getSeriesObject(); update(currentOperation); } catch (InstantiationException e) { logger.error(e.getMessage(), e); } } else { if (getOperations() == null || getOperations().length == 0) { output.clear(); } } } }); currentSliceLabel = new Label(parent, SWT.WRAP); currentSliceLabel.setText("Current slice of data: [ - - - - -]"); IWorkbenchPage page = getSite().getPage(); IViewPart view = page.findView("org.dawnsci.processing.ui.output"); output = (IPlottingSystem<Composite>) view.getAdapter(IPlottingSystem.class); view = page.findView("org.dawnsci.processing.ui.input"); input = (IPlottingSystem<Composite>) view.getAdapter(IPlottingSystem.class); fileManager.addFileListener( new IFilesAddedListener() { @Override public void filesAdded(FileAddedEvent event) { String[] paths = event.getPaths(); boolean[] success = event.getSuccess(); int first = -1; final List<String> failedPaths = new ArrayList<String>(); for (int i = 0; i < success.length; i++) { if (success[i] && first < 0) first = i; if (!success[i]) failedPaths.add(paths[i]); } String dsName = ""; try { dsName = " (" + fileManager.getContext().getDatasetNames().get(0) + ")"; } catch (Exception e) { // ignore } final String dsn = dsName; final int f = first; Display.getDefault() .syncExec( new Runnable() { @Override public void run() { if (f < 0) { MessageDialog.openError( getSite().getShell(), "Error loading files", "None of the selected files contained suitable datasets" + dsn + "!"); return; } if (!failedPaths.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("Failed to load: "); for (String p : failedPaths) sb.append(p + ", "); sb.append("did not contain suitable datasets"); sb.append(dsn); MessageDialog.openError( getSite().getShell(), "Error loading some files", sb.toString()); } } }); if (f < 0) return; final String path = paths[first]; Display.getDefault() .syncExec( new Runnable() { @Override public void run() { viewer.refresh(); viewer.setSelection(new StructuredSelection(path), true); } }); } }); eventManager.addOperationRunnerListener( new IOperationGUIRunnerListener.Stub() { @Override public void updateRequested() { update(currentOperation); } }); // hook up delete key to remove from list viewer .getTable() .addKeyListener( new KeyListener() { @Override public void keyReleased(KeyEvent e) {} @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL) { clearSelected(); } } }); }
void createSection(Section section, FormToolkit toolkit) { // Toolbar buttons ToolBar toolbar = new ToolBar(section, SWT.FLAT); section.setTextClient(toolbar); fillToolBar(toolbar); Composite composite = toolkit.createComposite(section); section.setClient(composite); table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); viewer = new TableViewer(table); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new VersionedClauseLabelProvider()); // Listeners viewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ToolItem remove = getRemoveItemTool(); if (remove != null) remove.setEnabled(!viewer.getSelection().isEmpty()); } }); ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) { @Override public void dragEnter(DropTargetEvent event) { super.dragEnter(event); event.detail = DND.DROP_COPY; } @Override public boolean validateDrop(Object target, int operation, TransferData transferType) { if (FileTransfer.getInstance().isSupportedType(transferType)) { return true; } else if (ResourceTransfer.getInstance().isSupportedType(transferType)) { return true; } else { ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { return false; } Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (!(element instanceof RepositoryBundle) && !(element instanceof RepositoryBundleVersion) && !(element instanceof ProjectBundle)) { return false; } } return true; } } @Override public boolean performDrop(Object data) { if (data instanceof String[]) { return handleFileNameDrop((String[]) data); } else if (data instanceof IResource[]) { return handleResourceDrop((IResource[]) data); } else { return handleSelectionDrop(); } } private boolean handleResourceDrop(IResource[] resources) { File[] files = new File[resources.length]; for (int i = 0; i < resources.length; i++) { files[i] = resources[i].getLocation().toFile(); } return handleFileDrop(files); } private boolean handleFileNameDrop(String[] paths) { File[] files = new File[paths.length]; for (int i = 0; i < paths.length; i++) { files[i] = new File(paths[i]); } return handleFileDrop(files); } private boolean handleFileDrop(File[] files) { if (files.length > 0) { IPreferenceStore store = Plugin.getDefault().getPreferenceStore(); boolean hideWarning = store.getBoolean(Plugin.PREF_HIDE_WARNING_EXTERNAL_FILE); if (!hideWarning) { MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning( getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null); if (Window.CANCEL == dialog.getReturnCode()) return false; if (dialog.getToggleState()) { store.setValue(Plugin.PREF_HIDE_WARNING_EXTERNAL_FILE, true); } } AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files); WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard); if (Window.OK == dialog.open()) { List<Pair<String, String>> addingBundles = wizard.getSelectedBundles(); List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size()); for (Pair<String, String> addingBundle : addingBundles) { Map<String, String> attribs = new HashMap<String, String>(); attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond()); addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs)); } if (!addingClauses.isEmpty()) { bundles.addAll(addingClauses); viewer.add(addingClauses.toArray(new Object[addingClauses.size()])); markDirty(); } } return true; } return false; } private boolean handleSelectionDrop() { ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { return false; } List<VersionedClause> adding = new LinkedList<VersionedClause>(); Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); while (iterator.hasNext()) { Object item = iterator.next(); if (item instanceof RepositoryBundle) { String bsn = ((RepositoryBundle) item).getBsn(); adding.add(new VersionedClause(bsn, new HashMap<String, String>())); } else if (item instanceof RepositoryBundleVersion) { RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item; Map<String, String> attribs = new HashMap<String, String>(); attribs.put(Constants.VERSION_ATTRIBUTE, bundleVersion.getVersion().toString()); adding.add(new VersionedClause(bundleVersion.getBundle().getBsn(), attribs)); } else if (item instanceof ProjectBundle) { String bsn = ((ProjectBundle) item).getBsn(); Map<String, String> attribs = new HashMap<String, String>(); attribs.put(Constants.VERSION_ATTRIBUTE, "snapshot"); adding.add(new VersionedClause(bsn, attribs)); } } if (!adding.isEmpty()) { bundles.addAll(adding); viewer.add(adding.toArray(new Object[adding.size()])); markDirty(); } return true; } }; dropAdapter.setFeedbackEnabled(false); dropAdapter.setExpandEnabled(false); viewer.addDropSupport( DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance() }, dropAdapter); table.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.character == SWT.DEL) { doRemove(); } else if (e.character == '+') {; doAdd(); } } }); // Layout GridLayout layout = new GridLayout(1, false); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); GridData gd = getTableLayoutData(); table.setLayoutData(gd); }
public Transfer getTransfer() { return ResourceTransfer.getInstance(); }
@Override public void createPartControl(Composite parent) { // CREATE CONTROLS Composite mainPanel = new Composite(parent, SWT.NONE); Control filterPanel = filterPart.createControl(mainPanel, 5, 5); Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI); filterPanel.setBackground(tree.getBackground()); viewer = new TreeViewer(tree); viewer.setContentProvider(contentProvider); ColumnViewerToolTipSupport.enableFor(viewer); viewer.setLabelProvider(new RepositoryTreeLabelProvider(false)); getViewSite().setSelectionProvider(viewer); createActions(); JpmPreferences jpmPrefs = new JpmPreferences(); final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL; // LISTENERS filterPart.addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { String filter = (String) event.getNewValue(); updatedFilter(filter); } }); ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) { @Override public boolean validateDrop(Object target, int operation, TransferData transferType) { if (canDrop(target, transferType)) return true; boolean valid = false; if (target instanceof RepositoryPlugin) { if (((RepositoryPlugin) target).canWrite()) { if (URLTransfer.getInstance().isSupportedType(transferType)) return true; if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) { ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); if (selection instanceof IStructuredSelection) { for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) { Object element = iter.next(); if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) { valid = true; break; } if (element instanceof IFile) { valid = true; break; } if (element instanceof IAdaptable) { IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class); if (file != null) { valid = true; break; } } } } } else { valid = true; } } } return valid; } @Override public void dragEnter(DropTargetEvent event) { super.dragEnter(event); event.detail = DND.DROP_COPY; } @Override public boolean performDrop(Object data) { if (RepositoriesView.this.performDrop( getCurrentTarget(), getCurrentEvent().currentDataType)) { viewer.refresh(getCurrentTarget(), true); return true; } boolean copied = false; if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) { try { URL url = new URL( (String) URLTransfer.getInstance() .nativeToJava(getCurrentEvent().currentDataType)); File tmp = File.createTempFile("dwnl", ".jar"); IO.copy(url, tmp); copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] {tmp}); } catch (Exception e) { return false; } } else if (data instanceof String[]) { String[] paths = (String[]) data; File[] files = new File[paths.length]; for (int i = 0; i < paths.length; i++) { files[i] = new File(paths[i]); } copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files); } else if (data instanceof IResource[]) { IResource[] resources = (IResource[]) data; File[] files = new File[resources.length]; for (int i = 0; i < resources.length; i++) { files[i] = resources[i].getLocation().toFile(); } copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files); } else if (data instanceof IStructuredSelection) { File[] files = convertSelectionToFiles((IStructuredSelection) data); if (files != null && files.length > 0) copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files); } return copied; } }; dropAdapter.setFeedbackEnabled(false); dropAdapter.setExpandEnabled(false); viewer.addDropSupport( DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter); viewer.addDragSupport( DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] {LocalSelectionTransfer.getTransfer()}, new SelectionDragAdapter(viewer)); viewer.addSelectionChangedListener( new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { boolean writableRepoSelected = false; IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); Object element = selection.getFirstElement(); if (element instanceof RepositoryPlugin) { RepositoryPlugin repo = (RepositoryPlugin) element; writableRepoSelected = repo.canWrite(); } addBundlesAction.setEnabled(writableRepoSelected); } }); tree.addMouseListener( new MouseAdapter() { @Override public void mouseUp(MouseEvent ev) { Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (element instanceof ContinueSearchElement) { try { getViewSite() .getPage() .showView( Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE); } catch (PartInitException e) { Plugin.getDefault().getLog().log(e.getStatus()); } } } }); viewer.addDoubleClickListener( new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { if (!event.getSelection().isEmpty()) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); Object element = selection.getFirstElement(); if (element instanceof IAdaptable) { URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class); if (uri != null) { IWorkbenchPage page = getSite().getPage(); try { IFileStore fileStore = EFS.getLocalFileSystem().getStore(uri); IDE.openEditorOnFileStore(page, fileStore); } catch (PartInitException e) { logger.logError("Error opening editor for " + uri, e); } } } else if (element instanceof ContinueSearchElement) { ContinueSearchElement searchElement = (ContinueSearchElement) element; try { JpmPreferences jpmPrefs = new JpmPreferences(); if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) getViewSite() .getWorkbenchWindow() .getWorkbench() .getBrowserSupport() .getExternalBrowser() .openURL(new URL("https://www.jpm4j.org/" + searchElement.getFilter())); else getViewSite() .getPage() .showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e) { Plugin.getDefault().getLog().log(e.getStatus()); } catch (MalformedURLException e) { // ignore } } } } }); createContextMenu(); // LOAD Central.onWorkspaceInit( new Function<Workspace, Void>() { @Override public Void run(Workspace a) { final List<RepositoryPlugin> repositories = RepositoryUtils.listRepositories(true); SWTConcurrencyUtil.execForControl( viewer.getControl(), true, new Runnable() { @Override public void run() { viewer.setInput(repositories); } }); return null; } }); // LAYOUT GridLayout layout = new GridLayout(1, false); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; mainPanel.setLayout(layout); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); // Toolbar createActions(); fillToolBar(getViewSite().getActionBars().getToolBarManager()); // Register as repository listener registration = Activator.getDefault() .getBundleContext() .registerService(RepositoryListenerPlugin.class, this, null); }