List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemPasteAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { fDestFileStores.clear();/* ww w.j a v a 2s . c o m*/ selectedFiles.clear(); fClipboardData = NO_FILES; if (!super.updateSelection(selection)) { return false; } if (selection == null || selection.isEmpty()) { return false; } Object[] elements = selection.toArray(); IFileStore fileStore; for (Object element : elements) { fileStore = getFileStore(element); if (fileStore != null) { if (!Utils.isDirectory(fileStore)) { fileStore = fileStore.getParent(); } fDestFileStores.add(fileStore); if (element instanceof IAdaptable) { IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class); if (resource != null) { selectedFiles.add((resource instanceof IContainer) ? resource : resource.getParent()); } else { selectedFiles.add(new FileSystemObject(fileStore, FileSystemUtils.getFileInfo(fileStore))); } } } } if (fDestFileStores.size() == 0) { return false; } fShell.getDisplay().syncExec(new Runnable() { public void run() { // clipboard must have files LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer(); Object contents = fClipboard.getContents(transfer); if (contents instanceof StructuredSelection) { Object[] elements = ((StructuredSelection) contents).toArray(); List<IFileStore> fileStores = new ArrayList<IFileStore>(); for (Object element : elements) { if (element instanceof IFileStore) { fileStores.add((IFileStore) element); } } fClipboardData = fileStores.toArray(new IFileStore[fileStores.size()]); } } }); if (fClipboardData.length > 0) { return true; } TransferData[] transfers = fClipboard.getAvailableTypes(); FileTransfer fileTransfer = FileTransfer.getInstance(); for (int i = 0; i < transfers.length; ++i) { if (fileTransfer.isSupportedType(transfers[i])) { return true; } } return false; }
From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemRefactorActionGroup.java
License:Open Source License
public void fillContextMenu(IMenuManager menu) { IStructuredSelection selection = getSelection(); if (selection != null && !selection.isEmpty()) { fRenameAction.selectionChanged(selection); menu.appendToGroup(ICommonMenuConstants.GROUP_REORGANIZE, fRenameAction); }/*w w w . j a v a 2 s . co m*/ }
From source file:com.aptana.ide.ui.io.navigator.actions.FileSystemRefreshAction.java
License:Open Source License
protected boolean updateSelection(IStructuredSelection selection) { fSelectedElements = null;/*from www . jav a2 s . c o m*/ if (selection != null && !selection.isEmpty()) { fSelectedElements = selection.toArray(); } return super.updateSelection(selection) && fSelectedElements != null; }
From source file:com.aptana.ide.ui.io.navigator.actions.NewFileAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { fSelectedElement = null;/*from w ww . j a v a 2s . c om*/ if (selection != null && !selection.isEmpty()) { Object element = selection.getFirstElement(); if (element instanceof IAdaptable) { fSelectedElement = (IAdaptable) element; } } return super.updateSelection(selection) && fSelectedElement != null; }
From source file:com.aptana.ide.ui.io.navigator.actions.NewFileTemplateMenuContributor.java
License:Open Source License
protected void createNewFileFromTemplate(final TemplateElement template) { IStructuredSelection selection = getActiveSelection(); if (!selection.isEmpty()) { Object element = selection.getFirstElement(); if (element instanceof IAdaptable) { IFileStore fileStore = (IFileStore) ((IAdaptable) element).getAdapter(IFileStore.class); if (fileStore != null) { // this is a non-workspace selection String filetype = template.getFiletype(); // strips the leading * before . if there is one int index = filetype.lastIndexOf('.'); if (index > -1) { filetype = filetype.substring(index); }//w ww.j ava2s . co m NewFileAction action = new NewFileAction("new_file" + filetype, template); //$NON-NLS-1$ action.updateSelection(selection); action.run(); return; } } } NewTemplateFileWizard wizard = new NewTemplateFileWizard(template); wizard.init(PlatformUI.getWorkbench(), selection); WizardDialog dialog = new WizardDialog(UIUtils.getActiveShell(), wizard); dialog.open(); }
From source file:com.aptana.ide.ui.io.navigator.actions.NewFileTemplateMenuContributor.java
License:Open Source License
protected void createNewBlankFile(String editorType, String fileExtension) { final String initialFileName = "new_file." + fileExtension; //$NON-NLS-1$ IStructuredSelection selection = getActiveSelection(); if (!selection.isEmpty()) { Object element = selection.getFirstElement(); if (element instanceof IAdaptable) { IFileStore fileStore = (IFileStore) ((IAdaptable) element).getAdapter(IFileStore.class); if (fileStore != null) { // this is a non-workspace selection NewFileAction action = new NewFileAction(initialFileName) { @Override/*www . jav a2s.c o m*/ protected InputStream getInitialContents() { // empty content return new ByteArrayInputStream(ArrayUtil.NO_BYTES); } }; action.updateSelection(selection); action.run(); return; } } } BasicNewFileResourceWizard wizard = new BasicNewFileResourceWizard() { @Override public void addPages() { super.addPages(); ((WizardNewFileCreationPage) getPages()[0]).setFileName(initialFileName); } }; wizard.init(PlatformUI.getWorkbench(), selection); WizardDialog dialog = new WizardDialog(UIUtils.getActiveShell(), wizard); dialog.open(); }
From source file:com.aptana.ide.ui.io.navigator.actions.NewFolderAction.java
License:Open Source License
protected boolean updateSelection(IStructuredSelection selection) { fSelectedElement = null;//from ww w . j av a2s . co m if (selection != null && !selection.isEmpty()) { Object element = selection.getFirstElement(); if (element instanceof IAdaptable) { fSelectedElement = (IAdaptable) element; } } return super.updateSelection(selection) && fSelectedElement != null; }
From source file:com.aptana.ide.ui.io.navigator.actions.OpenFileAction.java
License:Open Source License
public boolean updateSelection(IStructuredSelection selection) { fFileStores.clear();/* w w w . j a v a 2 s. c o m*/ if (selection != null && !selection.isEmpty()) { Object[] elements = selection.toArray(); IFileStore fileStore; for (Object element : elements) { if (element instanceof IAdaptable) { fileStore = Utils.getFileStore((IAdaptable) element); if (fileStore != null) { fFileStores.add(fileStore); } } } } return super.updateSelection(selection) && fFileStores.size() > 0; }
From source file:com.aptana.ide.ui.io.navigator.FilesystemLinkHelper.java
License:Open Source License
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return;/*from ww w. j a v a 2s. com*/ } Object element = aSelection.getFirstElement(); if (element instanceof FileSystemObject) { FileSystemObject file = (FileSystemObject) element; IFileStore fileStore = file.getFileStore(); try { IEditorPart editorPart = aPage.findEditor(UniformFileStoreEditorInputFactory .getUniformEditorInput(fileStore, new NullProgressMonitor())); aPage.bringToTop(editorPart); } catch (CoreException e) { IdeLog.logError(IOUIPlugin.getDefault(), e); } } }
From source file:com.aptana.js.debug.ui.internal.preferences.JSDetailFormattersPreferencePage.java
License:Open Source License
private void updatePage(IStructuredSelection selection) { removeFormatterButton.setEnabled(!selection.isEmpty()); editFormatterButton.setEnabled(selection.size() == 1); sourceViewer.getDocument()/*from ww w . j a v a 2 s. c o m*/ .set((selection.size() == 1) ? ((DetailFormatter) selection.getFirstElement()).getSnippet() : StringUtil.EMPTY); }