List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.drgarbage.bytecodevisualizer.editors.ToggleBytecodeBreakpointAdapter.java
License:Apache License
public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { ISelection sel = translateToMembers(part, selection); if (sel instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) sel; if (!structuredSelection.isEmpty()) { IMember member = (IMember) structuredSelection.getFirstElement(); int mtype = member.getElementType(); if (mtype == IJavaElement.FIELD) { toggleWatchpoints(part, sel); } else if (mtype == IJavaElement.METHOD) { toggleMethodBreakpoints(part, sel); } else if (member.getElementType() == IJavaElement.TYPE) { toggleClassBreakpoints(part, sel); } else { BytecodeVisualizerPlugin .log(new IllegalStateException("Uncovered element type " + member.getElementType())); // /* // * fall back to old behavior, always create a line // * breakpoint // */ // /* should never occur */ // toggleLineBreakpoints(part, selection, true); }//from w ww .j a v a2 s . c o m } } }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
/** * Constructor.//www. ja v a 2 s . c o m * @param pageName * @param selection */ public JavaToWSDLWizardPage(String pageName, IStructuredSelection selection) { super(pageName); setTitle("Java Interface"); //NON-NLS-1 setDescription("Select a Java interface."); //NON-NLS-1 if (selection != null && !selection.isEmpty()) { Object o = selection.getFirstElement(); try { if (o instanceof IProject && ((IProject) o).isAccessible() && ((IProject) o).hasNature(JavaCore.NATURE_ID)) this.javaProject = JavaCore.create((IProject) o); } catch (CoreException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.WARNING); } } }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); container.setLayout(layout);//from w w w .j a va2s . c o m container.setLayoutData(new GridData(GridData.FILL_BOTH)); // Container selection Label l = new Label(container, SWT.NONE); l.setText("Select the Java project that contains the classes."); GridData layoutData = new GridData(); layoutData.horizontalSpan = 2; l.setLayoutData(layoutData); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { @Override public Object[] getChildren(Object o) { if (o instanceof IWorkspaceRoot) { IProject[] projects = ((IWorkspaceRoot) o).getProjects(); ArrayList<IJavaProject> result = new ArrayList<IJavaProject>(); for (IProject project : projects) { try { if (!project.isOpen() || !project.hasNature(JavaCore.NATURE_ID)) continue; } catch (CoreException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.WARNING); continue; } IJavaProject p = JavaCore.create(project); result.add(p); } return result.toArray(); } return new Object[0]; } }); // Set page input IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); viewer.setInput(root); if (this.javaProject != null) { viewer.setSelection(new StructuredSelection(this.javaProject), true); viewer.expandToLevel(this.javaProject, 1); } viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); if (!s.isEmpty()) JavaToWSDLWizardPage.this.javaProject = (IJavaProject) s.getFirstElement(); else JavaToWSDLWizardPage.this.javaProject = null; validate(); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { openClassSelectionDialog(); } }); // Class field l = new Label(container, SWT.NONE); l.setText("Select the Java interface."); layoutData = new GridData(); layoutData.horizontalSpan = 2; layoutData.verticalIndent = 15; l.setLayoutData(layoutData); this.classText = new Text(container, SWT.BORDER | SWT.SINGLE); this.classText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.classText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { JavaToWSDLWizardPage.this.className = JavaToWSDLWizardPage.this.classText.getText(); validate(); } }); Button b = new Button(container, SWT.PUSH); b.setText("Browse..."); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { openClassSelectionDialog(); } @Override public void widgetSelected(SelectionEvent e) { openClassSelectionDialog(); } }); this.classText.setFocus(); setControl(container); }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.WSDLtoJavaWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); container.setLayout(layout);//from w ww.ja va 2 s.c o m container.setLayoutData(new GridData(GridData.FILL_BOTH)); // WSDL field Label l = new Label(container, SWT.NONE); l.setText("WSDL URI:"); l.setLayoutData(new GridData()); final Text text = new Text(container, SWT.BORDER | SWT.SINGLE); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { String uri = text.getText(); if (uri.trim().length() == 0) return; try { WSDLtoJavaWizardPage.this.wsdlUri = UriAndUrlHelper.urlToUri(uri); } catch (Exception e1) { WSDLtoJavaWizardPage.this.wsdlUri = null; } validate(); } }); Composite buttons = new Composite(container, SWT.NONE); layout = new GridLayout(2, false); layout.marginHeight = layout.marginWidth = 0; buttons.setLayout(layout); Button b = new Button(buttons, SWT.PUSH); b.setText("Browse File System"); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(text.getShell(), SWT.SINGLE); dlg.setFilterNames(new String[] { "WSDL (*.wsdl)" }); //$NON-NLS-1$ dlg.setFilterExtensions(new String[] { "*.wsdl" }); //$NON-NLS-1$ String path = dlg.open(); if (path != null) { text.setText(new File(path).toURI().toString()); text.setSelection(path.length()); text.setFocus(); } } }); b = new Button(buttons, SWT.PUSH); b.setText("Browse Workspace..."); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(SelectionEvent e) { WorkspaceExplorer dlg = new WorkspaceExplorer(getShell(), new String[] { "wsdl" }); if (dlg.open() == Window.OK) { IResource res = dlg.getSelectedResource(); text.setText(new File(res.getLocation().toOSString()).toURI().toString()); text.setSelection(text.getText().length()); text.setFocus(); } } }); // Container selection l = new Label(container, SWT.NONE); l.setText("Select the output location."); GridData layoutData = new GridData(); layoutData.verticalIndent = 15; l.setLayoutData(layoutData); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 200; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { @Override public Object[] getChildren(Object o) { if (o instanceof IContainer) { IResource[] members; try { members = ((IContainer) o).members(); } catch (Exception e) { return new Object[0]; } ArrayList<IResource> results = new ArrayList<IResource>(); for (IResource member : members) { if (member instanceof IContainer) results.add(member); } return results.toArray(); } return new Object[0]; } }); // Set page input IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); viewer.setInput(root); if (this.outputContainer != null) { viewer.setSelection(new StructuredSelection(this.outputContainer), true); viewer.expandToLevel(this.outputContainer, 1); } viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); if (!s.isEmpty()) WSDLtoJavaWizardPage.this.outputContainer = (IContainer) s.getFirstElement(); else WSDLtoJavaWizardPage.this.outputContainer = null; validate(); } }); text.setFocus(); setControl(container); }
From source file:com.ebmwebsourcing.petals.common.internal.commands.ConfigureBuildPathCommandHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { try {/*from ww w. ja va 2 s. c o m*/ IStructuredSelection selection = (IStructuredSelection) PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getSelectionService().getSelection(); if (!selection.isEmpty()) { IJavaProject project = (IJavaProject) ((IProject) selection.getFirstElement()) .getNature(JavaCore.NATURE_ID); // Copy-pasted from ConfigureBuildPathAction PreferencesUtil .createPropertyDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), project, BuildPathsPropertyPage.PROP_ID, null, Collections.EMPTY_MAP) .open(); } } catch (Exception ex) { throw new ExecutionException("Could not cast to Java Project", ex); } return null; }
From source file:com.ebmwebsourcing.petals.common.internal.projectscnf.PetalsProjectNavigator.java
License:Open Source License
@Override public boolean show(ShowInContext context) { IStructuredSelection selection = getSelection(context); if (selection != null && !selection.isEmpty()) { Object o = selection.getFirstElement(); if (o instanceof IPackageFragment || o instanceof IPackageFragmentRoot || o instanceof ICompilationUnit) { selectReveal(new StructuredSelection(o)); return true; } else {//w w w . j a va 2 s. co m IResource res = (IResource) PlatformUtils.getAdapter(o, IResource.class); if (res != null) { selectReveal(new StructuredSelection(res)); return true; } } } return false; }
From source file:com.ebmwebsourcing.petals.services.sa.wizards.PetalsSaNewWizard.java
License:Open Source License
@Override public void init(IWorkbench workbench, IStructuredSelection selection) { if (selection.isEmpty()) return;/*www . ja va 2 s. c om*/ Iterator<?> it = selection.iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof IProject) this.selectedProjects.add(((IProject) o).getName()); } }
From source file:com.ebmwebsourcing.petals.services.su.editor.SuEditionComposite.java
License:Open Source License
/** * Initializes the widgets on the left side. *///from w ww.ja v a 2 s.c o m protected void createLeftWidgets() { Composite servicesComposite = getFormToolkit().createComposite(this); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; servicesComposite.setLayout(layout); // Provides Form providesForm = getFormToolkit().createForm(servicesComposite); providesForm.setLayoutData(new GridData(GridData.FILL_BOTH)); providesForm.setText(Messages.provides); layout = new GridLayout(2, false); layout.marginHeight = 0; providesForm.getBody().setLayout(layout); this.providesViewer = new TableViewer(providesForm.getBody()); this.providesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); this.providesViewer.setLabelProvider(this.labelProvider); this.providesViewer.setContentProvider(new ArrayContentProvider()); Composite providesButtons = getFormToolkit().createComposite(providesForm.getBody()); layout = new GridLayout(); layout.marginHeight = 0; providesButtons.setLayout(layout); providesButtons.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, true)); Button newProvidesButton = getFormToolkit().createButton(providesButtons, "New...", SWT.NONE); newProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1)); newProvidesButton.setImage(PetalsImages.INSTANCE.getAdd()); final IWizard providesWizard = findNewWizard(PetalsMode.provides); if (providesWizard == null) { newProvidesButton.setEnabled(false); newProvidesButton.setToolTipText("The component is not supported."); } else { newProvidesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (new WizardDialog(getShell(), providesWizard).open() == Dialog.OK) SuEditionComposite.this.providesViewer.refresh(); } }); } final Button removeProvidesButton = getFormToolkit().createButton(providesButtons, "Remove", SWT.NONE); removeProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); removeProvidesButton.setImage(PetalsImages.INSTANCE.getDelete()); removeProvidesButton.addSelectionListener(new EListRemoveSelectionListener(this.providesViewer)); final Button upProvidesButton = getFormToolkit().createButton(providesButtons, "", SWT.NONE); upProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); upProvidesButton.setText("&Up"); upProvidesButton.addSelectionListener(new EListUpSelectionListener()); final Button downProvidesButton = getFormToolkit().createButton(providesButtons, "", SWT.NONE); downProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); downProvidesButton.setText("&Down"); downProvidesButton.addSelectionListener(new EListDownSelectionListener()); getDataBindingContext().bindValue(ViewersObservables.observeInput(this.providesViewer), EMFEditObservables.observeValue(getEditingDomain(), getJbiModel().getServices(), JbiPackage.Literals.SERVICES__PROVIDES)); // Consumes Form consumesForm = getFormToolkit().createForm(servicesComposite); consumesForm.setLayoutData(new GridData(GridData.FILL_BOTH)); consumesForm.setText(Messages.consumes); layout = new GridLayout(2, false); layout.marginHeight = 0; consumesForm.getBody().setLayout(layout); this.consumesViewer = new TableViewer(consumesForm.getBody()); this.consumesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); this.consumesViewer.setLabelProvider(this.labelProvider); this.consumesViewer.setContentProvider(new ArrayContentProvider()); Composite consumesButtons = getFormToolkit().createComposite(consumesForm.getBody()); layout = new GridLayout(); layout.marginHeight = 0; consumesButtons.setLayout(layout); consumesButtons.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, true)); Button newConsumesButton = getFormToolkit().createButton(consumesButtons, "New...", SWT.NONE); newConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); newConsumesButton.setImage(PetalsImages.INSTANCE.getAdd()); final IWizard consumesWizard = findNewWizard(PetalsMode.consumes); if (consumesWizard == null) { newConsumesButton.setEnabled(false); newConsumesButton.setToolTipText("The component is not supported."); } else { newConsumesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (new WizardDialog(getShell(), consumesWizard).open() == Dialog.OK) SuEditionComposite.this.consumesViewer.refresh(); } }); } final Button removeConsumesButton = getFormToolkit().createButton(consumesButtons, "Remove", SWT.NONE); removeConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); removeConsumesButton.setImage(PetalsImages.INSTANCE.getDelete()); removeConsumesButton.addSelectionListener(new EListRemoveSelectionListener(this.consumesViewer)); final Button upConsumesButton = getFormToolkit().createButton(consumesButtons, "", SWT.NONE); upConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); upConsumesButton.setText("&Up"); upConsumesButton.addSelectionListener(new EListUpSelectionListener()); final Button downConsumesButton = getFormToolkit().createButton(consumesButtons, "", SWT.NONE); downConsumesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1)); downConsumesButton.setText("&Down"); downConsumesButton.addSelectionListener(new EListDownSelectionListener()); getDataBindingContext().bindValue(ViewersObservables.observeInput(this.consumesViewer), EMFEditObservables.observeValue(getEditingDomain(), getJbiModel().getServices(), JbiPackage.Literals.SERVICES__CONSUMES)); this.providesViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = ((IStructuredSelection) SuEditionComposite.this.providesViewer .getSelection()); if (selection.isEmpty()) { SuEditionComposite.this.selectedEndpoint = null; upProvidesButton.setEnabled(false); downProvidesButton.setEnabled(false); } else { SuEditionComposite.this.consumesViewer.setSelection(new StructuredSelection()); SuEditionComposite.this.selectedEndpoint = (Provides) selection.getFirstElement(); SuEditionComposite.this.containmentList = getJbiModel().getServices().getProvides(); upProvidesButton.setEnabled(SuEditionComposite.this.containmentList .indexOf(SuEditionComposite.this.selectedEndpoint) > 0); downProvidesButton.setEnabled(SuEditionComposite.this.containmentList.indexOf( SuEditionComposite.this.selectedEndpoint) != SuEditionComposite.this.containmentList .size() - 1); refreshDetails(); } removeProvidesButton.setEnabled(SuEditionComposite.this.selectedEndpoint != null); } }); this.consumesViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = ((IStructuredSelection) SuEditionComposite.this.consumesViewer .getSelection()); if (selection.isEmpty()) { SuEditionComposite.this.selectedEndpoint = null; upConsumesButton.setEnabled(false); downConsumesButton.setEnabled(false); } else { SuEditionComposite.this.providesViewer.setSelection(new StructuredSelection()); SuEditionComposite.this.selectedEndpoint = (Consumes) selection.getFirstElement(); SuEditionComposite.this.containmentList = getJbiModel().getServices().getConsumes(); upConsumesButton.setEnabled(SuEditionComposite.this.containmentList .indexOf(SuEditionComposite.this.selectedEndpoint) > 0); downConsumesButton.setEnabled(SuEditionComposite.this.containmentList.indexOf( SuEditionComposite.this.selectedEndpoint) != SuEditionComposite.this.containmentList .size() - 1); refreshDetails(); } removeConsumesButton.setEnabled(SuEditionComposite.this.selectedEndpoint != null); } }); }
From source file:com.ebmwebsourcing.petals.services.su.export.SuBulkExportWizardPage.java
License:Open Source License
/** * Constructor./*from ww w . j a v a2 s. c o m*/ * @param selection */ public SuBulkExportWizardPage(IStructuredSelection selection) { super("SU Bulk Export Page"); setTitle("Bulk Services Export"); //NON-NLS-1 setDescription("Create n Petals services from one Service Unit project."); //NON-NLS-1 if (!selection.isEmpty()) { IProject project = PlatformUtils.getAdaptedProject(selection.getFirstElement()); if (project != null && ServiceProjectRelationUtils.isSuProject(project)) this.suProject = project; } try { ImageDescriptor desc = PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER); if (desc != null) this.folderImg = desc.createImage(); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.WARNING); } try { ImageDescriptor desc = PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(org.eclipse.ui.ide.IDE.SharedImages.IMG_OBJ_PROJECT); if (desc != null) this.projectImg = desc.createImage(); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.WARNING); } try { ImageDescriptor desc = PetalsServicesPlugin.getImageDescriptor("icons/obj16/properties.gif"); if (desc != null) this.propertiesImg = desc.createImage(); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.WARNING); } }
From source file:com.elphel.vdt.ui.launching.LaunchShortcut.java
License:Open Source License
private static IProject getActiveProject(ISelection selection) { if ((selection != null) && (selection instanceof IStructuredSelection)) { IStructuredSelection ssel = (IStructuredSelection) selection; if (!ssel.isEmpty()) { Object object = ssel.getFirstElement(); if (object instanceof IAdaptable) { IProject project = (IProject) ((IAdaptable) object).getAdapter(IProject.class); if (project != null && project.isOpen()) return project; }//from ww w. ja v a2s .co m } } return null; }