List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.iw.plugins.spindle.editors.template.TemplateContentOutlinePage.java
License:Mozilla Public License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() == 1) { try {/*from w ww . j av a 2s . c o m*/ ITypedRegion region = (ITypedRegion) selection.getFirstElement(); fireSelectionChanged(new StructuredSelection(new Object[] { findJWCID(region) })); } catch (BadLocationException e) { //swallow it } } }
From source file:com.iw.plugins.spindle.html.HTMLContentOutlinePage.java
License:Mozilla Public License
public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() == 1) { ITypedRegion region = (ITypedRegion) selection.getFirstElement(); fireSelectionChanged(new StructuredSelection(new Object[] { findJWCID(region) })); }/* www . ja v a2 s . co m*/ }
From source file:com.iw.plugins.spindle.html.HTMLContentOutlinePage.java
License:Mozilla Public License
private void fillContextMenu(IMenuManager manager) { TreeViewer viewer = (TreeViewer) getTreeViewer(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); IFile file = Utils.findRelatedComponent(documentFile); IStructuredSelection canCreateSelection = filterSelection(file, selection); if (canCreateSelection.isEmpty() && selection.size() == 1) { ILabelProvider provider = (ILabelProvider) getTreeViewer().getLabelProvider(); openAction.configure(file, provider.getText(selection.getFirstElement())); manager.add(openAction);/*w w w.j a va 2s.c o m*/ } else { createAction.configure(file, canCreateSelection); manager.add(createAction); } }
From source file:com.iw.plugins.spindle.ui.util.Revealer.java
License:Mozilla Public License
/** * @param useSelection//from ww w. jav a2s . c o m * @return */ private static ISelection checkSelectionForJarEntryFile(ISelection useSelection, IJavaProject jproject) { if (useSelection.isEmpty() || !(useSelection instanceof IStructuredSelection)) return useSelection; IStructuredSelection structured = (IStructuredSelection) useSelection; Object first = structured.getFirstElement(); if (structured.size() > 1 || !(first instanceof IJarEntryResource)) return useSelection; IJarEntryResource jarResource = (IJarEntryResource) first; IPath path = jarResource.getFullPath().removeFileExtension(); String name = path.lastSegment(); IPackageFragment[] fragments = null; try { if (jproject != null) { IPackageFragment frag = (IPackageFragment) jarResource.getParent(); if (frag != null) fragments = new IPackageFragment[] { frag }; } else { fragments = JarEntryFileUtil.getPackageFragments(ResourcesPlugin.getWorkspace().getRoot(), jarResource); } if (fragments.length != 1) return useSelection; // check to see if there is an IClassFile in the package IJavaElement[] children = fragments[0].getChildren(); if (children.length > 0) { IClassFile revealInstead = null; for (int i = 0; i < children.length; i++) { if (children[i].getElementType() != IJavaElement.CLASS_FILE) continue; revealInstead = (IClassFile) children[i]; String temp = revealInstead.getElementName(); temp = temp.substring(0, temp.length() - 6); if (temp.equals(name)) return new StructuredSelection(revealInstead); } if (revealInstead != null) return new StructuredSelection(revealInstead); } return new StructuredSelection(fragments[0]); } catch (CoreException e) { UIPlugin.log(e); } return useSelection; }
From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitAttributesPage.java
License:Mozilla Public License
/** * @param selection/*from w w w . j a v a2 s .co m*/ * @return */ private boolean canMoveUp(ISelection selection) { if (selection instanceof IStructuredSelection && !selection.isEmpty()) { IStructuredSelection structured = (IStructuredSelection) selection; return structured.size() == 1 && fAttributesThatMove.indexOf(structured.getFirstElement()) > 0; } return false; }
From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitAttributesPage.java
License:Mozilla Public License
/** * @param selection//from www . j av a 2 s .c o m * @return */ private boolean canMoveDown(ISelection selection) { if (selection instanceof IStructuredSelection && !selection.isEmpty()) { IStructuredSelection structured = (IStructuredSelection) selection; return structured.size() == 1 && fAttributesThatMove.indexOf(structured.getFirstElement()) < fAttributesThatMove.size() - 1; } return false; }
From source file:com.iw.plugins.spindle.wizards.extra.ConvertComponentIntoPageAction.java
License:Mozilla Public License
/** * Method checkMultiSelection./* www . java2s . c o m*/ * @param selection * @return boolean */ private boolean checkSelection(IStructuredSelection selection) { boolean result = false; if (selection != null && !selection.isEmpty() && selection.size() == 1) { try { for (Iterator iter = selection.iterator(); iter.hasNext();) { IFile candidateFile = (IFile) iter.next(); if (!candidateFile.isReadOnly() && !checkPageExists(candidateFile)) { try { ITapestryProject project = TapestryPlugin.getDefault() .getTapestryProjectFor(candidateFile); TapestryProjectModelManager mgr = project.getModelManager(); TapestryLibraryModel projectModel = (TapestryLibraryModel) project.getProjectModel(); TapestryComponentModel cmodel = null; if (mgr != null && projectModel != null) { IPackageFragment modelFragment = project.getLookup() .findPackageFragment(candidateFile); if (modelFragment != null) { fragment = modelFragment; cmodel = (TapestryComponentModel) mgr.getReadOnlyModel(candidateFile); if (cmodel.isLoaded()) { result = true; } } } } catch (CoreException e) { } } } } catch (ClassCastException e) { } } return result; }
From source file:com.javadude.antxr.eclipse.ui.actions.JavaBreakpointPropertiesAction.java
License:Open Source License
/** {@inheritDoc} */ public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.isEmpty() || ss.size() > 1) { return; }//from w w w . java 2s. c o m Object element = ss.getFirstElement(); if (element instanceof IJavaBreakpoint) { setBreakpoint((IJavaBreakpoint) element); } } }
From source file:com.jinnova.docaid.parts.DiagListPart.java
License:Open Source License
@PostConstruct public void createComposite(Composite parent) { parent.setLayout(new GridLayout(1, false)); colorOpening = parent.getDisplay().getSystemColor(SWT.COLOR_BLUE); patientNameLabel = new Label(parent, SWT.None); GridData gdata = new GridData(GridData.FILL_HORIZONTAL); //gdata.widthHint = 200; patientNameLabel.setLayoutData(gdata); patientNameLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE)); diagListViewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION); //patientList.add("Sample item 1"); //patientList.add("Sample item 2"); diagListViewer.setContentProvider(ArrayContentProvider.getInstance()); //patientList.setInput(new String[] {"a", "b"}); createColumn(30, Messages.DiagListPart_queueNumberAbbr, new DiagLabelProvider() { @Override//from ww w .j a va 2s .c o m public String getText(Object element) { DiagRecord p = (DiagRecord) element; //int i = diagList.size() - diagList.indexOf(p); return String.valueOf(diagList.indexOf(p) + 1); } }); createColumn(100, Messages.DiagListPart_date, new DiagLabelProvider() { @Override public String getText(Object element) { DiagRecord d = (DiagRecord) element; //if (d.id.getValue() == null || d.id.getValue() == -1) { if (d.isInDayNotEnd()) { return Messages.DiagListPart_new_in_brackets; } else { return d.date.getEasyLabel(); } } }); createColumn(50, Messages.DiagListPart_weight, new DiagLabelProvider() { @Override public String getText(Object element) { DiagRecord d = (DiagRecord) element; return String.valueOf(d.weight.getValueAsEditing()); } }); createColumn(50, Messages.DiagListPart_height, new DiagLabelProvider() { @Override public String getText(Object element) { DiagRecord d = (DiagRecord) element; return String.valueOf(d.height.getValueAsEditing()); } }); createColumn(800, "", new DiagLabelProvider() { //$NON-NLS-1$ @Override public String getText(Object element) { DiagRecord d = (DiagRecord) element; if (d.id.getValue() == null || d.id.getValue() == -1) { return ""; //$NON-NLS-1$ } String s = null; s = append(s, Messages.DiagListPart_small_symtoms_colon, d.symptons.getValue()); s = append(s, Messages.DiagListPart_small_diag_colon, d.diagnosis.getValue()); s = append(s, Messages.DiagListPart_small_treatments_colon, d.treatment.getValue()); s = append(s, Messages.DiagListPart_small_prescription_colon, d.prescription.getSummary()); if (s == null) { return ""; //$NON-NLS-1$ } else { return s.substring(0, 1).toUpperCase() + s.substring(1); } } private String append(String dest, String title, String value) { if (value == null || "".equals(value.trim())) { //$NON-NLS-1$ return dest; } if (dest == null) { return title + value; } else { return dest + ", " + title + value; //$NON-NLS-1$ } } }); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 4; diagListViewer.getTable().setLayoutData(layoutData); final Table table = diagListViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); diagListViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); selService.setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); //diagListViewer.setInput(diagList); //WaitingList.registerViewer(diagListViewer); selService.addSelectionListener(new ISelectionListener() { //private Patient newPatient; //private LinkedList<DiagRecord> newDiagList; @Override public void selectionChanged(MPart part, Object selection) { Patient newPatient = null; DiagRecord newDiag = null; if (selection instanceof QueueTicket) { newDiag = ((QueueTicket) selection).patient.todayDiag; newPatient = newDiag.patient; } else if (selection instanceof Patient) { newPatient = (Patient) selection; newDiag = null; if (newPatient.id.getValue() != null) { QueueTicket q = WaitingList.diagQueue.getQueueItem(newPatient.id.getValue()); if (q != null) { newDiag = q.patient.todayDiag; } } if (newDiag == null) { //newDiag = newPatient.getOrCreateDirectTicket().diag; newDiag = newPatient.todayDiag; } } if (newPatient == null || newPatient == currentPatient) { return; } /*if (diag != null) { diagList = new LinkedList<DiagRecord>(); diagList.add(((QueuedPatient) selection).diag); diagListViewer.setInput(diagList); diagListViewer.setSelection(new StructuredSelection(diagList.getFirst()), true); }*/ setPatient(newPatient, newDiag); } /*private void loadViewer(LinkedList<DiagRecord> newDiagList) { patientNameLabel.setText(currentPatient.name.getValueAsEditing() + " (" + currentPatient.dob.getValueAsEditing() + ")"); diagList = newDiagList; diagListViewer.setInput(newDiagList.toArray()); }*/ }); Patient.addPatientSelectionEmptyListener(new Runnable() { @Override public void run() { /*patientNameLabel.setText(""); diagList = null; diagListViewer.setInput(null);*/ setPatient(null, null); } }); WaitingList.diagQueue.addQueuePeekingListener(new QueuePeekingListener() { @Override public void queuePeeked(QueueTicket ticket) { if (ticket == null) { setPatient(null, null); } else { setPatient(ticket.patient, ticket.patient.todayDiag); } } }); }
From source file:com.jinnova.docaid.parts.FamilyPart.java
License:Open Source License
@PostConstruct public void createComposite(Composite parent) { parent.setLayout(new GridLayout(2, false)); candidateName = new Label(parent, SWT.None); candidateName.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE)); candidateName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); addButton = new Button(parent, SWT.PUSH); addButton.setText(" "); //$NON-NLS-1$ addButton.addSelectionListener(new SelectionListener() { @Override/*from www. ja v a2 s.co m*/ public void widgetSelected(SelectionEvent e) { NamedAction action = getAction(); if (action != null) { action.run(); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); patientList = new PatientTableBuilder().builderViewer(parent); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; patientList.getTable().setLayoutData(layoutData); final Table table = patientList.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); patientList.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() < 1) { return; } PatientFamilyMember m = (PatientFamilyMember) selection.getFirstElement(); if (m.patient != null) { selService.setSelection(m); } candidate = null; populateCandidate(); } }); selService.addSelectionListener(new ISelectionListener() { @Override public void selectionChanged(MPart part, Object selection) { //System.out.println("got selection"); Patient p = null; if (selection instanceof Patient) { p = (Patient) selection; } else if (selection instanceof QueueTicket) { p = ((QueueTicket) selection).patient; } if (p != null && !p.equals(patient)) { patient = p; candidate = null; new Thread() { public void run() { loadMemberPatients(); } }.start(); populate(); return; } if (selection instanceof PatientFamilyCandidate) { PatientFamilyCandidate newCandidate = (PatientFamilyCandidate) selection; if (candidate == null || !newCandidate.patient.equals(candidate.patient)) { candidate = newCandidate; populateCandidate(); } } } }); }