List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:com.amazonaws.eclipse.datatools.sqltools.tablewizard.simpledb.ui.popup.actions.NewAttributeWizardAction.java
License:Apache License
public boolean performFinish(final ConnectionInfo info, final String domainName, final String attrName, final Object node) { WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override/*from ww w.j a va 2s . com*/ protected void execute(final IProgressMonitor monitor) { try { // SQLDevToolsConfiguration f = SQLToolsFacade.getConfigurationByProfileName(info.getConnectionProfile().getName()); // ConnectionService conService = f.getConnectionService(); // DatabaseVendorDefinitionId dbVendorId = ProfileUtil.getDatabaseVendorDefinitionId(profileName); // DatabaseIdentifier databaseIdentifier = new DatabaseIdentifier(info.getConnectionProfile().getName(), info.getDatabaseName()); // Connection conn = conService.createConnection(databaseIdentifier, true); Connection conn = info.getSharedConnection(); // conn.prepareStatement("create domain " + domainName).executeUpdate(); JdbcConnection jdbcConn = (JdbcConnection) conn; jdbcConn.addPendingColumn(domainName, attrName); CommonViewer cViewer = (CommonViewer) NewAttributeWizardAction.this.event.getSource(); TreePath[] expanded = cViewer.getExpandedTreePaths(); // Object selected = ((IStructuredSelection) NewAttributeWizardAction.this.event.getSelection()) // .getFirstElement(); IVirtualNode vnode = (IVirtualNode) node; ICatalogObject table = (ICatalogObject) vnode.getParent(); table.refresh(); // if (NewAttributeWizardAction.this.event.getSelection() instanceof IStructuredSelection // && ((IStructuredSelection) NewAttributeWizardAction.this.event.getSelection()).getFirstElement() instanceof EObject) { // EObject o = (EObject) ((IStructuredSelection) NewAttributeWizardAction.this.event.getSelection()) // .getFirstElement(); // cViewer.expandToLevel(o, 1); // } // cViewer.refresh(); // Object col = ((JDBCTable) table).getColumns().get(((JDBCTable) table).getColumns().size() - 1); for (TreePath path : expanded) { cViewer.expandToLevel(path, 0); } cViewer.setSelection(new StructuredSelection(table), true); // cViewer.reveal(table); // cViewer.expandToLevel(table, 2); // cViewer.setSelection(new StructuredSelection(table)); // cViewer.reveal(((IStructuredSelection) NewAttributeWizardAction.this.event.getSelection()).getFirstElement()); // cViewer.expandToLevel(((IStructuredSelection) NewAttributeWizardAction.this.event.getSelection()) // .getFirstElement(), 1); // cViewer.setSelection(new StructuredSelection(((IStructuredSelection) NewAttributeWizardAction.this.event // .getSelection()).getFirstElement())); } catch (Exception e) { e.printStackTrace(); } finally { if (monitor != null) { monitor.done(); } } } }; try { UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().run(false, true, operation); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:com.amazonaws.eclipse.datatools.sqltools.tablewizard.simpledb.ui.popup.actions.NewDomainWizardAction.java
License:Apache License
public boolean performFinish(final ConnectionInfo info, final String domainName, final Database db) { WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override// w w w . j a v a2 s .c o m protected void execute(final IProgressMonitor monitor) { try { // SQLDevToolsConfiguration f = SQLToolsFacade.getConfigurationByProfileName(info.getConnectionProfile().getName()); // ConnectionService conService = f.getConnectionService(); // DatabaseVendorDefinitionId dbVendorId = ProfileUtil.getDatabaseVendorDefinitionId(profileName); // DatabaseIdentifier databaseIdentifier = new DatabaseIdentifier(info.getConnectionProfile().getName(), info.getDatabaseName()); // Connection conn = conService.createConnection(databaseIdentifier, true); Connection conn = info.getSharedConnection(); conn.prepareStatement("create domain " + JdbcStatement.DELIMITED_IDENTIFIER_QUOTE + domainName //$NON-NLS-1$ + JdbcStatement.DELIMITED_IDENTIFIER_QUOTE).executeUpdate(); CommonViewer cViewer = (CommonViewer) NewDomainWizardAction.this.event.getSource(); TreePath[] expanded = cViewer.getExpandedTreePaths(); // Object selected = ((IStructuredSelection) NewDomainWizardAction.this.event.getSelection()).getFirstElement(); ((ICatalogObject) db).refresh(); for (TreePath path : expanded) { cViewer.expandToLevel(path, 0); } cViewer.setSelection(new StructuredSelection(db), true); } catch (Exception e) { Status status = new Status(IStatus.ERROR, "com.amazonaws.eclipse.datatools.enablement.simpledb", "Unable to create domain: " + e.getMessage(), e); StatusManager.getManager().handle(status, StatusManager.SHOW); e.printStackTrace(); } finally { if (monitor != null) { monitor.done(); } } } }; try { UIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().run(false, true, operation); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:com.amazonaws.eclipse.ec2.ui.views.instances.InstanceSelectionTable.java
License:Apache License
/** * Sets the list of instances to be displayed in the instance table. * * @param instances/*from w ww .j a v a 2s . c o m*/ * The list of instances to be displayed in the instance table. * @param securityGroupMap * A map of instance IDs to a list of security groups in which * those instances were launched. */ private void setInput(final List<Instance> instances, final Map<String, List<String>> securityGroupMap) { Display.getDefault().asyncExec(new Runnable() { @SuppressWarnings("unchecked") public void run() { /* * Sometimes we see cases where the content provider for a table * viewer is null, so we check for that here to avoid causing an * unhandled event loop exception. All InstanceSelectionTables * should always have a content provider set in the constructor, * but for some reason we occasionally still see this happen. */ if (viewer.getContentProvider() == null) { return; } StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection(); viewer.setInput(new InstancesViewInput(instances, securityGroupMap)); packColumns(); Set<String> instanceIds = new HashSet<String>(); for (Instance instance : (List<Instance>) currentSelection.toList()) { instanceIds.add(instance.getInstanceId()); } List<Instance> newSelectedInstances = new ArrayList<Instance>(); for (TreeItem treeItem : viewer.getTree().getItems()) { Instance instance = (Instance) treeItem.getData(); if (instanceIds.contains(instance.getInstanceId())) { newSelectedInstances.add(instance); } } viewer.setSelection(new StructuredSelection(newSelectedInstances)); } }); }
From source file:com.amazonaws.eclipse.rds.RDSPlugin.java
License:Apache License
/** * Connects the specified connection profile and selects and reveals it in * the Data Source Explorer view.//from w w w .j a va 2s .com * * @param profile * The connection profile to connect and reveal. */ public static void connectAndReveal(final IConnectionProfile profile) { IStatus connectStatus = profile.connect(); if (connectStatus.isOK() == false) { Status status = new Status(IStatus.ERROR, RDSPlugin.PLUGIN_ID, "Unable to connect to the database. Make sure your password is correct and make sure you can access your database through your network and any firewalls you may be connecting through."); StatusManager.getManager().handle(status, StatusManager.BLOCK | StatusManager.LOG); return; } Display.getDefault().syncExec(new Runnable() { public void run() { try { IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .showView("org.eclipse.datatools.connectivity.DataSourceExplorerNavigator"); if (view instanceof DataSourceExplorerView) { DataSourceExplorerView dse = (DataSourceExplorerView) view; StructuredSelection selection = new StructuredSelection(profile); dse.getCommonViewer().setSelection(selection, true); } } catch (Exception e) { Status status = new Status(IStatus.ERROR, RDSPlugin.PLUGIN_ID, "Unable to reveal connection profile: " + e.getMessage(), e); StatusManager.getManager().handle(status, StatusManager.LOG); } } }); }
From source file:com.amitinside.e4.rcp.todo.parts.TodoDeletionPart.java
License:Apache License
private void updateViewer(List<Todo> todos) { viewer.setInput(todos);/*w ww . j ava2 s.c o m*/ if (todos.size() > 0) { viewer.setSelection(new StructuredSelection(todos.get(0))); } }
From source file:com.android.ide.eclipse.adt.internal.editors.manifest.model.UiPackageAttributeNode.java
License:Open Source License
/** * Displays and handles a "Create Package Wizard". * * This is invoked by doLabelClick() when clicking on the hyperlink label with an * empty package text field./*from w w w.j ava 2s. co m*/ */ private void createNewPackage() { OpenNewPackageWizardAction action = new OpenNewPackageWizardAction(); IProject project = getProject(); action.setSelection(new StructuredSelection(project)); action.run(); IJavaElement element = action.getCreatedElement(); if (element != null && element.exists() && element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { setPackageTextField((IPackageFragment) element); } }
From source file:com.android.ide.eclipse.adt.internal.editors.manifest.pages.OverviewExportPart.java
License:Open Source License
public OverviewExportPart(OverviewPage overviewPage, final Composite body, FormToolkit toolkit, ManifestEditor editor) {/*from w w w . j a va2 s . co m*/ super(body, toolkit, Section.TWISTIE | Section.EXPANDED, true /* description */); mOverviewPage = overviewPage; Section section = getSection(); section.setText("Exporting"); final IProject project = getProject(); boolean isLibrary = false; if (project != null) { ProjectState state = Sdk.getProjectState(project); if (state != null) { isLibrary = state.isLibrary(); } } if (isLibrary) { section.setDescription("Library project cannot be exported."); Composite table = createTableLayout(toolkit, 2 /* numColumns */); createFormText(table, toolkit, true, "<form></form>", false /* setupLayoutData */); } else { section.setDescription("To export the application for distribution, you have the following options:"); Composite table = createTableLayout(toolkit, 2 /* numColumns */); StringBuffer buf = new StringBuffer(); buf.append("<form><li><a href=\"wizard\">"); //$NON-NLS-1$ buf.append("Use the Export Wizard"); buf.append("</a>"); //$NON-NLS-1$ buf.append(" to export and sign an APK"); buf.append("</li>"); //$NON-NLS-1$ buf.append("<li><a href=\"manual\">"); //$NON-NLS-1$ buf.append("Export an unsigned APK"); buf.append("</a>"); //$NON-NLS-1$ buf.append(" and sign it manually"); buf.append("</li></form>"); //$NON-NLS-1$ FormText text = createFormText(table, toolkit, true, buf.toString(), false /* setupLayoutData */); text.addHyperlinkListener(new HyperlinkAdapter() { @Override public void linkActivated(HyperlinkEvent e) { if (project != null) { if ("manual".equals(e.data)) { //$NON-NLS-1$ // now we can export an unsigned apk for the project. ExportHelper.exportUnsignedReleaseApk(project); } else { // call the export wizard StructuredSelection selection = new StructuredSelection(project); ExportWizard wizard = new ExportWizard(); wizard.init(PlatformUI.getWorkbench(), selection); WizardDialog dialog = new WizardDialog(body.getShell(), wizard); dialog.open(); } } } }); } layoutChanged(); }
From source file:com.android.ide.eclipse.adt.internal.launch.DeviceChooserDialog.java
License:Open Source License
/** * Look for a default device to select. This is done by looking for the running * clients on each device and finding one similar to the one being launched. * <p/>/*from w w w. j a v a 2s. c o m*/ * This is done every time the device list changed unless there is a already selection. */ private void updateDefaultSelection() { if (mDeviceTable.getSelectionCount() == 0) { AndroidDebugBridge bridge = AndroidDebugBridge.getBridge(); IDevice[] devices = bridge.getDevices(); for (IDevice device : devices) { Client[] clients = device.getClients(); for (Client client : clients) { if (mPackageName.equals(client.getClientData().getClientDescription())) { // found a match! Select it. mViewer.setSelection(new StructuredSelection(device)); handleSelection(device); // and we're done. return; } } } } handleDeviceSelection(); }
From source file:com.android.ide.eclipse.adt.internal.ui.ConfigurationSelector.java
License:Open Source License
/** * Creates the selector.//from w w w . jav a2 s .c om * <p/> * The {@link SelectorMode} changes the behavior of the selector depending on what is being * edited (a device config, a resource config, a given configuration). * * @param parent the composite parent. * @param mode the mode for the selector. */ public ConfigurationSelector(Composite parent, SelectorMode mode) { super(parent, SWT.NONE); mMode = mode; mBaseConfiguration.createDefault(); GridLayout gl = new GridLayout(4, false); gl.marginWidth = gl.marginHeight = 0; setLayout(gl); // first column is the first table final Table fullTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); fullTable.setLayoutData(new GridData(GridData.FILL_BOTH)); fullTable.setHeaderVisible(true); fullTable.setLinesVisible(true); // create the column final TableColumn fullTableColumn = new TableColumn(fullTable, SWT.LEFT); // set the header fullTableColumn.setText("Available Qualifiers"); fullTable.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle r = fullTable.getClientArea(); fullTableColumn.setWidth(r.width); } }); mFullTableViewer = new TableViewer(fullTable); mFullTableViewer.setContentProvider(new QualifierContentProvider()); // the label provider must return the value of the label only if the mode is // CONFIG_ONLY mFullTableViewer.setLabelProvider(new QualifierLabelProvider(mMode == SelectorMode.CONFIG_ONLY)); mFullTableViewer.setInput(mBaseConfiguration); mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structSelection = (IStructuredSelection) selection; Object first = structSelection.getFirstElement(); if (first instanceof ResourceQualifier) { mAddButton.setEnabled(true); return; } } mAddButton.setEnabled(false); } }); // 2nd column is the left/right arrow button Composite buttonComposite = new Composite(this, SWT.NONE); gl = new GridLayout(1, false); gl.marginWidth = gl.marginHeight = 0; buttonComposite.setLayout(gl); buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); new Composite(buttonComposite, SWT.NONE); mAddButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); mAddButton.setText("->"); mAddButton.setEnabled(false); mAddButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) mFullTableViewer.getSelection(); Object first = selection.getFirstElement(); if (first instanceof ResourceQualifier) { ResourceQualifier qualifier = (ResourceQualifier) first; mBaseConfiguration.removeQualifier(qualifier); mSelectedConfiguration.addQualifier(qualifier); mFullTableViewer.refresh(); mSelectionTableViewer.refresh(); mSelectionTableViewer.setSelection(new StructuredSelection(qualifier), true); onChange(false /* keepSelection */); } } }); mRemoveButton = new Button(buttonComposite, SWT.BORDER | SWT.PUSH); mRemoveButton.setText("<-"); mRemoveButton.setEnabled(false); mRemoveButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) mSelectionTableViewer.getSelection(); Object first = selection.getFirstElement(); if (first instanceof ResourceQualifier) { ResourceQualifier qualifier = (ResourceQualifier) first; mSelectedConfiguration.removeQualifier(qualifier); mBaseConfiguration.addQualifier(qualifier); mFullTableViewer.refresh(); mSelectionTableViewer.refresh(); onChange(false /* keepSelection */); } } }); // 3rd column is the selected config table final Table selectionTable = new Table(this, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); selectionTable.setLayoutData(new GridData(GridData.FILL_BOTH)); selectionTable.setHeaderVisible(true); selectionTable.setLinesVisible(true); // create the column final TableColumn selectionTableColumn = new TableColumn(selectionTable, SWT.LEFT); // set the header selectionTableColumn.setText("Chosen Qualifiers"); selectionTable.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle r = selectionTable.getClientArea(); selectionTableColumn.setWidth(r.width); } }); mSelectionTableViewer = new TableViewer(selectionTable); mSelectionTableViewer.setContentProvider(new QualifierContentProvider()); // always show the qualifier value in this case. mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider(true /* showQualifierValue */)); mSelectionTableViewer.setInput(mSelectedConfiguration); mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // ignore selection changes during resfreshes in some cases. if (mOnRefresh) { return; } ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structSelection = (IStructuredSelection) selection; if (structSelection.isEmpty() == false) { Object first = structSelection.getFirstElement(); if (first instanceof ResourceQualifier) { mRemoveButton.setEnabled(true); if (mMode != SelectorMode.CONFIG_ONLY) { QualifierEditBase composite = mUiMap.get(first.getClass()); if (composite != null) { composite.setQualifier((ResourceQualifier) first); } mStackLayout.topControl = composite; mQualifierEditParent.layout(); } return; } } else { if (mMode != SelectorMode.CONFIG_ONLY) { mStackLayout.topControl = null; mQualifierEditParent.layout(); } } } mRemoveButton.setEnabled(false); } }); if (mMode != SelectorMode.CONFIG_ONLY) { // 4th column is the detail of the selected qualifier mQualifierEditParent = new Composite(this, SWT.NONE); mQualifierEditParent.setLayout(mStackLayout = new StackLayout()); mQualifierEditParent.setLayoutData(new GridData(GridData.FILL_VERTICAL)); // create the UI for all the qualifiers, and associate them to the // ResourceQualifer class. mUiMap.put(CountryCodeQualifier.class, new MCCEdit(mQualifierEditParent)); mUiMap.put(NetworkCodeQualifier.class, new MNCEdit(mQualifierEditParent)); mUiMap.put(LocaleQualifier.class, new LocaleEdit(mQualifierEditParent)); mUiMap.put(LayoutDirectionQualifier.class, new LayoutDirectionEdit(mQualifierEditParent)); mUiMap.put(SmallestScreenWidthQualifier.class, new SmallestScreenWidthEdit(mQualifierEditParent)); mUiMap.put(ScreenWidthQualifier.class, new ScreenWidthEdit(mQualifierEditParent)); mUiMap.put(ScreenHeightQualifier.class, new ScreenHeightEdit(mQualifierEditParent)); mUiMap.put(ScreenSizeQualifier.class, new ScreenSizeEdit(mQualifierEditParent)); mUiMap.put(ScreenRatioQualifier.class, new ScreenRatioEdit(mQualifierEditParent)); mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent)); mUiMap.put(UiModeQualifier.class, new UiModeEdit(mQualifierEditParent)); mUiMap.put(NightModeQualifier.class, new NightModeEdit(mQualifierEditParent)); mUiMap.put(DensityQualifier.class, new DensityEdit(mQualifierEditParent)); mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent)); mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent)); mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent)); mUiMap.put(NavigationStateQualifier.class, new NavigationStateEdit(mQualifierEditParent)); mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent)); mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent)); mUiMap.put(VersionQualifier.class, new VersionEdit(mQualifierEditParent)); } }
From source file:com.android.ide.eclipse.adt.internal.wizards.actions.OpenWizardAction.java
License:Open Source License
/** * Opens and display the Android New Project Wizard. * <p/>/* w w w. j a va2 s .c om*/ * Most of this implementation is extracted from {@link NewWizardShortcutAction#run()}. * * @param action The action that got us here. Can be null when used internally. * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ @Override public void run(IAction action) { // get the workbench and the current window IWorkbench workbench = mWorkbench != null ? mWorkbench : PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); // This code from NewWizardShortcutAction#run() gets the current window selection // and converts it to a workbench structured selection for the wizard, if possible. ISelection selection = mSelection; if (selection == null) { selection = window.getSelectionService().getSelection(); } IStructuredSelection selectionToPass = StructuredSelection.EMPTY; if (selection instanceof IStructuredSelection) { selectionToPass = (IStructuredSelection) selection; } else { // Build the selection from the IFile of the editor IWorkbenchPart part = window.getPartService().getActivePart(); if (part instanceof IEditorPart) { IEditorInput input = ((IEditorPart) part).getEditorInput(); Class<?> fileClass = LegacyResourceSupport.getFileClass(); if (input != null && fileClass != null) { Object file = Util.getAdapter(input, fileClass); if (file != null) { selectionToPass = new StructuredSelection(file); } } } } // Create the wizard and initialize it with the selection mWizard = instanciateWizard(action); mWizard.init(workbench, selectionToPass); // It's not visible yet until a dialog is created and opened Shell parent = window.getShell(); WizardDialogEx dialog = new WizardDialogEx(parent, mWizard); dialog.create(); if (mWizard instanceof IUpdateWizardDialog) { ((IUpdateWizardDialog) mWizard).updateWizardDialog(dialog); } // This code comes straight from NewWizardShortcutAction#run() Point defaultSize = dialog.getShell().getSize(); dialog.getShell().setSize(Math.max(SIZING_WIZARD_WIDTH, defaultSize.x), Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y)); window.getWorkbench().getHelpSystem().setHelp(dialog.getShell(), IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT); mDialogResult = dialog.open(); }