List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.google.dart.tools.ui.internal.refactoring.actions.RenameDartElementAction.java
License:Open Source License
@Override public void selectionChanged(IStructuredSelection selection) { try {/* ww w . j av a 2s. c o m*/ if (selection.size() == 1) { setEnabled(canEnable(selection)); return; } } catch (DartModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (DartModelUtil.isExceptionToBeLogged(e)) { DartToolsPlugin.log(e); } } catch (CoreException e) { DartToolsPlugin.log(e); } setEnabled(false); }
From source file:com.google.dart.tools.ui.internal.refactoring.actions.RenameResourceAction.java
License:Open Source License
private static IResource getResource(IStructuredSelection selection) { if (selection.size() != 1) return null; Object first = selection.getFirstElement(); if (!(first instanceof IResource)) return null; return (IResource) first; }
From source file:com.google.dart.tools.ui.internal.viewsupport.StatusBarUpdater.java
License:Open Source License
protected String formatMessage(ISelection sel) { if (sel instanceof IStructuredSelection && !sel.isEmpty()) { IStructuredSelection selection = (IStructuredSelection) sel; int nElements = selection.size(); if (nElements > 1) { return Messages.format(DartUIMessages.StatusBarUpdater_num_elements_selected, String.valueOf(nElements)); } else {/*w w w . j a va2 s. c o m*/ Object elem = selection.getFirstElement(); if (elem instanceof DartElement) { return formatJavaElementMessage((DartElement) elem); } else if (elem instanceof IResource) { return formatResourceMessage((IResource) elem); // } else if (elem instanceof PackageFragmentRootContainer) { // PackageFragmentRootContainer container = (PackageFragmentRootContainer) elem; // return container.getLabel() + DartElementLabels.CONCAT_STRING // + container.getJavaProject().getElementName(); // } else if (elem instanceof IJarEntryResource) { // IJarEntryResource jarEntryResource = (IJarEntryResource) elem; // StringBuffer buf = new StringBuffer(jarEntryResource.getName()); // buf.append(DartElementLabels.CONCAT_STRING); // IPath fullPath = jarEntryResource.getFullPath(); // if (fullPath.segmentCount() > 1) { // buf.append(fullPath.removeLastSegments(1).makeRelative()); // buf.append(DartElementLabels.CONCAT_STRING); // } // DartElementLabels.getPackageFragmentRootLabel( // jarEntryResource.getPackageFragmentRoot(), // DartElementLabels.ROOT_POST_QUALIFIED, buf); // return buf.toString(); } else if (elem instanceof IAdaptable) { IWorkbenchAdapter wbadapter = (IWorkbenchAdapter) ((IAdaptable) elem) .getAdapter(IWorkbenchAdapter.class); if (wbadapter != null) { return wbadapter.getLabel(elem); } } } } return ""; //$NON-NLS-1$ }
From source file:com.google.dart.tools.ui.web.pubspec.DependencyDetailsPage.java
License:Open Source License
@Override public void selectionChanged(IFormPart part, ISelection selection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() == 1) { input = (DependencyObject) ssel.getFirstElement(); } else {// ww w. jav a 2s . c o m input = null; } ignoreModify = true; update(); ignoreModify = false; }
From source file:com.google.gdt.eclipse.core.ui.SdkTable.java
License:Open Source License
@SuppressWarnings("unchecked") private T getSelectedSdk() { IStructuredSelection selection = (IStructuredSelection) sdkTableViewer.getSelection(); assert (selection.size() <= 1); return (T) selection.getFirstElement(); }
From source file:com.google.gdt.eclipse.core.ui.SdkTable.java
License:Open Source License
private void updateRemoteButtonEnabled() { IStructuredSelection selection = (IStructuredSelection) sdkTableViewer.getSelection(); removeButton.setEnabled(selection.size() != 0); }
From source file:com.google.gwt.eclipse.core.editors.java.GWTOpenEditorActionGroup.java
License:Open Source License
private void addOpenWithMenu(IMenuManager menu) { ISelection selection = getContext().getSelection(); if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { return;/*www . ja v a 2 s .c o m*/ } IStructuredSelection ss = (IStructuredSelection) selection; if (ss.size() != 1) { return; } Object o = ss.getFirstElement(); IFile file = AdapterUtilities.getAdapter(o, IFile.class); if (file == null) { return; } // Create a menu. IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label); submenu.add(new OpenWithMenu(site.getPage(), file)); // Add the submenu. menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); }
From source file:com.hudson.hibernatesynchronizer.wizard.NewConfigurationWizardPage.java
License:GNU General Public License
/** * Tests if the current workbench selection is a suitable container to use. *///from w w w . j ava 2 s.co m private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() == 1) { Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer cont; if (obj instanceof IContainer) cont = (IContainer) obj; else cont = ((IResource) obj).getParent(); containerText.setText(cont.getFullPath().toString()); projectChanged(((IResource) obj).getProject()); } else if (obj instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) obj; containerText.setText(frag.getPath().toString()); projectChanged(frag.getJavaProject().getProject()); } else if (obj instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) obj; containerText.setText(root.getPath().toString()); projectChanged(root.getJavaProject().getProject()); } else if (obj instanceof IJavaProject) { IJavaProject proj = (IJavaProject) obj; containerText.setText("/" + proj.getProject().getName()); projectChanged(proj.getProject()); } else if (obj instanceof IProject) { IProject proj = (IProject) obj; containerText.setText("/" + proj.getName()); projectChanged(proj); } } } fileText.setText("hibernate.cfg.xml"); }
From source file:com.hudson.hibernatesynchronizer.wizard.NewMappingWizardPage.java
License:GNU General Public License
public Composite addConfiguration(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout);//from w ww.j av a 2 s .co m layout.numColumns = 3; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); label.setText("&Container:"); containerText = new Text(container, SWT.BORDER | SWT.SINGLE); containerText.setEnabled(false); containerText.setBackground(new Color(null, 255, 255, 255)); GridData gd = new GridData(); gd.widthHint = 250; containerText.setLayoutData(gd); containerText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); Button containerButton = new Button(container, SWT.NATIVE); containerButton.setText("Browse"); containerButton.addMouseListener(new ContainerMouseListener(this)); label = new Label(container, SWT.NULL); gd = new GridData(); gd.grabExcessHorizontalSpace = true; gd.horizontalSpan = 3; label.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("&Driver:"); driverText = new Text(container, SWT.BORDER | SWT.SINGLE); driverText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); driverText.setEnabled(false); driverText.setBackground(new Color(null, 255, 255, 255)); gd = new GridData(); gd.widthHint = 250; driverText.setLayoutData(gd); Button driverButton = new Button(container, SWT.NATIVE); driverButton.setText("Browse"); driverButton.addMouseListener(new DriverMouseListener(this)); label = new Label(container, SWT.NULL); label.setText("&Database URL:"); databaseUrlText = new Text(container, SWT.BORDER | SWT.SINGLE); databaseUrlText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); gd = new GridData(); gd.horizontalSpan = 2; gd.widthHint = 250; databaseUrlText.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("&Username:"); usernameText = new Text(container, SWT.BORDER | SWT.SINGLE); usernameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); gd = new GridData(); gd.horizontalSpan = 2; gd.widthHint = 150; usernameText.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("&Password:"); passwordText = new Text(container, SWT.BORDER | SWT.SINGLE); passwordText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); passwordText.setEchoChar('*'); gd = new GridData(); gd.horizontalSpan = 2; gd.widthHint = 150; passwordText.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("Table pattern:"); tablePattern = new Text(container, SWT.BORDER | SWT.SINGLE); tablePattern.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); tablePattern.setEnabled(true); tablePattern.setBackground(new Color(null, 255, 255, 255)); gd = new GridData(); gd.horizontalSpan = 2; gd.widthHint = 250; tablePattern.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("Schema pattern:"); schemaPattern = new Text(container, SWT.BORDER | SWT.SINGLE); schemaPattern.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); schemaPattern.setEnabled(true); schemaPattern.setBackground(new Color(null, 255, 255, 255)); gd = new GridData(); gd.horizontalSpan = 2; gd.widthHint = 250; schemaPattern.setLayoutData(gd); label = new Label(container, SWT.NULL); label.setText("Tables"); table = new Table(container, SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.CHECK); table.setVisible(true); table.setLinesVisible(false); table.setHeaderVisible(false); table.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { dialogChanged(); } public void widgetDefaultSelected(SelectionEvent e) { } }); GridData data = new GridData(); data.heightHint = 150; data.widthHint = 250; table.setLayoutData(data); // create the columns TableColumn nameColumn = new TableColumn(table, SWT.LEFT); ColumnLayoutData nameColumnLayout = new ColumnWeightData(100, false); // set columns in Table layout TableLayout tableLayout = new TableLayout(); tableLayout.addColumnData(nameColumnLayout); table.setLayout(tableLayout); Composite buttonContainer = new Composite(container, SWT.NULL); buttonContainer.setLayout(new GridLayout(1, true)); gd = new GridData(); gd.verticalAlignment = GridData.BEGINNING; gd.horizontalAlignment = GridData.BEGINNING; buttonContainer.setLayoutData(gd); tableRefreshButton = new Button(buttonContainer, SWT.PUSH); tableRefreshButton.setText("Refresh"); tableRefreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableRefreshButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask("Refreshing tables...", 21); refreshTables(monitor); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }); } catch (Exception exc) { } } }); selectAllButton = new Button(buttonContainer, SWT.PUSH); selectAllButton.setText("Select All"); selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); selectAllButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { for (int i = 0; i < table.getItemCount(); i++) { table.getItem(i).setChecked(true); } dialogChanged(); } catch (Exception exc) { } } }); selectNoneButton = new Button(buttonContainer, SWT.PUSH); selectNoneButton.setText("Select None"); selectNoneButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); selectNoneButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { for (int i = 0; i < table.getItemCount(); i++) { table.getItem(i).setChecked(false); } dialogChanged(); } catch (Exception exc) { } } }); label = new Label(container, SWT.NULL); label.setText("&Package:"); packageText = new Text(container, SWT.BORDER | SWT.SINGLE); packageText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); gd = new GridData(); gd.widthHint = 250; packageText.setLayoutData(gd); packageButton = new Button(container, SWT.NATIVE); packageButton.setText("Browse"); packageButton.addMouseListener(new MouseListener() { public void mouseDown(MouseEvent e) { if (null != project) { try { IJavaSearchScope searchScope = SearchEngine.createWorkspaceScope(); SelectionDialog sd = JavaUI.createPackageDialog(getShell(), project, IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS); sd.open(); Object[] objects = sd.getResult(); if (null != objects && objects.length > 0) { IPackageFragment pf = (IPackageFragment) objects[0]; packageText.setText(pf.getElementName()); } } catch (JavaModelException jme) { jme.printStackTrace(); } } } public void mouseDoubleClick(MouseEvent e) { } public void mouseUp(MouseEvent e) { } }); if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() == 1) { Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer cont; if (obj instanceof IContainer) cont = (IContainer) obj; else cont = ((IResource) obj).getParent(); containerText.setText(cont.getFullPath().toString()); projectChanged(cont.getProject()); } else if (obj instanceof IPackageFragment) { IPackageFragment frag = (IPackageFragment) obj; containerText.setText(frag.getPath().toString()); projectChanged(frag.getJavaProject().getProject()); } else if (obj instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) obj; containerText.setText(root.getPath().toString()); projectChanged(root.getJavaProject().getProject()); } else if (obj instanceof IJavaProject) { IJavaProject proj = (IJavaProject) obj; containerText.setText("/" + proj.getProject().getName()); projectChanged(proj.getProject()); } else if (obj instanceof IProject) { IProject proj = (IProject) obj; containerText.setText("/" + proj.getName()); projectChanged(proj); } } } containerText.forceFocus(); initialize(); dialogChanged(); return container; }
From source file:com.hudson.hibernatesynchronizer.wizard.NewMappingWizardPage.java
License:GNU General Public License
/** * Tests if the current workbench selection is a suitable container to use. *//*from w w w . ja v a 2s. c o m*/ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) return; Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container; if (obj instanceof IContainer) container = (IContainer) obj; else container = ((IResource) obj).getParent(); containerText.setText(container.getFullPath().toString()); } } }