List of usage examples for org.eclipse.jface.viewers IStructuredSelection getFirstElement
public Object getFirstElement();
null
if the selection is empty. From source file:com.android.ide.eclipse.apt.internal.handlers.AptHandler.java
License:Apache License
private IResource extractSelection(final ISelection sel) { if (!(sel instanceof IStructuredSelection)) { return null; }/* w ww . j av a2s . c o m*/ final IStructuredSelection ss = (IStructuredSelection) sel; final Object element = ss.getFirstElement(); if (element instanceof IResource) { return (IResource) element; } if (!(element instanceof IAdaptable)) { return null; } final IAdaptable adaptable = (IAdaptable) element; final Object adapter = adaptable.getAdapter(IResource.class); return (IResource) adapter; }
From source file:com.android.ide.eclipse.auidt.internal.ui.ConfigurationSelector.java
License:Open Source License
/** * Creates the selector.//from w ww .j a v a2 s .com * <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.ide.eclipse.editors.resources.explorer.ResourceExplorerView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { mTree = new Tree(parent, SWT.SINGLE | SWT.VIRTUAL); mTree.setLayoutData(new GridData(GridData.FILL_BOTH)); mTree.setHeaderVisible(true);// ww w . j a va 2 s . c om mTree.setLinesVisible(true); final IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore(); // create 2 columns. The main one with the resources, and an "info" column. createTreeColumn(mTree, "Resources", SWT.LEFT, "abcdefghijklmnopqrstuvwxz", -1, PREFS_COLUMN_RES, store); //$NON-NLS-2$ createTreeColumn(mTree, "Info", SWT.LEFT, "0123456789", -1, PREFS_COLUMN_2, store); //$NON-NLS-2$ // create the jface wrapper mTreeViewer = new TreeViewer(mTree); mTreeViewer.setContentProvider(new ResourceContentProvider(true /* fullLevels */)); mTreeViewer.setLabelProvider(new ResourceLabelProvider()); // listen to selection change in the workbench. IWorkbenchPage page = getSite().getPage(); page.addSelectionListener(this); // init with current selection selectionChanged(getSite().getPart(), page.getSelection()); // add support for double click. mTreeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { ISelection sel = event.getSelection(); if (sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; if (selection.size() == 1) { Object element = selection.getFirstElement(); // if it's a resourceFile, we directly open it. if (element instanceof ResourceFile) { try { IDE.openEditor(getSite().getWorkbenchWindow().getActivePage(), ((ResourceFile) element).getFile().getIFile()); } catch (PartInitException e) { } } else if (element instanceof ProjectResourceItem) { // if it's a ResourceItem, we open the first file, but only if // there's no alternate files. ProjectResourceItem item = (ProjectResourceItem) element; if (item.isEditableDirectly()) { ResourceFile[] files = item.getSourceFileArray(); if (files[0] != null) { try { IDE.openEditor(getSite().getWorkbenchWindow().getActivePage(), files[0].getFile().getIFile()); } catch (PartInitException e) { } } } } } } } }); // set up the resource manager to send us resource change notification AdtPlugin.getDefault().getResourceMonitor().addResourceEventListener(this); }
From source file:com.android.ide.eclipse.ndk.internal.actions.AddNativeAction.java
License:Open Source License
@Override public void run(IAction action) { IProject project = null;//w ww . jav a 2 s . c o m if (mSelection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) mSelection; if (ss.size() == 1) { Object obj = ss.getFirstElement(); if (obj instanceof IProject) { project = (IProject) obj; } else if (obj instanceof PlatformObject) { project = (IProject) ((PlatformObject) obj).getAdapter(IProject.class); } } } if (project != null) { AddNativeWizard wizard = new AddNativeWizard(project, mPart.getSite().getWorkbenchWindow()); WizardDialog dialog = new WizardDialog(mPart.getSite().getShell(), wizard); dialog.open(); } }
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 ww. j a v a2 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.sdkman2.AddonSitesDialog.java
License:Apache License
private void on_ButtonDelete_widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) mTableViewer.getSelection(); String selectedUrl = sel.isEmpty() ? null : sel.getFirstElement().toString(); if (selectedUrl == null) { return;/*from ww w. jav a 2 s . com*/ } MessageBox mb = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL); mb.setText("Delete add-on site"); mb.setMessage(String.format("Do you want to delete the URL %1$s?", selectedUrl)); if (mb.open() == SWT.YES) { SdkSources sources = mUpdaterData.getSources(); for (SdkSource source : sources.getSources(SdkSourceCategory.USER_ADDONS)) { if (selectedUrl.equals(source.getUrl())) { sources.remove(source); setReturnValue(true); loadList(); } } } }
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;/*from www. jav a 2 s . c om*/ } 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.sdkuilib.internal.repository.ui.AddonSitesDialog.java
License:Apache License
private void on_UserButtonDelete_widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) mUserTableViewer.getSelection(); String selectedUrl = sel.isEmpty() ? null : sel.getFirstElement().toString(); if (selectedUrl == null) { return;// w ww . j a v a2s.co m } MessageBox mb = new MessageBox(getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL); mb.setText("Delete add-on site"); mb.setMessage(String.format("Do you want to delete the URL %1$s?", selectedUrl)); if (mb.open() == SWT.YES) { for (SdkSource source : mSources.getSources(SdkSourceCategory.USER_ADDONS)) { if (selectedUrl.equals(source.getUrl())) { mSources.remove(source); setReturnValue(true); mSources.notifyChangeListeners(); break; } } } }
From source file:com.android.traceview.ProfileView.java
License:Apache License
public ProfileView(Composite parent, TraceReader reader, SelectionController selectController) { super(parent, SWT.NONE); setLayout(new GridLayout(1, false)); this.mSelectionController = selectController; mSelectionController.addObserver(this); // Add a tree viewer at the top mTreeViewer = new TreeViewer(this, SWT.MULTI | SWT.NONE); mTreeViewer.setUseHashlookup(true);/*from ww w . jav a2 s.co m*/ mProfileProvider = reader.getProfileProvider(); mProfileProvider.setTreeViewer(mTreeViewer); SelectionAdapter listener = mProfileProvider.getColumnListener(); final Tree tree = mTreeViewer.getTree(); tree.setHeaderVisible(true); tree.setLayoutData(new GridData(GridData.FILL_BOTH)); // Get the column names from the ProfileProvider String[] columnNames = mProfileProvider.getColumnNames(); int[] columnWidths = mProfileProvider.getColumnWidths(); int[] columnAlignments = mProfileProvider.getColumnAlignments(); for (int ii = 0; ii < columnWidths.length; ++ii) { TreeColumn column = new TreeColumn(tree, SWT.LEFT); column.setText(columnNames[ii]); column.setWidth(columnWidths[ii]); column.setMoveable(true); column.addSelectionListener(listener); column.setAlignment(columnAlignments[ii]); } // Add a listener to the tree so that we can make the row // height smaller. tree.addListener(SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { int fontHeight = event.gc.getFontMetrics().getHeight(); event.height = fontHeight; } }); mTreeViewer.setContentProvider(mProfileProvider); mTreeViewer.setLabelProvider(mProfileProvider.getLabelProvider()); mTreeViewer.setInput(mProfileProvider.getRoot()); // Create another composite to hold the label and text box Composite composite = new Composite(this, SWT.NONE); composite.setLayout(new GridLayout(2, false)); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add a label for the search box Label label = new Label(composite, SWT.NONE); label.setText("Find:"); // Add a text box for searching for method names mSearchBox = new Text(composite, SWT.BORDER); mSearchBox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Display display = getDisplay(); mColorNoMatch = new Color(display, 255, 200, 200); mColorMatch = mSearchBox.getBackground(); mSearchBox.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent ev) { String query = mSearchBox.getText(); if (query.length() == 0) return; findName(query); } }); // Add a key listener to the text box so that we can clear // the text box if the user presses <ESC>. mSearchBox.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.ESC) { mSearchBox.setText(""); } else if (event.keyCode == SWT.CR) { String query = mSearchBox.getText(); if (query.length() == 0) return; findNextName(query); } } }); // Also add a key listener to the tree viewer so that the // user can just start typing anywhere in the tree view. tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.ESC) { mSearchBox.setText(""); } else if (event.keyCode == SWT.BS) { // Erase the last character from the search box String text = mSearchBox.getText(); int len = text.length(); String chopped; if (len <= 1) chopped = ""; else chopped = text.substring(0, len - 1); mSearchBox.setText(chopped); } else if (event.keyCode == SWT.CR) { String query = mSearchBox.getText(); if (query.length() == 0) return; findNextName(query); } else { // Append the given character to the search box String str = String.valueOf(event.character); mSearchBox.append(str); } event.doit = false; } }); // Add a selection listener to the tree so that the user can click // on a method that is a child or parent and jump to that method. mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent ev) { ISelection sel = ev.getSelection(); if (sel.isEmpty()) return; if (sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; Object element = selection.getFirstElement(); if (element == null) return; if (element instanceof MethodData) { MethodData md = (MethodData) element; highlightMethod(md, true); } if (element instanceof ProfileData) { MethodData md = ((ProfileData) element).getMethodData(); highlightMethod(md, true); } } } }); // Add a tree listener so that we can expand the parents and children // of a method when a method is expanded. mTreeViewer.addTreeListener(new ITreeViewerListener() { @Override public void treeExpanded(TreeExpansionEvent event) { Object element = event.getElement(); if (element instanceof MethodData) { MethodData md = (MethodData) element; expandNode(md); } } @Override public void treeCollapsed(TreeExpansionEvent event) { } }); tree.addListener(SWT.MouseDown, new Listener() { @Override public void handleEvent(Event event) { Point point = new Point(event.x, event.y); TreeItem treeItem = tree.getItem(point); MethodData md = mProfileProvider.findMatchingTreeItem(treeItem); if (md == null) return; ArrayList<Selection> selections = new ArrayList<Selection>(); selections.add(Selection.highlight("MethodData", md)); mSelectionController.change(selections, "ProfileView"); if (mMethodHandler != null && (event.stateMask & SWT.MOD1) != 0) { mMethodHandler.handleMethod(md); } } }); }
From source file:com.android.uiautomator.UiAutomatorView.java
License:Apache License
public UiAutomatorView(Composite parent, int style) { super(parent, SWT.NONE); setLayout(new FillLayout()); SashForm baseSash = new SashForm(this, SWT.HORIZONTAL); mOrginialCursor = getShell().getCursor(); mCrossCursor = new Cursor(getDisplay(), SWT.CURSOR_CROSS); mScreenshotComposite = new Composite(baseSash, SWT.BORDER); mStackLayout = new StackLayout(); mScreenshotComposite.setLayout(mStackLayout); // draw the canvas with border, so the divider area for sash form can be highlighted mScreenshotCanvas = new Canvas(mScreenshotComposite, SWT.BORDER); mStackLayout.topControl = mScreenshotCanvas; mScreenshotComposite.layout();/*from ww w .j a v a2 s . c o m*/ // set cursor when enter canvas mScreenshotCanvas.addListener(SWT.MouseEnter, new Listener() { @Override public void handleEvent(Event arg0) { getShell().setCursor(mCrossCursor); } }); mScreenshotCanvas.addListener(SWT.MouseExit, new Listener() { @Override public void handleEvent(Event arg0) { getShell().setCursor(mOrginialCursor); } }); mScreenshotCanvas.addMouseListener(new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { if (mModel != null) { mModel.toggleExploreMode(); redrawScreenshot(); } if (e.button == 3) { //set menus Menu menu = new Menu(mScreenshotCanvas); mScreenshotCanvas.setMenu(menu); Menu menu1 = new Menu(menu); Menu menu2 = new Menu(menu); Menu menu3 = new Menu(menu); Menu menu4 = new Menu(menu); Menu menu5 = new Menu(menu); Menu menu6 = new Menu(menu); Menu menu7 = new Menu(menu); Menu menu8 = new Menu(menu); Menu menu9 = new Menu(menu); //set items MenuItem item1 = new MenuItem(menu, SWT.CASCADE); MenuItem item2 = new MenuItem(menu, SWT.CASCADE); MenuItem item3 = new MenuItem(menu, SWT.CASCADE); MenuItem item4 = new MenuItem(menu, SWT.CASCADE); MenuItem item5 = new MenuItem(menu, SWT.CASCADE); MenuItem item6 = new MenuItem(menu, SWT.CASCADE); MenuItem item7 = new MenuItem(menu, SWT.CASCADE); MenuItem item8 = new MenuItem(menu, SWT.CASCADE); MenuItem item9 = new MenuItem(menu, SWT.CASCADE); MenuItem item43 = new MenuItem(menu, SWT.CASCADE); MenuItem item10 = new MenuItem(menu1, SWT.NONE); MenuItem item11 = new MenuItem(menu1, SWT.NONE); MenuItem item12 = new MenuItem(menu1, SWT.NONE); MenuItem item13 = new MenuItem(menu1, SWT.NONE); MenuItem item14 = new MenuItem(menu1, SWT.NONE); MenuItem item15 = new MenuItem(menu2, SWT.NONE); MenuItem item16 = new MenuItem(menu2, SWT.NONE); MenuItem item17 = new MenuItem(menu2, SWT.NONE); MenuItem item18 = new MenuItem(menu2, SWT.NONE); MenuItem item19 = new MenuItem(menu2, SWT.NONE); MenuItem item20 = new MenuItem(menu3, SWT.NONE); MenuItem item21 = new MenuItem(menu3, SWT.NONE); MenuItem item22 = new MenuItem(menu3, SWT.NONE); MenuItem item23 = new MenuItem(menu3, SWT.NONE); MenuItem item24 = new MenuItem(menu3, SWT.NONE); MenuItem item25 = new MenuItem(menu4, SWT.NONE); MenuItem item26 = new MenuItem(menu4, SWT.NONE); MenuItem item27 = new MenuItem(menu4, SWT.NONE); MenuItem item28 = new MenuItem(menu4, SWT.NONE); MenuItem item29 = new MenuItem(menu4, SWT.NONE); MenuItem item30 = new MenuItem(menu6, SWT.NONE); MenuItem item31 = new MenuItem(menu6, SWT.NONE); MenuItem item32 = new MenuItem(menu6, SWT.NONE); MenuItem item33 = new MenuItem(menu5, SWT.NONE); MenuItem item34 = new MenuItem(menu5, SWT.NONE); MenuItem item35 = new MenuItem(menu5, SWT.NONE); MenuItem item36 = new MenuItem(menu5, SWT.NONE); MenuItem item37 = new MenuItem(menu5, SWT.NONE); MenuItem item38 = new MenuItem(menu8, SWT.NONE); MenuItem item39 = new MenuItem(menu8, SWT.NONE); MenuItem item40 = new MenuItem(menu8, SWT.NONE); MenuItem item41 = new MenuItem(menu8, SWT.NONE); MenuItem item42 = new MenuItem(menu8, SWT.NONE); MenuItem item44 = new MenuItem(menu6, SWT.NONE); //set item text item1.setText("Click"); item2.setText("Click(Refresh)"); item3.setText("longClick"); item4.setText("longClick(Refresh)"); item5.setText("editText"); item6.setText("SystemCommand"); item7.setText("SystemCommand(Refresh)"); item43.setText("Sleep"); item8.setText("Check"); item9.setText("Find"); item10.setText("id"); item11.setText("text"); item12.setText("desc"); item13.setText("class"); item14.setText("xpath"); item15.setText("id"); item16.setText("text"); item17.setText("desc"); item18.setText("class"); item19.setText("xpath"); item20.setText("id"); item21.setText("text"); item22.setText("desc"); item23.setText("class"); item24.setText("xpath"); item25.setText("id"); item26.setText("text"); item27.setText("desc"); item28.setText("class"); item29.setText("xpath"); item30.setText("Home"); item31.setText("Back"); item32.setText("Power"); item33.setText("id"); item34.setText("text"); item35.setText("desc"); item36.setText("class"); item37.setText("xpath"); item38.setText("id"); item39.setText("text"); item40.setText("desc"); item41.setText("class"); item42.setText("xpath"); item44.setText("Other"); //bind menu item1.setMenu(menu1); //item2.setMenu(menu2); item3.setMenu(menu3); //item4.setMenu(menu4); item5.setMenu(menu5); item6.setMenu(menu6); //item7.setMenu(menu7); item8.setMenu(menu8); //item9.setMenu(menu9); //add item listener //click item10-14 item10.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item10.getText(), item1.getText()); chargeText(script); //scriptTextarea.setText(script); } }); item11.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item11.getText(), item1.getText()); chargeText(script); } }); item12.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item12.getText(), item1.getText()); chargeText(script); } }); item13.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item13.getText(), item1.getText()); chargeText(script); } }); item14.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item14.getText(), item1.getText()); chargeText(script); } }); //click(refresh) item15-19 item2.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { objectClick(item2.getText(), ""); UiAutomatorViewer window = UiAutomatorViewer.getInstance(); ScreenshotAction screenshot = new ScreenshotAction(window, false); screenshot.run(); } }); //longclick item20-24 item20.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item20.getText(), item3.getText()); chargeText(script); } }); item21.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item21.getText(), item3.getText()); chargeText(script); } }); item22.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item22.getText(), item3.getText()); chargeText(script); } }); item23.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item23.getText(), item3.getText()); chargeText(script); } }); item24.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByAction(item24.getText(), item3.getText()); chargeText(script); } }); //longclick(refresh) item4.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { objectClick(item4.getText(), ""); UiAutomatorViewer window = UiAutomatorViewer.getInstance(); ScreenshotAction screenshot = new ScreenshotAction(window, false); screenshot.run(); } }); //edittext item33-37 item33.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input id", "please input", null, null); if (dialog.open() == InputDialog.OK) { String script = getScriptByValue(item33.getText(), dialog.getValue()); chargeText(script); } } }); item34.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input text", "please input", null, null); if (dialog.open() == InputDialog.OK) { String script = getScriptByValue(item34.getText(), dialog.getValue()); chargeText(script); } } }); item35.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input desc", "please input", null, null); if (dialog.open() == InputDialog.OK) { String script = getScriptByValue(item35.getText(), dialog.getValue()); chargeText(script); } } }); item36.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input class", "please input", null, null); if (dialog.open() == InputDialog.OK) { String script = getScriptByValue(item36.getText(), dialog.getValue()); chargeText(script); } } }); item37.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input xpath", "please input", null, null); if (dialog.open() == InputDialog.OK) { String script = getScriptByValue(item37.getText(), dialog.getValue()); chargeText(script); } } }); //systemcommand item30.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByCommand(item30.getText(), "3"); chargeText(script); } }); item31.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByCommand(item31.getText(), "4"); chargeText(script); } }); item32.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String script = getScriptByCommand(item32.getText(), "26"); chargeText(script); } }); item44.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input text", "please input", null, null); if (dialog.open() == InputDialog.OK && dialog.getValue() != "") { String script = getScriptByCommand(item44.getText(), dialog.getValue()); chargeText(script); } else { //MessageDialog mdialog=new MessageDialog(getShell(), null, null, "please enter text", MessageDialog.WARNING, null, MessageDialog.WARNING); //mdialog.open(); dialog.open(); } } }); //systemcommand(refresh) item7.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dialog = new InputDialog(getShell(), "please input keyevent", "please input", null, null); if (dialog.open() == InputDialog.OK) { objectClick(item7.getText(), dialog.getValue()); UiAutomatorViewer window = UiAutomatorViewer.getInstance(); ScreenshotAction screenshot = new ScreenshotAction(window, false); screenshot.run(); } } }); } } private String getRes(String res) { String Res = ((UiNode) mModel.getSelectedNode()).getAttribute(res); return Res; } private String getScriptByAction(String id, String ac) { // TODO Auto-generated methoad stub String script = "driver"; String res = ""; switch (id) { case "id": res = getRes("resource-id"); script += ".findElementById(\"" + res + "\")."; script += chargeAction(ac); break; case "text": res = getRes("text"); script += ".findElementByText(\"" + res + "\")."; script += chargeAction(ac); break; case "class": res = getRes("class"); script += ".findElementByClassName(\"" + res + "\")."; script += chargeAction(ac); break; case "desc": res = getRes("content-desc"); script += ".findElementByContent(\"" + res + "\")."; script += chargeAction(ac); break; case "xpath": res = getRes("xpath"); script += ".findElementByXpath(\"" + res + "\")."; script += chargeAction(ac); break; } return script; } private String getScriptByCommand(String id, String value) { String script = "driver"; switch (id) { case "Home": script += ".sendKeys(\"" + value + "\")"; break; case "Back": script += ".sendKeys(\"" + value + "\")"; break; case "Power": script += ".sendKeys(\"" + value + "\")"; break; case "Other": script += ".sendKeys(\"" + value + "\")"; break; } return script; } private String getScriptByValue(String id, String value) { // TODO Auto-generated method stub String script = "driver"; String res = ""; switch (id) { case "id": res = getRes("resource-id"); script += ".findElementById(\"" + res + "\").sendKeys(\"" + value + "\")"; break; case "text": res = getRes("text"); script += ".findElementByText(\"" + res + "\").sendKeys(\"" + value + "\")"; break; case "class": res = getRes("class"); script += ".findElementByClassName(\"" + res + "\").sendKeys(\"" + value + "\")"; break; case "desc": res = getRes("content-desc"); script += ".findElementByContent(\"" + res + "\").sendKeys(\"" + value + "\")"; break; case "xpath": res = getRes("xpath"); script += ".findElementByXpath(\"" + res + "\").sendKeys(\"" + value + "\")"; break; } return script; } private String chargeAction(String ac) { String ca = ""; switch (ac) { case "Click": ca = "click();"; break; case "longClick": ca = "longclick();"; break; } return ca; } private void chargeText(String res) { if (scriptTextarea.getText().isEmpty()) { scriptTextarea.append(res); } else { scriptTextarea.append(System.getProperty("line.separator") + res); } } private void objectClick(String ac, String value) { Rectangle rect = mModel.getCurrentDrawingRect(); String adbStr = ""; switch (ac) { case "Click(Refresh)": adbStr = "adb shell input tap " + (rect.x + rect.width / 2) + " " + (rect.y + rect.height / 2); break; case "LongClick(Refresh)": adbStr = "adb shell input tap " + (rect.x + rect.width / 2) + " " + (rect.y + rect.height / 2); break; case "SystemCommand(Refresh)": adbStr = "adb shell input keyevent " + value + ""; break; } try { System.out.println(adbStr); Runtime.getRuntime().exec(adbStr); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); mScreenshotCanvas.addPaintListener(new PaintListener() { @Override public void paintControl(PaintEvent e) { if (mScreenshot != null) { updateScreenshotTransformation(); // shifting the image here, so that there's a border around screen shot // this makes highlighting red rectangles on the screen shot edges more visible Transform t = new Transform(e.gc.getDevice()); t.translate(mDx, mDy); t.scale(mScale, mScale); e.gc.setTransform(t); e.gc.drawImage(mScreenshot, 0, 0); // this resets the transformation to identity transform, i.e. no change // we don't use transformation here because it will cause the line pattern // and line width of highlight rect to be scaled, causing to appear to be blurry e.gc.setTransform(null); if (mModel.shouldShowNafNodes()) { // highlight the "Not Accessibility Friendly" nodes e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_YELLOW)); e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_YELLOW)); for (Rectangle r : mModel.getNafNodes()) { e.gc.setAlpha(50); e.gc.fillRectangle(mDx + getScaledSize(r.x), mDy + getScaledSize(r.y), getScaledSize(r.width), getScaledSize(r.height)); e.gc.setAlpha(255); e.gc.setLineStyle(SWT.LINE_SOLID); e.gc.setLineWidth(2); e.gc.drawRectangle(mDx + getScaledSize(r.x), mDy + getScaledSize(r.y), getScaledSize(r.width), getScaledSize(r.height)); } } // draw the search result rects if (mSearchResult != null) { for (BasicTreeNode result : mSearchResult) { if (result instanceof UiNode) { UiNode uiNode = (UiNode) result; Rectangle rect = new Rectangle(uiNode.x, uiNode.y, uiNode.width, uiNode.height); e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_YELLOW)); e.gc.setLineStyle(SWT.LINE_DASH); e.gc.setLineWidth(1); e.gc.drawRectangle(mDx + getScaledSize(rect.x), mDy + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height)); } } } // draw the mouseover rects Rectangle rect = mModel.getCurrentDrawingRect(); if (rect != null) { e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED)); if (mModel.isExploreMode()) { // when we highlight nodes dynamically on mouse move, // use dashed borders e.gc.setLineStyle(SWT.LINE_DASH); e.gc.setLineWidth(1); } else { // when highlighting nodes on tree node selection, // use solid borders e.gc.setLineStyle(SWT.LINE_SOLID); e.gc.setLineWidth(2); } e.gc.drawRectangle(mDx + getScaledSize(rect.x), mDy + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height)); } } } }); mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() { @Override public void mouseMove(MouseEvent e) { if (mModel != null) { int x = getInverseScaledSize(e.x - mDx); int y = getInverseScaledSize(e.y - mDy); // show coordinate coordinateLabel.setText(String.format("(%d,%d)", x, y)); if (mModel.isExploreMode()) { BasicTreeNode node = mModel.updateSelectionForCoordinates(x, y); if (node != null) { updateTreeSelection(node); } } } } }); mSetScreenshotComposite = new Composite(mScreenshotComposite, SWT.NONE); mSetScreenshotComposite.setLayout(new GridLayout()); final Button setScreenshotButton = new Button(mSetScreenshotComposite, SWT.PUSH); setScreenshotButton.setText("Specify Screenshot..."); setScreenshotButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent arg0) { FileDialog fd = new FileDialog(setScreenshotButton.getShell()); fd.setFilterExtensions(new String[] { "*.png" }); if (mModelFile != null) { fd.setFilterPath(mModelFile.getParent()); } String screenshotPath = fd.open(); if (screenshotPath == null) { return; } ImageData[] data; try { data = new ImageLoader().load(screenshotPath); } catch (Exception e) { return; } // "data" is an array, probably used to handle images that has multiple frames // i.e. gifs or icons, we just care if it has at least one here if (data.length < 1) { return; } mScreenshot = new Image(Display.getDefault(), data[0]); redrawScreenshot(); } }); // right sash is split into 2 parts: upper-right and lower-right // both are composites with borders, so that the horizontal divider can be highlighted by // the borders SashForm rightSash = new SashForm(baseSash, SWT.VERTICAL); // upper-right base contains the toolbar and the tree Composite upperRightBase = new Composite(rightSash, SWT.BORDER); upperRightBase.setLayout(new GridLayout(1, false)); ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); toolBarManager.add(new ExpandAllAction(this)); toolBarManager.add(new ToggleNafAction(this)); ToolBar searchtoolbar = toolBarManager.createControl(upperRightBase); // add search box and navigation buttons for search results ToolItem itemSeparator = new ToolItem(searchtoolbar, SWT.SEPARATOR | SWT.RIGHT); searchTextarea = new Text(searchtoolbar, SWT.BORDER | SWT.SINGLE | SWT.SEARCH); searchTextarea.pack(); itemSeparator.setWidth(searchTextarea.getBounds().width); itemSeparator.setControl(searchTextarea); itemPrev = new ToolItem(searchtoolbar, SWT.SIMPLE); itemPrev.setImage(ImageHelper.loadImageDescriptorFromResource("images/prev.png").createImage()); itemNext = new ToolItem(searchtoolbar, SWT.SIMPLE); itemNext.setImage(ImageHelper.loadImageDescriptorFromResource("images/next.png").createImage()); itemDeleteAndInfo = new ToolItem(searchtoolbar, SWT.SIMPLE); itemDeleteAndInfo.setImage(ImageHelper.loadImageDescriptorFromResource("images/delete.png").createImage()); itemDeleteAndInfo.setToolTipText("Clear search results"); coordinateLabel = new ToolItem(searchtoolbar, SWT.SIMPLE); coordinateLabel.setText(""); coordinateLabel.setEnabled(false); // add search function searchTextarea.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent event) { if (event.keyCode == SWT.CR) { String term = searchTextarea.getText(); if (!term.isEmpty()) { if (term.equals(mLastSearchedTerm)) { nextSearchResult(); return; } clearSearchResult(); mSearchResult = mModel.searchNode(term); if (!mSearchResult.isEmpty()) { mSearchResultIndex = 0; updateSearchResultSelection(); mLastSearchedTerm = term; } } } } @Override public void keyPressed(KeyEvent event) { } }); SelectionListener l = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent se) { if (se.getSource() == itemPrev) { prevSearchResult(); } else if (se.getSource() == itemNext) { nextSearchResult(); } else if (se.getSource() == itemDeleteAndInfo) { searchTextarea.setText(""); clearSearchResult(); } } }; itemPrev.addSelectionListener(l); itemNext.addSelectionListener(l); itemDeleteAndInfo.addSelectionListener(l); searchtoolbar.pack(); searchtoolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mTreeViewer = new TreeViewer(upperRightBase, SWT.NONE); mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider()); // default LabelProvider uses toString() to generate text to display mTreeViewer.setLabelProvider(new LabelProvider()); mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { BasicTreeNode selectedNode = null; if (event.getSelection() instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); Object o = selection.getFirstElement(); if (o instanceof BasicTreeNode) { selectedNode = (BasicTreeNode) o; } } mModel.setSelectedNode(selectedNode); redrawScreenshot(); if (selectedNode != null) { loadAttributeTable(); } } }); Tree tree = mTreeViewer.getTree(); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // move focus so that it's not on tool bar (looks weird) tree.setFocus(); // lower-right base contains the detail group Composite lowerRightBase = new Composite(rightSash, SWT.BORDER); lowerRightBase.setLayout(new FillLayout()); Group grpNodeDetail = new Group(lowerRightBase, SWT.NONE); grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL)); grpNodeDetail.setText("Node Detail"); Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE); TableColumnLayout columnLayout = new TableColumnLayout(); tableContainer.setLayout(columnLayout); mTableViewer = new TableViewer(tableContainer, SWT.NONE | SWT.FULL_SELECTION); Table table = mTableViewer.getTable(); table.setLinesVisible(true); // use ArrayContentProvider here, it assumes the input to the TableViewer // is an array, where each element represents a row in the table mTableViewer.setContentProvider(new ArrayContentProvider()); TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE); TableColumn tblclmnKey = tableViewerColumnKey.getColumn(); tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof AttributePair) { // first column, shows the attribute name return ((AttributePair) element).key; } return super.getText(element); } }); columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true)); TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE); tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer)); TableColumn tblclmnValue = tableViewerColumnValue.getColumn(); columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true)); tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof AttributePair) { // second column, shows the attribute value return ((AttributePair) element).value; } return super.getText(element); } }); SashForm downSash = new SashForm(baseSash, SWT.VERTICAL | SWT.BORDER); scriptTextarea = new Text(downSash, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); downSash.setMaximizedControl(scriptTextarea); scriptTextarea.pack(); scriptTextarea.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent event) { if (event.keyCode == SWT.CR) { String lastterm = scriptTextarea.getText(); if (!lastterm.isEmpty()) { if (count == 0) { MessageDialog.openWarning(shell, "", ""); term = lastterm; scriptTextarea.setText(term); count++; } else { term += lastterm; scriptTextarea.setText(term); count++; } } } } @Override public void keyPressed(KeyEvent event) { } }); baseSash.setWeights(new int[] { 4, 3, 3 }); // sets the ratio of the vertical split: left 5 vs right 3 //baseSash.setWeights(new int[] {5,3}); }