List of usage examples for org.eclipse.jface.viewers LabelProvider LabelProvider
public LabelProvider()
From source file:com.android.sdkuilib.internal.repository.ui.AddonSitesDialog.java
License:Apache License
void createTabUserSites(TabFolder tabFolder, TabItem userTabItem) { Composite root = new Composite(tabFolder, SWT.NONE); userTabItem.setControl(root);//w ww . j ava2 s. c o m GridLayoutBuilder.create(root).columns(2); Label label = new Label(root, SWT.NONE); GridDataBuilder.create(label).hLeft().vCenter().hSpan(2); label.setText("This lets you manage a list of user-contributed external add-on sites URLs.\n" + "\n" + "Add-on sites can provide new add-ons and extra packages.\n" + "They cannot provide standard Android platforms, system images or docs.\n" + "Adding a URL here will not allow you to clone an official Android repository."); mUserTableViewer = new TableViewer(root, SWT.BORDER | SWT.FULL_SELECTION); mUserTableViewer.setContentProvider(new SourcesContentProvider()); mUserTableViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { on_UserTableViewer_selectionChanged(event); } }); mUserTable = mUserTableViewer.getTable(); mUserTable.setLinesVisible(true); mUserTable.addMouseListener(new MouseAdapter() { @Override public void mouseUp(MouseEvent event) { on_UserTable_mouseUp(event); } }); GridDataBuilder.create(mUserTable).fill().grab().vSpan(5); TableViewerColumn tableViewerColumn = new TableViewerColumn(mUserTableViewer, SWT.NONE); TableColumn userColumnUrl = tableViewerColumn.getColumn(); userColumnUrl.setWidth(100); // Implementation detail: set the label provider on the table viewer *after* associating // a column. This will set the label provider on the column for us. mUserTableViewer.setLabelProvider(new LabelProvider()); mUserButtonNew = new Button(root, SWT.NONE); mUserButtonNew.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { userNewOrEdit(false /*isEdit*/); } }); GridDataBuilder.create(mUserButtonNew).hFill().vCenter(); mUserButtonNew.setText("New..."); mUserButtonEdit = new Button(root, SWT.NONE); mUserButtonEdit.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { userNewOrEdit(true /*isEdit*/); } }); GridDataBuilder.create(mUserButtonEdit).hFill().vCenter(); mUserButtonEdit.setText("Edit..."); mUserButtonDelete = new Button(root, SWT.NONE); mUserButtonDelete.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { on_UserButtonDelete_widgetSelected(e); } }); GridDataBuilder.create(mUserButtonDelete).hFill().vCenter(); mUserButtonDelete.setText("Delete..."); adjustColumnsWidth(mUserTable, userColumnUrl); }
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();/* w w w. ja va 2 s . c om*/ // 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}); }
From source file:com.apicloud.navigator.dialogs.CreateParamDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { setMessage(Messages.CreateParamDialog_INPUT_PARAM_NAME); Composite com = new Composite(parent, SWT.NONE); com.setLayout(new GridLayout(2, false)); com.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label featureLabel = new Label(com, SWT.NONE); featureLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); featureLabel.setText("feature"); //$NON-NLS-1$ this.list = new ComboViewer(com, SWT.NONE); this.list.setLabelProvider(new LabelProvider()); this.list.setContentProvider(new ArrayContentProvider()); this.list.setInput(config.getFeatures()); this.list.getCombo().select(0); Label paramNameLabel = new Label(com, SWT.NONE); paramNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); paramNameLabel.setText(Messages.CreateParamDialog_NAME); this.paramNameText = new Text(com, SWT.BORDER); this.paramNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Label paramValueLabel = new Label(com, SWT.NONE); paramValueLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); paramValueLabel.setText(Messages.CreateParamDialog_VALUE); this.paramValueText = new Text(com, SWT.BORDER); this.paramValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); return parent; }
From source file:com.aptana.editor.common.spelling.SpellingPreferencePage.java
License:Open Source License
@Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(GridLayoutFactory.swtDefaults().create()); composite.setLayoutData(GridDataFactory.fillDefaults().create()); globalPreferencesLink = new Link(composite, SWT.NONE); globalPreferencesLink.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).create()); Label label = new Label(composite, SWT.NONE); label.setText(StringUtil.makeFormLabel(Messages.SpellingPreferencePage_label)); label.setLayoutData(/*w w w .j av a 2 s. c om*/ GridDataFactory.swtDefaults().indent(SWT.DEFAULT, 5).align(SWT.FILL, SWT.CENTER).create()); tableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER); tableViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); tableViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ScopeDefinitions.DEFINITIONS.get(element); } }); tableViewer.setInput(ScopeDefinitions.DEFINITIONS.keySet()); tableViewer.setCheckedElements(SpellingPreferences.getEnabledScopes().toArray()); globalPreferencesLink.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ((IWorkbenchPreferenceContainer) getContainer()).openPage(GENERAL_SPELLING_PREF_ID, null); } }); applyDialogFont(composite); updateStatus(); return composite; }
From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java
License:Open Source License
/** * Returns the item list label provider. * // w w w .jav a 2s . c om * @return the item list label provider */ private ItemsListLabelProvider getItemsListLabelProvider() { if (itemsListLabelProvider == null) { itemsListLabelProvider = new ItemsListLabelProvider(new LabelProvider(), null); } return itemsListLabelProvider; }
From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java
License:Open Source License
private ILabelProvider getDetailsLabelProvider() { if (detailsLabelProvider == null) { detailsLabelProvider = new LabelProvider(); }//w w w . j a v a 2s .co m return detailsLabelProvider; }
From source file:com.aptana.editor.php.internal.ui.dialog.TypeSelectionDialog.java
License:Open Source License
/** * Constructs a new TypeSelectionDialog/*from ww w .j a va 2 s .co m*/ * * @param shell * @param multi */ public TypeSelectionDialog(Shell shell, boolean multi) { super(shell, multi); setDetailsLabelProvider(new LabelProvider() { public Image getImage(Object element) { if (element instanceof IElementNode) { return PHPOutlineLabelProvider.BLOCK_ICON; } return super.getImage(element); } public String getText(Object element) { if (element instanceof IElementNode) { IElementNode node = (IElementNode) element; return node.getPath(); } return super.getText(element); } }); setListLabelProvider(new TypeLabelProvider()); }
From source file:com.aptana.editor.php.internal.ui.preferences.BuildPathEditingComposite.java
License:Open Source License
private void createDirectoryPart(TabItem item) { TabFolder parent2 = item.getParent(); Composite projectPart = new Composite(parent2, SWT.NONE); projectPart.setLayout(new GridLayout(2, false)); directoryViewer = new TableViewer(projectPart, SWT.BORDER | SWT.MULTI); directoryViewer.setLabelProvider(new LabelProvider() { @Override/*from ww w.j a va2 s. c om*/ public Image getImage(Object element) { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); } @Override public String getText(Object element) { File fl = (File) element; return fl.getAbsolutePath(); } }); directoryViewer.setContentProvider(new ArrayContentProvider()); directoryViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); Composite buttonsComp = new Composite(projectPart, SWT.NONE); buttonsComp.setLayoutData(new GridData(GridData.FILL_VERTICAL)); buttonsComp.setLayout(new GridLayout(1, false)); Button add = new Button(buttonsComp, SWT.NONE); add.setText(Messages.BuildPathEditingComposite_AddDirectory); add.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.NONE); dialog.setText(Messages.BuildPathEditingComposite_AddDirectoryDescription); String open = dialog.open(); if (open != null) { addWithValidation(directoryViewer, new File(open)); } } }); add.setLayoutData(GridDataFactory.fillDefaults().hint(100, -1).create()); final Button remove = new Button(buttonsComp, SWT.NONE); remove.setText(Messages.BuildPathEditingComposite_RemoveDirectory); remove.setLayoutData(GridDataFactory.fillDefaults().hint(100, -1).create()); directoryViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { remove.setEnabled(!event.getSelection().isEmpty()); } }); remove.setEnabled(false); remove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IStructuredSelection sel = (IStructuredSelection) directoryViewer.getSelection(); Object[] selections = sel.toArray(); for (Object selected : selections) { directoryViewer.remove(selected); } } }); directoryViewer.setSorter(new ViewerSorter()); item.setControl(projectPart); }
From source file:com.aptana.editor.php.internal.ui.preferences.PHPLibraryDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite body = new Composite(parent, SWT.NONE); body.setLayout(new GridLayout(2, false)); body.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(body, SWT.NONE); label.setText(Messages.PHPLibraryDialog_libraryName); nameText = new Text(body, SWT.BORDER); nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); if (library != null) { nameText.setText(library.getName()); }/*w w w . ja v a 2 s.com*/ nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validate(); } }); Group pComp = new Group(body, SWT.NONE); pComp.setText(Messages.PHPLibraryDialog_libraryContent); pComp.setLayout(new GridLayout(2, false)); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; layoutData.minimumHeight = 200; pComp.setLayoutData(layoutData); viewer = new TableViewer(pComp, SWT.BORDER); viewer.setComparator(new ViewerComparator()); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { return element.toString(); } public Image getImage(Object element) { return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); } }); Composite buttons = new Composite(pComp, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; if (library != null) { viewer.setInput(library.getDirectories().toArray()); } else { viewer.setInput(new String[0]); // $codepro.audit.disable reusableImmutables } buttons.setLayout(layout); Button add = new Button(buttons, SWT.NONE); add.setText(Messages.PHPLibraryDialog_addFolder); add.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { DirectoryDialog directoryDialog = new DirectoryDialog(Display.getCurrent().getActiveShell()); directoryDialog.setText(Messages.PHPLibraryDialog_selectFolder); String open = directoryDialog.open(); viewer.add(open); } }); add.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button remove = new Button(buttons, SWT.NONE); remove.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); for (Object o : selection.toArray()) { viewer.remove(o); } } }); remove.setText(Messages.PHPLibraryDialog_removeSelected); remove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); Control createDialogArea = super.createDialogArea(parent); setMessage(Messages.PHPLibraryDialog_libraryConfigureMessage); setTitleImage(titleImage); setTitle(Messages.PHPLibraryDialog_libraryConfigureTitle); buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); return createDialogArea; }
From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java
License:Open Source License
protected void configurePreview(Composite composite, int numColumns) { createLabel(composite, FormatterMessages.AbstractFormatterSelectionBlock_preview, numColumns); Composite previewGroup = new Composite(composite, SWT.NONE); previewGroup.setLayout(new GridLayout(1, true)); GridData gd = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = numColumns;/* w w w.j a va 2s .c om*/ previewGroup.setLayoutData(gd); // Adds a SashForm to create left and right areas. The left will hold the list of formatters, while the right // will hold a preview pane SashForm sashForm = new SashForm(previewGroup, SWT.HORIZONTAL); sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); final ListViewer listViewer = new ListViewer(sashForm, SWT.SINGLE | SWT.BORDER); listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); // Add the right panel (code preview and buttons) Composite rightPanel = new Composite(sashForm, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; rightPanel.setLayout(layout); rightPanel.setLayoutData(new GridData(GridData.FILL_BOTH)); // Previews area final Composite previewPane = new Composite(rightPanel, SWT.BORDER); GridData previewGridData = new GridData(GridData.FILL_BOTH); previewGridData.heightHint = 300; previewGridData.widthHint = 450; previewPane.setLayoutData(previewGridData); previewStackLayout = new StackLayout(); previewPane.setLayout(previewStackLayout); // Set the data into the list listViewer.setContentProvider(ArrayContentProvider.getInstance()); listViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { IScriptFormatterFactory factory = (IScriptFormatterFactory) element; return factory.getName(); } }); listViewer.setInput(this.factories); if (selectedFormatter < 0) { selectedFormatter = 0; } listViewer.setSelection(new StructuredSelection(this.factories[selectedFormatter])); listViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // Update the preview selectedFormatter = listViewer.getList().getSelectionIndex(); if (selectedFormatter > -1 && selectedFormatter < sourcePreviewViewers.size()) { fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); updatePreview(); } } }); listViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (listViewer.getList().getSelectionIndex() > -1) { editButtonPressed(); } } }); for (IScriptFormatterFactory factory : this.factories) { SourceViewer sourcePreview = createSourcePreview(previewPane, factory); sourcePreviewViewers.add(sourcePreview); } if (selectedFormatter > -1 && sourcePreviewViewers.size() > selectedFormatter) { fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); } sashForm.setWeights(new int[] { 1, 3 }); // Attach the listeners profileChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IProfileManager.PROFILE_SELECTED.equals(event.getProperty())) { IProfile profile = (IProfile) event.getNewValue(); fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); updatePreview(); fDefaultButton.setEnabled(!profile.isBuiltInProfile()); } } }; profileManager.addPropertyChangeListener(profileChangeListener); }