List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:com.android.ide.eclipse.adt.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/>/* w w w . ja v a2s. com*/ * 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(); Device[] devices = bridge.getDevices(); for (Device 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.ui.ConfigurationSelector.java
License:Open Source License
public ConfigurationSelector(Composite parent) { super(parent, SWT.NONE); mBaseConfiguration.createDefault();/*from w ww .j ava 2s . c o m*/ 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()); mFullTableViewer.setLabelProvider(new QualifierLabelProvider(false /* showQualifierValue */)); mFullTableViewer.setInput(mBaseConfiguration); mFullTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { 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()); mSelectionTableViewer.setLabelProvider(new QualifierLabelProvider(true /* showQualifierValue */)); mSelectionTableViewer.setInput(mSelectedConfiguration); mSelectionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { 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); QualifierEditBase composite = mUiMap.get(first.getClass()); if (composite != null) { composite.setQualifier((ResourceQualifier) first); } mStackLayout.topControl = composite; mQualifierEditParent.layout(); return; } } else { mStackLayout.topControl = null; mQualifierEditParent.layout(); } } mRemoveButton.setEnabled(false); } }); // 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(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent)); mUiMap.put(RegionQualifier.class, new RegionEdit(mQualifierEditParent)); mUiMap.put(ScreenOrientationQualifier.class, new OrientationEdit(mQualifierEditParent)); mUiMap.put(PixelDensityQualifier.class, new PixelDensityEdit(mQualifierEditParent)); mUiMap.put(TouchScreenQualifier.class, new TouchEdit(mQualifierEditParent)); mUiMap.put(KeyboardStateQualifier.class, new KeyboardEdit(mQualifierEditParent)); mUiMap.put(TextInputMethodQualifier.class, new TextInputEdit(mQualifierEditParent)); mUiMap.put(NavigationMethodQualifier.class, new NavigationEdit(mQualifierEditParent)); mUiMap.put(ScreenDimensionQualifier.class, new ScreenDimensionEdit(mQualifierEditParent)); }
From source file:com.android.ide.eclipse.adt.wizards.actions.OpenWizardAction.java
License:Open Source License
/** * Opens and display the Android New Project Wizard. * <p/>//w ww .j a v a 2s .c om * Most of this implementation is extracted from {@link NewWizardShortcutAction#run()}. * * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { // get the workbench and the current window IWorkbench workbench = 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 = 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 IWorkbenchWizard wizard = instanciateWizard(action); wizard.init(workbench, selectionToPass); // It's not visible yet until a dialog is created and opened Shell parent = window.getShell(); WizardDialog dialog = new WizardDialog(parent, wizard); dialog.create(); // 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); dialog.open(); }
From source file:com.android.ide.eclipse.auidt.internal.ui.ConfigurationSelector.java
License:Open Source License
/** * Creates the selector./*from www. j a va2 s. c o m*/ * <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(LanguageQualifier.class, new LanguageEdit(mQualifierEditParent)); mUiMap.put(RegionQualifier.class, new RegionEdit(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.sdkuilib.internal.repository.sdkman2.AddonSitesDialog.java
License:Apache License
private void newOrEdit(final boolean isEdit) { SdkSources sources = mUpdaterData.getSources(); final SdkSource[] knownSources = sources.getAllSources(); String title = isEdit ? "Edit Add-on Site URL" : "Add Add-on Site URL"; String msg = "Please enter the URL of the addon.xml:"; IStructuredSelection sel = (IStructuredSelection) mTableViewer.getSelection(); final String initialValue = !isEdit || sel.isEmpty() ? null : sel.getFirstElement().toString(); if (isEdit && initialValue == null) { // Edit with no actual value is not supposed to happen. Ignore this case. return;/*from w w w. ja v a 2 s .c o m*/ } InputDialog dlg = new InputDialog(getShell(), title, msg, initialValue, new IInputValidator() { public String isValid(String newText) { newText = newText == null ? null : newText.trim(); if (newText == null || newText.length() == 0) { return "Error: URL field is empty. Please enter a URL."; } // A URL should have one of the following prefixes if (!newText.startsWith("file://") && //$NON-NLS-1$ !newText.startsWith("ftp://") && //$NON-NLS-1$ !newText.startsWith("http://") && //$NON-NLS-1$ !newText.startsWith("https://")) { //$NON-NLS-1$ return "Error: The URL must start by one of file://, ftp://, http:// or https://"; } if (isEdit && newText.equals(initialValue)) { // Edited value hasn't changed. This isn't an error. return null; } // Reject URLs that are already in the source list. // URLs are generally case-insensitive (except for file:// where it all depends // on the current OS so we'll ignore this case.) for (SdkSource s : knownSources) { if (newText.equalsIgnoreCase(s.getUrl())) { return "Error: This site is already listed."; } } return null; } }); if (dlg.open() == Window.OK) { String url = dlg.getValue().trim(); if (!url.equals(initialValue)) { if (isEdit && initialValue != null) { // Remove the old value before we add the new one, which is we just // asserted will be different. for (SdkSource source : sources.getSources(SdkSourceCategory.USER_ADDONS)) { if (initialValue.equals(source.getUrl())) { sources.remove(source); break; } } } // create the source, store it and update the list SdkAddonSource newSource = new SdkAddonSource(url, null/*uiName*/); sources.add(SdkSourceCategory.USER_ADDONS, newSource); setReturnValue(true); loadList(); // select the new source IStructuredSelection newSel = new StructuredSelection(newSource); mTableViewer.setSelection(newSel, true /*reveal*/); } } }
From source file:com.android.sdkuilib.internal.repository.ui.AddonSitesDialog.java
License:Apache License
private void userNewOrEdit(final boolean isEdit) { final SdkSource[] knownSources = mSources.getAllSources(); String title = isEdit ? "Edit Add-on Site URL" : "Add Add-on Site URL"; String msg = "Please enter the URL of the addon.xml:"; IStructuredSelection sel = (IStructuredSelection) mUserTableViewer.getSelection(); final String initialValue = !isEdit || sel.isEmpty() ? null : sel.getFirstElement().toString(); if (isEdit && initialValue == null) { // Edit with no actual value is not supposed to happen. Ignore this case. return;//w w w . j a v a 2 s. c o m } InputDialog dlg = new InputDialog(getShell(), title, msg, initialValue, new IInputValidator() { @Override public String isValid(String newText) { newText = newText == null ? null : newText.trim(); if (newText == null || newText.length() == 0) { return "Error: URL field is empty. Please enter a URL."; } // A URL should have one of the following prefixes if (!newText.startsWith("file://") && //$NON-NLS-1$ !newText.startsWith("ftp://") && //$NON-NLS-1$ !newText.startsWith("http://") && //$NON-NLS-1$ !newText.startsWith("https://")) { //$NON-NLS-1$ return "Error: The URL must start by one of file://, ftp://, http:// or https://"; } if (isEdit && newText.equals(initialValue)) { // Edited value hasn't changed. This isn't an error. return null; } // Reject URLs that are already in the source list. // URLs are generally case-insensitive (except for file:// where it all depends // on the current OS so we'll ignore this case.) for (SdkSource s : knownSources) { if (newText.equalsIgnoreCase(s.getUrl())) { return "Error: This site is already listed."; } } return null; } }); if (dlg.open() == Window.OK) { String url = dlg.getValue().trim(); if (!url.equals(initialValue)) { if (isEdit && initialValue != null) { // Remove the old value before we add the new one, which is we just // asserted will be different. for (SdkSource source : mSources.getSources(SdkSourceCategory.USER_ADDONS)) { if (initialValue.equals(source.getUrl())) { mSources.remove(source); break; } } } // create the source, store it and update the list SdkSource newSource; // use url suffix to decide whether this is a SysImg or Addon; // see SdkSources.loadUserAddons() for another check like this if (url.endsWith(SdkSysImgConstants.URL_DEFAULT_FILENAME)) { newSource = new SdkSysImgSource(url, null/*uiName*/); } else { newSource = new SdkAddonSource(url, null/*uiName*/); } mSources.add(SdkSourceCategory.USER_ADDONS, newSource); setReturnValue(true); // notify sources change listeners. This will invoke our own loadUserUrlsList(). mSources.notifyChangeListeners(); // select the new source IStructuredSelection newSel = new StructuredSelection(newSource); mUserTableViewer.setSelection(newSel, true /*reveal*/); } } }
From source file:com.android.traceview.ProfileView.java
License:Apache License
private void highlightMethod(MethodData md, boolean clearSearch) { if (md == null) return;/*w w w . j a v a2s. c o m*/ // Avoid an infinite recursion if (md == mCurrentHighlightedMethod) return; if (clearSearch) { mSearchBox.setText(""); mSearchBox.setBackground(mColorMatch); } mCurrentHighlightedMethod = md; mTreeViewer.collapseAll(); // Expand this node and its children expandNode(md); StructuredSelection sel = new StructuredSelection(md); mTreeViewer.setSelection(sel, true); Tree tree = mTreeViewer.getTree(); TreeItem[] items = tree.getSelection(); if (items.length != 0) { tree.setTopItem(items[0]); // workaround a Mac bug by adding showItem(). tree.showItem(items[0]); } }
From source file:com.android.uiautomator.UiAutomatorView.java
License:Apache License
public void updateTreeSelection(BasicTreeNode node) { mTreeViewer.setSelection(new StructuredSelection(node), true); }
From source file:com.antimatterstudios.esftp.actions.Selection.java
License:Open Source License
/** * @see IActionDelegate#selectionChanged(IAction, ISelection) *///from w w w .j a va 2 s . com public void selectionChanged(IAction action, ISelection s) { if (s != null) { if (s instanceof IStructuredSelection) { m_selection = (IStructuredSelection) s; //SftpPlugin.consolePrintln(selection.toString(),1); //SftpPlugin.consolePrintln(ObjectDumper.dumpObject(selection),1); } // added this to capture if selection is the current editor view if (s instanceof ITextSelection) { IEditorPart part = Activator.getActivePage().getActiveEditor(); if (part != null) { IEditorInput input = part.getEditorInput(); IResource r = (IResource) input.getAdapter(IResource.class); if (r != null) { switch (r.getType()) { case IResource.FILE: m_selection = new StructuredSelection(r); //SftpPlugin.consolePrintln("Set:"+this.selection.toString(),1); break; } } // set selection to current editor file; } } else { //SftpPlugin.consolePrintln("Not Structure",1); //SftpPlugin.consolePrintln(ObjectDumper.dumpObject(selection),1); } } }
From source file:com.apicloud.navigator.dialogs.AddFeatureDialog.java
License:Open Source License
@Override protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.OK_ID) { if (selectFeature == null) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, Messages.AddFeatureDialog_MESSAGE); return; }//from w ww. j a va2s . com for (Feature feature : config.getFeatures()) { if (feature.getName().equals(selectFeature.getName())) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, Messages.CreateFeatureDialog_FEATURE_NAME_DUP); return; } } if (text_urlScheme.isVisible() && text_urlScheme.getText().isEmpty()) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, lblParamkey.getText().trim() + Messages.AddFeatureDialog_MESSAGE_NULL); return; } if (text_apiKey.isVisible() && text_apiKey.getText().isEmpty()) { MessageDialog.openInformation(getShell(), Messages.AddFeatureDialog_INFORMATION, lblParamvalue.getText().trim() + Messages.AddFeatureDialog_MESSAGE_NULL); return; } feature = new Feature(); feature.setName(selectFeature.getName()); if (text_urlScheme.isVisible()) { Param p = new Param(); p.setName("urlScheme"); if (feature.getName().equals("baiduMap")) { p.setName("android_api_key"); } p.setValue(text_urlScheme.getText()); feature.getParams().add(p); } if (text_apiKey.isVisible()) { Param p = new Param(); p.setName("apiKey"); if (feature.getName().equals("baiduMap")) { p.setName("ios_api_key"); } p.setValue(text_apiKey.getText()); feature.getParams().add(p); } config.addFeature(feature); TreeNode node = new TreeNode(feature); treeViewer.setInput(config.createTreeNode()); treeViewer.collapseAll(); StructuredSelection selection = new StructuredSelection(node); treeViewer.setSelection(selection, true); treeViewer.refresh(); editor.setDirty(true); editor.change(); } super.buttonPressed(buttonId); }