List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:edu.illinois.ncsa.datawolf.executor.java.wizard.ToolSelectWizardPage.java
License:Open Source License
public Set<WorkflowTool> getTools() throws Exception { IStructuredSelection ssel = (IStructuredSelection) lvTools.getSelection(); Set<WorkflowTool> result = new HashSet<WorkflowTool>(); // editing a single tool, only tool creted. if (oldtool != null) { WorkflowTool tool = getTool((Class<? extends JavaTool>) ssel.getFirstElement()); tool.setPreviousVersion(oldtool); // add list of all people working on this tool // TODO RK : add people // if (!oldtool.getCreator().equals(Workflow.getUserBean())) { // tool.addContributor(oldtool.getCreator()); // } // for (Person user : oldtool.getContributors()) { // if (!user.equals(Workflow.getUserBean())) { // tool.addContributor(user); // } // } // only tool created result.add(tool);//from w w w .j av a 2s. c o m } else { for (Iterator<Class<? extends JavaTool>> iter = ssel.iterator(); iter.hasNext();) { result.add(getTool(iter.next())); } } return result; }
From source file:edu.isistan.carcha.components.WorkbenchTreeViewer.java
License:Open Source License
/** * Gets the result./*w ww . jav a2 s . com*/ * * @return the result */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected void getResult() { ISelection selection = getSelection(); List data = new ArrayList(); if (!selection.isEmpty()) { if (selection instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) selection; for (Iterator i = sel.iterator(); i.hasNext();) { Object next = i.next(); IResource resource = null; if (next instanceof IResource) resource = (IResource) next; else if (next instanceof IAdaptable) { if (resource == null) resource = (IResource) ((IAdaptable) next).getAdapter(IResource.class); } if (resource != null) { data.add(resource); } } } } result = (IResource[]) data.toArray(new IResource[] {}); }
From source file:edu.ohio_state.khatchad.refactoring.ui.ConvertConstantsToEnumHandler.java
License:Open Source License
/** * Gets fields from the given selection. */// w w w . j ava 2s . c o m private static List getFields(ISelection selection) { List fields = new ArrayList(); if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object selectedObject = iterator.next(); if (selectedObject instanceof IField) { fields.add(selectedObject); } else if (selectedObject instanceof IType) { // need to traverse each of the fields of the selected // object. IType type = (IType) selectedObject; // the fields in the type. List fieldsOfType = getFields(type); // add them to the list to be returned. fields.addAll(fieldsOfType); } // this condition check if the class compilationUnit get // selected, it will convert all possible IFields to Enum else if (selectedObject instanceof ICompilationUnit) { // need to traverse each of the ITypes. ICompilationUnit compilationUnit = (ICompilationUnit) selectedObject; List fieldsOfCompilationUnit = getFields(compilationUnit); fields.addAll(fieldsOfCompilationUnit); } else if (selectedObject instanceof IPackageFragment) { // need to traverse each of the package fragments of the // selected IPackageFragment packageFragment = (IPackageFragment) selectedObject; fields.addAll(getFields(packageFragment)); } else if (selectedObject instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) selectedObject; fields.addAll(getFields(root)); } else if (selectedObject instanceof IJavaProject) { IJavaProject iJavaProject = (IJavaProject) selectedObject; try { IPackageFragmentRoot[] allPackageFragmentRoots = iJavaProject.getAllPackageFragmentRoots(); for (int i = 0; i < allPackageFragmentRoots.length; i++) { IPackageFragmentRoot iPackageFragmentRoot = allPackageFragmentRoots[i]; fields.addAll(getFields(iPackageFragmentRoot)); } } catch (JavaModelException e) { e.printStackTrace(); } } } } return fields; }
From source file:edu.toronto.cs.se.mmint.mid.relationship.diagram.part.RelationshipDiagramOutlineDragListener.java
License:Open Source License
/** * {@inheritDoc}<br />// w ww . j a va 2 s .com * Starts the drag by copying the selected objects into the transfer data. * * @param event * The drag event. */ @Override public void dragStart(DragSourceEvent event) { List<Object> transferData = new ArrayList<>(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); boolean isInstancesLevel = modelRel.isInstancesLevel(); ModelElement modelElemType = null; // filtering Iterator<?> it = selection.iterator(); while (it.hasNext()) { Object selected = it.next(); EObject modelObj; // filter unallowed objects if (isInstancesLevel) { if (!(selected instanceof EObject) && !(selected instanceof AttributeValueWrapperItemProvider)) { continue; } modelObj = (selected instanceof AttributeValueWrapperItemProvider) ? new PrimitiveEObjectWrapper((AttributeValueWrapperItemProvider) selected) : (EObject) selected; } else { if (!(selected instanceof EClass) && !(selected instanceof EStructuralFeature)) { continue; } modelObj = (EObject) selected; } // assign to container //TODO MMINT[MODELELEMENT] Think about simplifying the accept phase and the dnd info, probably not everything is needed anymore String modelElemUri = MIDRegistry.getModelElementUri(modelObj); for (ModelEndpointReference modelEndpointRef : modelRel.getModelEndpointRefs()) { try { if (isInstancesLevel) { modelElemType = modelEndpointRef.acceptModelElementInstance(modelObj); if (modelElemType == null) { continue; } } else { if (!modelEndpointRef.acceptModelElementType(modelObj)) { continue; } } } catch (MMINTException e) { continue; } RelationshipDiagramOutlineDropObject dropObject = new RelationshipDiagramOutlineDropObject(modelObj, modelRel.getLevel(), modelEndpointRef, modelElemType, modelElemUri); transferData.add(dropObject); } } // create drag transfer selection selection = new StructuredSelection(transferData); if (selection.isEmpty()) { event.doit = false; } else { LocalSelectionTransfer.getTransfer().setSelection(selection); event.doit = true; } }
From source file:edu.tsinghua.lumaqq.ui.config.face.FaceManagePage.java
License:Open Source License
@Override protected void initialVariable() { currentPage = -1;//from w w w . java 2s .co m sl = new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { MenuItem mi = (MenuItem) e.getSource(); int dest = (Integer) mi.getData(); if (dest == getCurrentPage()) return; FaceRegistry util = FaceRegistry.getInstance(); IStructuredSelection selection = (IStructuredSelection) faceViewer.getSelection(); Iterator<?> i = selection.iterator(); while (i.hasNext()) util.moveFace((Face) i.next(), dest); faceViewer.refresh(); } }; }
From source file:edu.tsinghua.lumaqq.ui.config.face.FaceManagePage.java
License:Open Source License
protected Control createContent(Composite parent) { content = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); content.setLayout(layout);//from w w w .j av a2 s . c om content.setBackground(Colors.WHITE); FormData fd = new FormData(); fd.top = fd.left = new FormAttachment(0, 1); fd.bottom = fd.right = new FormAttachment(100, -1); setLayoutData(fd); // viewer faceViewer = new TableViewer(content, SWT.FULL_SELECTION | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI); faceViewer.setContentProvider(new FaceContentProvider()); faceViewer.setLabelProvider(new FaceLabelProvider()); Table t = faceViewer.getTable(); GridData gd = new GridData(GridData.FILL_BOTH); gd.verticalSpan = 5; t.setLayoutData(gd); TableColumn tc = new TableColumn(t, SWT.LEFT); tc.setText(face_id); tc.setWidth(70); tc = new TableColumn(t, SWT.LEFT); tc.setText(face_image); tc.setWidth(100); t.setLinesVisible(true); t.setHeaderVisible(true); // Slat btnAdd = new Slat(content, SWT.NONE); btnAdd.setText(button_add_dot); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 100; btnAdd.setLayoutData(gd); btnAdd.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { if (currentPage == -1) { MessageDialog.openWarning(parentShell, message_box_common_warning_title, message_box_need_face_group); return; } FileDialog dialog = new FileDialog(parentShell, SWT.OPEN); dialog.setFilterExtensions(new String[] { "*.*", "*.gif", "*.jpg", "*.bmp" }); dialog.setFilterNames(new String[] { "All Files(*.*)", "GIF Files(*.gif)", "JPEG Files(*.jpg)", "Bitmap Files(*.bmp)" }); dialog.open(); String filename = dialog.getFileName(); if (filename == null) return; String path = dialog.getFilterPath(); if (!path.endsWith(File.separator)) path += File.separatorChar; // ? FaceRegistry util = FaceRegistry.getInstance(); FaceGroup g = util.getFaceGroup(getCurrentPage()); SingleFaceImporter importer = new SingleFaceImporter(path + filename, LumaQQ.CUSTOM_FACE_DIR, g); FaceEntry entry = importer.getEntry(); if (util.hasFace(entry.md5)) return; // ? if (!importer.saveEntry()) return; // table util.addFace(entry, g); refreshViewer(g); } }); // Slat btnDelete = new Slat(content, SWT.NONE); btnDelete.setText(button_delete); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 100; btnDelete.setLayoutData(gd); btnDelete.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { FaceRegistry util = FaceRegistry.getInstance(); IStructuredSelection selection = (IStructuredSelection) faceViewer.getSelection(); Iterator<?> i = selection.iterator(); while (i.hasNext()) { Face face = (Face) i.next(); FileTool.deleteFile(util.getFacePath(face)); FileTool.deleteFile(util.getSmallFacePath(face)); util.removeFace(face.getMd5()); } faceViewer.refresh(); } }); // Slat btnUp = new Slat(content, SWT.NONE); btnUp.setText(button_up); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 100; btnUp.setLayoutData(gd); btnUp.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { FaceRegistry util = FaceRegistry.getInstance(); Table table = faceViewer.getTable(); int[] indices = table.getSelectionIndices(); for (int i = 0; i < indices.length; i++) util.upFace(currentPage, indices[i]); faceViewer.refresh(); } }); // Slat btnDown = new Slat(content, SWT.NONE); btnDown.setText(button_down); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 100; btnDown.setLayoutData(gd); btnDown.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { FaceRegistry util = FaceRegistry.getInstance(); Table table = faceViewer.getTable(); int[] indices = table.getSelectionIndices(); for (int i = 0; i < indices.length; i++) util.downFace(currentPage, indices[i]); faceViewer.refresh(); } }); // btnMove = new Slat(content, SWT.NONE); btnMove.setText(button_move_dot); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING); gd.widthHint = 100; btnMove.setLayoutData(gd); btnMove.addMouseListener(new MouseAdapter() { public void mouseUp(MouseEvent e) { Rectangle bound = btnMove.getBounds(); moveMenu.setLocation(btnMove.getParent().toDisplay(bound.x, bound.y + bound.height)); moveMenu.setVisible(true); } }); // ??? initMoveMenu(); return content; }
From source file:edu.tsinghua.lumaqq.ui.dialogs.DiskShareDialog.java
License:Open Source License
@Override protected void createButtonsForButtonBar(Composite parent) { super.createButtonsForButtonBar(parent); createButton(parent, REMOVE_ID, button_delete, false).addSelectionListener(new SelectionAdapter() { @Override/* w w w . j ava 2s . c o m*/ public void widgetSelected(SelectionEvent e) { IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); for (Iterator<?> i = s.iterator(); i.hasNext();) { Integer qq = (Integer) i.next(); User u = ModelRegistry.getUser(qq); if (u != null) fss.deselect(u); newList.remove(qq); } viewer.refresh(); } }); }
From source file:edu.uci.isr.archstudio4.comp.tracelink.addtracelinks.RecordLinkView.java
private Vector<String> getLocationList(IStructuredSelection ss, ISelectionModel selection) { Vector<String> locationList = new Vector<String>(); Iterator<?> iterator = ss.iterator(); Object obj;//from w w w . jav a 2s .c o m String location = ""; String temp; URI locationURI; //ITraceEndpointModel endpoint; while (iterator.hasNext()) { obj = iterator.next(); System.out.println("@@@obj class " + obj.getClass().toString()); //System.out.println("selection item event" + o.getClass().getName()); /* if (obj instanceof File) { location = ((File) obj).getFullPath().toPortableString(); } */ if (obj.toString().contains("ObjRef")) { //since it is an object ref, and the selections in BNA only represent the most recent selection, //we need to get the string selected instead //location = "#" + xadlFacade.getID(obj.toString()); location = "#" + xadlFacade.getID(selection.getElement()); } else { //assume this is a selected File in the Resource Navigator try { temp = obj.toString(); if (temp.contains("L/")) temp = obj.toString().substring(1); //truncate "L/" locationURI = new URI(temp); location = locationURI.toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //endpoint = createEndpoint(location); //if (endpoint != null) // endpoints.add(endpoint); locationList.add(location); } return locationList; }
From source file:edu.uci.lighthouse.core.commands.ImportHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); final Collection<IFile> javaFiles = new ArrayList<IFile>(); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { Object itemSelected = iterator.next(); if (itemSelected instanceof IJavaProject) { IJavaProject jProject = (IJavaProject) itemSelected; /* Verifies if the project is open in the workspace. This method is different from IJavaProject.isOpen() */ if (jProject.getProject().isOpen()) { javaFiles.addAll(WorkbenchUtility.getFilesFromJavaProject(jProject)); } // TODO handle else }/*w w w .j a v a 2 s . c o m*/ } //TODO (tproenca): Converter pra IDatabaseAction final Job job = new Job("Sharing Project") { @Override protected IStatus run(IProgressMonitor monitor) { try { monitor.beginTask("Sharing files...", javaFiles.size()); PushModel pushModel = PushModel.getInstance(); // Parsing files monitor.subTask("Parsing Java files..."); Collection<LighthouseEvent> listEvents = pushModel.addIFilesToModel(javaFiles); // Saving in the Database (it has its own monitor). monitor.subTask("Saving data to the database..."); pushModel.importEventsToDatabase(listEvents, new SubProgressMonitor(monitor, javaFiles.size())); //TODO: Rollback model changes WorkbenchUtility.updateProjectIcon(); LighthouseModel.getInstance().fireModelChanged(); } catch (final JPAException e) { logger.error(e, e); UserDialog.openError("JPAException: " + e.getMessage()); } catch (final ParserException e) { logger.error(e, e); UserDialog.openError("ParserException: " + e.getMessage()); } finally { monitor.done(); } return Status.OK_STATUS; } }; job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(final IJobChangeEvent event) { if (event.getResult() != Status.CANCEL_STATUS && !event.getResult().isOK()) { UserDialog.openError("Imposible to connect to server. Please, check your connection settings."); } } }); job.setUser(true); job.schedule(); return null; }
From source file:edu.uci.lighthouse.core.commands.ProjectPropertyTester.java
License:Open Source License
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (receiver instanceof IStructuredSelection) { LighthouseModel model = LighthouseModel.getInstance(); Collection<String> projectNames = model.getProjectNames(); IStructuredSelection selections = (IStructuredSelection) receiver; for (Iterator itSelections = selections.iterator(); itSelections.hasNext();) { Object selection = itSelections.next(); if (selection instanceof IJavaProject) { IJavaProject jProject = (IJavaProject) selection; if (projectNames.contains(jProject.getElementName())) { return false; }/*from w w w. j av a2s.c o m*/ } } } return true; }