List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.nokia.s60ct.gui.eventListener.FeatureTreeListener.java
License:Open Source License
protected void processSelection(ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator iterator = structuredSelection.iterator(); iterator.hasNext();) callEditor(iterator.next()); }/*from www. j a v a 2 s . c om*/ }
From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java
License:Open Source License
/** * Download all selected files//from www .jav a 2 s . c om * @param viewer Viewer * @param contentProvider Content provider */ @SuppressWarnings("unchecked") static public void downloadFiles(TableViewer viewer, ViewContentProvider contentProvider) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); Object selectedObject = selection.getFirstElement(); if (selectedObject == null || !FtpFileObject.class.isInstance(selectedObject)) { // Nothing selected or selection is not file return; } // Show select folder dialog to user Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell(); DirectoryDialog dirDialog = new DirectoryDialog(sh, SWT.OPEN); dirDialog.setText(Messages.getString("FtpUtils.Select_Folder_DlgText")); //$NON-NLS-1$ dirDialog.setMessage(Messages.getString("FtpUtils.Select_Folder_DlgMsg")); //$NON-NLS-1$ String downloadFilterPath = RCPreferences.getDownloadLocation(); if (downloadFilterPath == "") { //$NON-NLS-1$ // Workspace root is used as default folder IPath location = ResourcesPlugin.getWorkspace().getRoot().getLocation(); dirDialog.setFilterPath(location.toString()); } else { // use last used folder dirDialog.setFilterPath(downloadFilterPath); } // Get user selected folder String destPath = dirDialog.open(); if (destPath == null) { // User is canceled dialog return; } // Remember last used folder RCPreferences.setDownloadLocation(destPath); destPath = addFileSepatorToEnd(destPath); // Full path for remote file String currentDirectory = getCurrentPath(contentProvider); IFtpObject ftpObject = null; String remoteFile = null; String destFile = null; FileDownloadJob job = null; // Download files Iterator iter = selection.iterator(); boolean canWrite; boolean replaceAll = false; while (iter.hasNext()) { canWrite = true; ftpObject = (IFtpObject) iter.next(); if (FtpFileObject.class.isInstance(ftpObject)) { // Folders are not downloaded // Full path for destination file destFile = destPath + ftpObject.getName(); remoteFile = currentDirectory + ftpObject.getName(); if (RCPreferences.getDownloadConfirm()) { // Confirm replace from user if file already exists File file = new File(destFile); if (file.exists() && !replaceAll) { // Show confirmation dialog ConfirmReplaceDialog dlg = new ConfirmReplaceDialog(sh, ftpObject.getName(), iter.hasNext(), ConfirmReplaceDialog.Operation.DOWNLOAD); dlg.open(); int sel = dlg.getSelection(); switch (sel) { case ConfirmReplaceDialog.RENAME_ID: // Rename this file RenameDialog renameDlg = new RenameDialog(sh, ftpObject.getName(), true, RENAME_FILE_DLG_NAME); if (renameDlg.open() == Dialog.CANCEL) { // User canceled dialog return; } // Get new file name from dialog. If user canceled dialog the original // filename is returned destFile = destPath + renameDlg.getFileName(); canWrite = true; break; case IDialogConstants.YES_ID: // Replace this file canWrite = true; break; case IDialogConstants.YES_TO_ALL_ID: // Replace all files replaceAll = true; break; case IDialogConstants.NO_ID: // Do not replace this file canWrite = false; break; case IDialogConstants.CANCEL_ID: // Cancel operation return; default: break; } } } if (canWrite) { job = new FileDownloadJob( Messages.getString("FtpUtils.Download_File_Job_Name") + ftpObject.getName(), //$NON-NLS-1$ remoteFile, destFile, false); job.setPriority(Job.DECORATE); job.schedule(); } } } }
From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java
License:Open Source License
/** * Deletes selected directories and files * @param viewer Viewer// w ww . jav a 2s. c o m * @param contentProvider Content provider */ @SuppressWarnings("unchecked") static public void delete(TableViewer viewer, ViewContentProvider contentProvider) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (RCPreferences.getDeleteConfirm()) { // Show confirmation dialog to user Shell sh = RemoteControlActivator.getCurrentlyActiveWbWindowShell(); ConfirmDeleteDialog dlg = new ConfirmDeleteDialog(sh); dlg.open(); if (dlg.getSelection() != IDialogConstants.YES_ID) { // Do not delete return; } } // Get current folder String path = getCurrentPath(contentProvider); // Delete all selected files and folders IFtpObject ftpObject = null; String dir = null; Iterator iter = selection.iterator(); while (iter.hasNext()) { ftpObject = (IFtpObject) iter.next(); // Add selected file/folder to path dir = path + ftpObject.getName(); if (FtpFolderObject.class.isInstance(ftpObject)) { // Start job for deleting folder DeleteDirJob job = new DeleteDirJob( Messages.getString("FtpUtils.Delete_Folder_Job_Name") + " " + dir, dir); //$NON-NLS-1$ //$NON-NLS-2$ job.schedule(); } else if (FtpFileObject.class.isInstance(ftpObject)) { // Start job for deleting file DeleteFileJob job = new DeleteFileJob( Messages.getString("FtpUtils.Delete_File_Job_Name") + " " + dir, dir); //$NON-NLS-1$ //$NON-NLS-2$ job.schedule(); } } }
From source file:com.nokia.s60tools.remotecontrol.ftp.ui.view.FtpUtils.java
License:Open Source License
/** * Returns files and folders that are currently selected in viewer. * @param viewer Viewer/* w w w. j av a 2 s. c om*/ * @param contentProvider Content provider * @return All currently selected file and folder names. */ @SuppressWarnings("unchecked") public static List<IFtpObject> getSelectedObjectNames(TableViewer viewer, ViewContentProvider contentProvider) { List<IFtpObject> selectedObjects = new ArrayList<IFtpObject>(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); // Get all selected files and folders IFtpObject ftpObject; Iterator iter = selection.iterator(); while (iter.hasNext()) { ftpObject = (IFtpObject) iter.next(); // Adding files and folders to list. if (FtpFileObject.class.isInstance(ftpObject) || FtpFolderObject.class.isInstance(ftpObject)) { selectedObjects.add(ftpObject); } } return selectedObjects; }
From source file:com.nokia.sdt.component.symbian.actions.VerticalMoveActionDelegate.java
License:Open Source License
private List<EObject> getEObjectListFromSelection(IStructuredSelection structuredSelection) { List<EObject> list = new ArrayList<EObject>(); for (Iterator iterator = structuredSelection.iterator(); iterator.hasNext();) { Object next = iterator.next(); if (next instanceof IAdaptable) { IComponentInstance ci = (IComponentInstance) ((IAdaptable) next) .getAdapter(IComponentInstance.class); if (ci != null) list.add(ci.getEObject()); }/*from w w w .j a v a2 s .c om*/ } return list; }
From source file:com.nokia.sdt.symbian.ui.appeditor.S60ApplicationEditorExtender.java
License:Open Source License
@SuppressWarnings("unchecked") private void pruneAppUiSelection() { // remove any items no longer in the model from the last appUi page selection List selItems = new ArrayList(); IStructuredSelection sel = (IStructuredSelection) lastAppUiPageSelection; for (Iterator iter = sel.iterator(); iter.hasNext();) { EditPart part = (EditPart) iter.next(); if (ModelUtils.getModel((EObject) part.getModel()) != null) selItems.add(part);// ww w. ja va2s. c o m } lastAppUiPageSelection = new StructuredSelection(selItems); }
From source file:com.nokia.sdt.uidesigner.gallery.GalleryView.java
License:Open Source License
private void openSelection(IStructuredSelection selection) { for (Iterator iter = selection.iterator(); iter.hasNext();) { Object item = iter.next(); if (item instanceof IDesignerDataModelSpecifier) { try { IDesignerDataModelSpecifier specifier = (IDesignerDataModelSpecifier) item; specifier.openInEditor(); } catch (CoreException x) { IStatus status = Logging.newSimpleStatus(0, IStatus.ERROR, x.getMessage(), x); Logging.log(UIDesignerPlugin.getDefault(), status); Logging.showErrorDialog(null, x.getMessage(), status); }/* w w w .j a v a 2s .c o m*/ } } }
From source file:com.nokia.sdt.uidesigner.ui.actions.CopyActionCommandHandler.java
License:Open Source License
public boolean updateSelection(IStructuredSelection selection) { List filteredSelection = new ArrayList(); for (Iterator iter = selection.iterator(); iter.hasNext();) { EditPart part = (EditPart) iter.next(); filteredSelection.add(part);/*from w w w . j a v a 2 s . c o m*/ } if (filteredSelection.isEmpty()) return false; // can't execute return super.updateSelection(new StructuredSelection(filteredSelection)); }
From source file:com.nokia.sdt.uidesigner.ui.actions.CutActionCommandHandler.java
License:Open Source License
public boolean updateSelection(IStructuredSelection selection) { List filteredSelection = new ArrayList(); for (Iterator iter = selection.iterator(); iter.hasNext();) { EditPart part = (EditPart) iter.next(); if (helper.isRemovablePart(part) && !isDescendantOfSelectedPart(part, selection.toList())) filteredSelection.add(part); }/*w w w. j a va 2 s. c o m*/ if (filteredSelection.isEmpty()) return false; // can't execute return super.updateSelection(new StructuredSelection(filteredSelection)); }
From source file:com.nokia.sdt.uidesigner.ui.SelectionManager.java
License:Open Source License
public List getSelectedModelNames() { ISelection sel = getSelection();/* w w w . ja v a 2s . c o m*/ if (!(sel instanceof IStructuredSelection)) return null; List objectNames = new ArrayList(); IStructuredSelection selection = (IStructuredSelection) sel; for (Iterator iter = selection.iterator(); iter.hasNext();) { EObject object = getObjectFromSelected(iter.next()); if (object != null) { IComponentInstance instance = Adapters.getComponentInstance(object); objectNames.add(instance.getName()); } } return objectNames; }