public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("SWT and Swing DND Example"); GridLayout layout = new GridLayout(1, false); shell.setLayout(layout); Text swtText = new Text(shell, SWT.BORDER); swtText.setText("SWT Text"); GridData data = new GridData(GridData.FILL_HORIZONTAL); swtText.setLayoutData(data); setDragDrop(swtText); Composite comp = new Composite(shell, SWT.EMBEDDED); java.awt.Frame frame = SWT_AWT.new_Frame(comp); JTextField swingText = new JTextField(40); swingText.setText("Swing Text"); swingText.setDragEnabled(true); frame.add(swingText); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = swingText.getPreferredSize().height; comp.setLayoutData(data); shell.setSize(400, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
/** * Initialize the toolbar with icons and selection listeners in the appropriate part of the window */ public void initToolbar() { Device dev = shell.getDisplay(); try { exitImg = new Image(dev, "img/exit.png"); // openImg = new Image(dev, "img/open.png"); playImg = new Image(dev, "img/play.png"); // pauseImg = new Image(dev, "img/pause.png"); } catch (Exception e) { System.out.println("Cannot load images"); System.out.println(e.getMessage()); System.exit(1); } ToolBar toolBar = new ToolBar(shell, SWT.BORDER); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; toolBar.setLayoutData(gridData); ToolItem exit = new ToolItem(toolBar, SWT.PUSH); exit.setImage(exitImg); // ToolItem open = new ToolItem(toolBar, SWT.PUSH); // exit.setImage(openImg); ToolItem play = new ToolItem(toolBar, SWT.PUSH); play.setImage(playImg); // ToolItem pause = new ToolItem(toolBar, SWT.PUSH); // pause.setImage(pauseImg); toolBar.pack(); exit.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.exit(0); } }); // open.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e) { // FileDialog dialog = new FileDialog(shell, SWT.NULL); // String path = dialog.open(); // } // }); play.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { controller.RunAnimation(); } }); }
/** Creates the "Control" group. */ void createControlGroup() { /* * Create the "Control" group. This is the group on the * right half of each example tab. It consists of the * style group, the display group and the size group. */ controlGroup = new Group(tabFolderPage, SWT.NONE); GridLayout gridLayout = new GridLayout(); controlGroup.setLayout(gridLayout); gridLayout.numColumns = 2; gridLayout.makeColumnsEqualWidth = true; controlGroup.setLayoutData( new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); controlGroup.setText(ControlExample.getResourceString("Parameters")); /* * Create a group to hold the dialog style combo box and * create dialog button. */ dialogStyleGroup = new Group(controlGroup, SWT.NONE); dialogStyleGroup.setLayout(new GridLayout()); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); gridData.horizontalSpan = 2; dialogStyleGroup.setLayoutData(gridData); dialogStyleGroup.setText(ControlExample.getResourceString("Dialog_Type")); }
protected void createSpacer(Composite parent) { Label spacer = new Label(parent, SWT.NONE); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.BEGINNING; data.heightHint = 4; spacer.setLayoutData(data); }
/** Initialize the canvas in the appropriate part of the window */ public void initCanvas() { canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.BORDER); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; canvas.setLayoutData(gridData); }
private void createLabels(Composite pageContent) { Label label = new Label(pageContent, SWT.LEFT); label.setText(Messages._UI_LABEL_SOURCE_FILES); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; label.setLayoutData(data); label = new Label(pageContent, SWT.LEFT); label.setText(Messages._UI_LABEL_SELECTED_FILES); }
@Override protected void doFillIntoGrid(Composite parent, int numColumns) { Control control = getLabelControl(parent); GridData gd = new GridData(); control.setLayoutData(gd); gd = new GridData(GridData.FILL_HORIZONTAL); gd.verticalAlignment = GridData.FILL; gd.horizontalSpan = numColumns - 1; gd.grabExcessHorizontalSpace = true; spinner.setLayoutData(gd); spinner.layout(); }
private Text createTextInput( Composite parent, String labelKey, String configKey, String defaultValue, int widthHint) { // TODO: use this method to create all text inputs createLabel(parent, labelKey); final Text t = new Text(parent, SWT.BORDER); final GridData gd = new GridData(); if (widthHint > 0) gd.widthHint = widthHint; t.setLayoutData(gd); String val = controller.getConfig().getString(configKey); if ("".equals(val) && defaultValue != null) val = defaultValue; t.setText(String.valueOf(val)); return t; }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, true)); final Browser browser; try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; browser.setLayoutData(data); Button headersButton = new Button(shell, SWT.PUSH); headersButton.setText("Send custom headers"); data = new GridData(); data.horizontalAlignment = GridData.FILL; headersButton.setLayoutData(data); headersButton.addListener( SWT.Selection, event -> browser.setUrl( "http://www.ericgiguere.com/tools/http-header-viewer.html", null, new String[] {"User-agent: SWT Browser", "Custom-header: this is just a demo"})); Button postDataButton = new Button(shell, SWT.PUSH); postDataButton.setText("Send post data"); data = new GridData(); data.horizontalAlignment = GridData.FILL; postDataButton.setLayoutData(data); postDataButton.addListener( SWT.Selection, event -> browser.setUrl( "https://bugs.eclipse.org/bugs/buglist.cgi", "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring", null)); shell.setBounds(10, 10, 600, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
void createRTFTransfer(Composite copyParent, Composite pasteParent) { // RTF Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("RTFTransfer:"); // $NON-NLS-1$ copyRtfText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); copyRtfText.setText("some\nrtf\ntext"); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; copyRtfText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = copyRtfText.getText(); if (data.length() > 0) { status.setText(""); data = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i " + data + "}"; clipboard.setContents( new Object[] {data}, new Transfer[] {RTFTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("RTFTransfer:"); // $NON-NLS-1$ pasteRtfText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteRtfText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = (String) clipboard.getContents(RTFTransfer.getInstance()); if (data != null && data.length() > 0) { status.setText(""); pasteRtfText.setText("start paste>" + data + "<end paste"); } else { status.setText("nothing to paste"); } } }); }
void createHTMLTransfer(Composite copyParent, Composite pasteParent) { // HTML Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("HTMLTransfer:"); // $NON-NLS-1$ copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); copyHtmlText.setText("<b>Hello World</b>"); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; copyHtmlText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = copyHtmlText.getText(); if (data.length() > 0) { status.setText(""); clipboard.setContents( new Object[] {data}, new Transfer[] {HTMLTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("HTMLTransfer:"); // $NON-NLS-1$ pasteHtmlText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteHtmlText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String data = (String) clipboard.getContents(HTMLTransfer.getInstance()); if (data != null && data.length() > 0) { status.setText(""); pasteHtmlText.setText("start paste>" + data + "<end paste"); } else { status.setText("nothing to paste"); } } }); }
void createAvailableTypes(Composite parent) { final List list = new List(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = 100; list.setLayoutData(data); Button b = new Button(parent, SWT.PUSH); b.setText("Get Available Types"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { list.removeAll(); String[] names = clipboard.getAvailableTypeNames(); for (int i = 0; i < names.length; i++) { list.add(names[i]); } } }); }
private void createSelectedListBox(Composite parent) { selectedListBox = new List(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); selectedListBox.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) {} public void widgetSelected(SelectionEvent event) { if (selectedListBox.getSelectionCount() > 0) setRemoveButtonEnabled(true); else setRemoveButtonEnabled(false); return; } }); GridData gd = new GridData(GridData.FILL_BOTH); gd.widthHint = SIZING_LISTS_WIDTH; gd.heightHint = SIZING_LISTS_HEIGHT; selectedListBox.setLayoutData(gd); }
private void createContent() { GridData termGD = new GridData(GridData.FILL_BOTH); termGD.heightHint = 400; termGD.widthHint = 400; termGD.horizontalSpan = 3; terminal = new Text(mainPane, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY); terminal.setLayoutData(termGD); pause = new Button(mainPane, SWT.TOGGLE); pause.setText("Pause"); pause.setToolTipText("Pause Terminal"); clear = new Button(mainPane, SWT.PUSH); clear.setText("Clear"); clear.setToolTipText("Clear the Terminal"); close = new Button(mainPane, SWT.PUSH); close.setText("Close"); }
void createImportButton(Composite parent) { importButton = new Button(parent, SWT.PUSH); importButton.setText(Messages._UI_IMPORT_BUTTON); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.CENTER; importButton.setLayoutData(gridData); importButton.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { FileSystemImportWizard importWizard = new FileSystemImportWizard(); importWizard.init(workbench, selection); Shell shell = Display.getCurrent().getActiveShell(); WizardDialog wizardDialog = new WizardDialog(shell, importWizard); wizardDialog.create(); wizardDialog.open(); sourceFileViewer.refresh(); } }); importButton.setToolTipText(Messages._UI_IMPORT_BUTTON_TOOL_TIP); }
private void createSourceViewer(Composite parent) { sourceFileViewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER)); sourceFileViewer.setContentProvider(new WorkbenchContentProvider()); sourceFileViewer.setLabelProvider(new WorkbenchLabelProvider()); sourceFileViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { java.util.List list; ISelection selection = event.getSelection(); boolean newFilesSelected = false; if (selection instanceof IStructuredSelection) { list = ((IStructuredSelection) selection).toList(); for (Iterator i = list.iterator(); i.hasNext(); ) { IResource resource = (IResource) i.next(); if (resource instanceof IFile) { if (checkIfFileInTarget((IFile) resource) == false) newFilesSelected = true; } } setAddButtonEnabled(newFilesSelected); } } }); sourceFileViewer.addDoubleClickListener( new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { addSelectedFilesToTargetList(); } }); Control treeWidget = sourceFileViewer.getTree(); GridData gd = new GridData(GridData.FILL_BOTH); gd.widthHint = SIZING_LISTS_WIDTH; gd.heightHint = SIZING_LISTS_HEIGHT; treeWidget.setLayoutData(gd); }
private void createComp(Composite group) { GridLayout layout = new GridLayout(1, false); layout.verticalSpacing = 10; group.setLayout(layout); // TableViewer是通过Table来布局的 // 制作表格 MULTI可多选 H_SCROLL有水平 滚动条、V_SCROLL有垂直滚动条、BORDER有边框、FULL_SELECTION整行选择 table = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); // 注意此处的设置 TableLayout tableLayout = new TableLayout(); table.setLayout(tableLayout); // 指定Table单元格的宽度和高度 table.addListener( SWT.MeasureItem, new Listener() { // 向表格增加一个SWT.MeasureItem监听器,每当需要单元内容的大小的时候就会被调用。 public void handleEvent(Event event) { event.width = table.getGridLineWidth(); // 设置宽度 event.height = (int) Math.floor(event.gc.getFontMetrics().getHeight() * 1.5); // 设置高度为字体高度的1.5倍 } }); // 表格的视图 tableViewer = new TableViewer(table); // 标题和网格线可见 tableViewer.getTable().setLinesVisible(true); tableViewer.getTable().setHeaderVisible(true); // 设置填充 // GridData data = new GridData(SWT.LEFT,SWT.CENTER, true, false);//SWT.FILL, SWT.FILL, true, // false xbm GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = 350; data.heightHint = 295; data.grabExcessHorizontalSpace = true; tableViewer.getTable().setLayoutData(data); // 表格的布局 // 创建表格列的标题 int width = 1; for (int i = 0; i < stationData.getColumnCount(); i++) { width = stationData.getColumnWidth(i); TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth((int) (width * 8)); column.setText(stationData.getColumnHeads()[i]); // 设置表头 column.setAlignment(SWT.LEFT); // 对齐方式SWT.LEFT if (i == 0) // 站名 { // 列的选择事件 实现排序 column.addSelectionListener( new SelectionAdapter() { boolean sortType = true; // sortType记录上一次的排序方式,默认为升序 public void widgetSelected(SelectionEvent e) { sortType = !sortType; // 取反。下一次排序方式要和这一次的相反 tableViewer.setSorter(new StationSorter(sortType, stationData.columnHeads[0])); } }); } } /*tableLayout.addColumnData(new ColumnWeightData(8, 8, false));//设置列宽为8像素 TableColumn column_one = new TableColumn(table, SWT.NONE);//SWT.LEFT column_one.setText(stationData.COLUMN_HEADINGS[0]);//设置表头 column_one.setAlignment(SWT.LEFT);//对齐方式SWT.LEFT column.setWidth(10);//宽度 */ // 设置标题的提供者 tableViewer.setLabelProvider(new TableLabelProvider()); // 设置表格视图的内容提供者 tableViewer.setContentProvider(new TableContentProvider()); // 设置列的属性. tableViewer.setColumnProperties(stationData.columnHeads); // 定义每一列的别名 tableViewer.setColumnProperties(new String[] {"name", "down", "up", "map"}); // 设置每一列的单元格编辑组件CellEditor CellEditor[] celleditors = new CellEditor[5]; // 文本编辑框 celleditors[0] = null; celleditors[1] = new TextCellEditor(table); celleditors[2] = new TextCellEditor(table); // CheckboxCellEditor(table) 复选框 celleditors[3] = new ComboBoxCellEditor(table, StationData.MAPS, SWT.READ_ONLY); // 下拉框 Text text = (Text) celleditors[1].getControl(); // 设置第down列只能输入数值 text.addVerifyListener( new VerifyListener() { public void verifyText(VerifyEvent e) { // 输入控制键,输入中文,输入字符,输入数字 正整数验证 Pattern pattern = Pattern.compile("[0-9]\\d*"); // 正则表达式 Matcher matcher = pattern.matcher(e.text); if (matcher.matches()) // 处理数字 { /*if(Integer.parseInt(e.text) != 0)//确保输入的数字不是0 e.doit = true; else e.doit = false; */ e.doit = true; } else if (e.text.length() > 0) // 字符: 包含中文、空格 e.doit = false; else // 控制键 e.doit = true; } }); Text text1 = (Text) celleditors[2].getControl(); // 设置第up列只能输入数值 text1.addVerifyListener( new VerifyListener() { public void verifyText(VerifyEvent e) { String inStr = e.text; if (inStr.length() > 0) { e.doit = NumberUtils.isDigits(inStr); } } }); table.addMouseMoveListener( new MouseMoveListener() { public void mouseMove(MouseEvent e) { if (StationData.reloadFlag) { getStationInfo(); openCurrentTable(row); StationData.reloadFlag = false; // System.out.println("entry"); } } }); /*table.addFocusListener(new FocusListener(){ public void focusGained(FocusEvent e) { getStationInfo(); openCurrentTable(row); } @Override public void focusLost(FocusEvent e) { } }); */ tableViewer.setCellEditors(celleditors); // 设置单元的更改器 tableViewer.setCellModifier(new TableCellModifier()); tableViewer.addFilter(new TableViewerFilter()); // 过滤器 // 构造工具条 Composite buttonComposite = new Composite(group, SWT.NONE); buttonComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); // 使工具条居中 Action actionModify = new Action("更新") { public void run() { // 取得用户所选择的第一行, 若没有选择则为null IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); // 获取选中的第一行数据 Station station = (Station) selection.getFirstElement(); if (station != null) { if (updateStationInfo( station.getStation_downnumber(), station.getStation_upnumber(), station.getStation_graph(), station.getStation_name())) { showMsg("成功更新!"); // 表格的刷新方法,界面会重新读取数据并显示 pushCommand(); tableViewer.refresh(); // false } else { showMsg("更新失败!"); // tableViewer.refresh();//false } } else { showMsg("请选取进行更新的行!"); } } }; Action actionDelete = new Action("删除") { public void run() { // 取得用户所选择的第一行, 若没有选择则为null IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); // 获取选中的第一个数据 Station station = (Station) selection.getFirstElement(); if (station != null) { // 先预先移动到下一行 Table table = tableViewer.getTable(); // int i = table.getSelectionIndex(); //取得当前所选行的序号,如没有则返回-1 // table.setSelection(i + 1); //当前选择行移下一行 // 确认删除 MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_INFORMATION); messageBox.setText("提示信息"); messageBox.setMessage("确定要删除此记录吗?"); // SWT.YES 是 // SWT.NO 否 // SWT.CANCEL 取消 // SWT.RETRY 重试// SWT.ABORT 放弃// SWT.IGNORE // 忽略 if (messageBox.open() == SWT.YES) { if (deleteStationInfo(station.getStation_name())) // 从数据库中删除记录 { // showMsg("成功删除!"); ((List) tableViewer.getInput()).remove(station); // 数据模型的List容器中删除 stationData.remove(station.getStation_name()); openCurrentTable(row); tableViewer.remove(station); // 从表格界面上删除 pushCommand(); } else showMsg("删除失败!"); } } else { showMsg("请选取要删除的纪录!"); } } }; Action actionClear = new Action("清空") { // 清除所显示内容,点击保存后更新库 public void run() { if (clearStationInfo()) { showMsg("清空操作成功!"); stationData.removeAll(); openCurrentTable(row); pushCommand(); } else showMsg("清空操作失败!"); } }; Action actionHelp = new Action("帮助") { public void run() { String str = "更新:\n\r" + "先对某行内容进行修改,然后点击更新进行保存\n\r" + "清空:\n\r" + "从库中物理删除所有记录"; showMsg(str); } }; Action nextPage = new Action("下一页") { public void run() { row++; if (row > stationData.getTotalPageNum()) { row--; return; } openCurrentTable(row); } }; Action prevPage = new Action("上一页") { public void run() { row--; if (row < 1) { row++; return; } openCurrentTable(row); } }; Action refresh = new Action("刷新") { public void run() { getStationInfo(); openCurrentTable(row); } }; // 工具条 ToolBar toolBar = new ToolBar(buttonComposite, SWT.FLAT | SWT.RIGHT); // |SWT.BORDER // 工具条管理器 ToolBarManager manager = new ToolBarManager(toolBar); // manager.add(refresh); // manager.add(new Separator()); manager.add(nextPage); manager.add(prevPage); manager.add(new Separator()); manager.add(actionModify); manager.add(actionDelete); manager.add(actionClear); manager.add(new Separator()); manager.add(actionHelp); manager.update(true); // 选中某行时,改变行的颜色 table.addListener( SWT.EraseItem, new Listener() { public void handleEvent(Event event) { event.detail &= ~SWT.HOT; if ((event.detail & SWT.SELECTED) == 0) return; int clientWidth = table.getClientArea().width; GC gc = event.gc; Color oldForeground = gc.getForeground(); Color oldBackground = gc.getBackground(); gc.setForeground(red); // gc.setBackground(yellow); gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false); gc.setForeground(oldForeground); gc.setBackground(oldBackground); event.detail &= ~SWT.SELECTED; } }); // 在tableviewer内部为数据记录和tableItem之间的映射创建一个hash表,这样可以加快tableItem的和记录间的查找速度 // 必须保证存在要显示的数据,否则程序出错。所以这里不能用下面的语句 // tableViewer.setUseHashlookup(true);//必须在setInput之前加入才有效 // 从服务器获取数据 getStationInfo(); // 通过setInput为table添加了一个list后,只要对这个list里的元素进行添加和删除, // table中的数据就会自动添加和删除,当然每次操作后需要调用refresh方法对tableviewer进行刷新。 // 打开界面所显示的内容 tableViewer.setInput(stationData.getData()); // 自动输入数据 即将数据显示在表格中 tableViewer.setItemCount(stationData.PAGE_SIZE); // 设置显示的Item数 } //// createComp
private void createButtonPanel(Composite pageContent) { Composite buttonPanel = new Composite(pageContent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; buttonPanel.setLayout(layout); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = false; gridData.grabExcessVerticalSpace = true; gridData.verticalAlignment = GridData.CENTER; gridData.horizontalAlignment = GridData.CENTER; buttonPanel.setLayoutData(gridData); addButton = new Button(buttonPanel, SWT.PUSH); addButton.setText(Messages._UI_ADD_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; addButton.setLayoutData(gridData); addButton.addSelectionListener(new ButtonSelectListener()); addButton.setToolTipText(Messages._UI_ADD_BUTTON_TOOL_TIP); addButton.setEnabled(false); removeButton = new Button(buttonPanel, SWT.PUSH); removeButton.setText(Messages._UI_REMOVE_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; removeButton.setLayoutData(gridData); removeButton.addSelectionListener(new ButtonSelectListener()); removeButton.setToolTipText(Messages._UI_REMOVE_BUTTON_TOOL_TIP); removeButton.setEnabled(false); removeAllButton = new Button(buttonPanel, SWT.PUSH); removeAllButton.setText(Messages._UI_REMOVE_ALL_BUTTON); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.CENTER; removeAllButton.setLayoutData(gridData); removeAllButton.addSelectionListener(new ButtonSelectListener()); removeAllButton.setToolTipText(Messages._UI_REMOVE_ALL_BUTTON_TOOL_TIP); removeAllButton.setEnabled(false); }
private static GridData getButtonGridData(Button button) { GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = SWTUtil.getButtonWidthHint(button); // data.heightHint= SWTUtil.getButtonHeigthHint(button); return data; }
void createFileTransfer(Composite copyParent, Composite pasteParent) { // File Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("FileTransfer:"); // $NON-NLS-1$ Composite c = new Composite(copyParent, SWT.NONE); c.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.FILL_HORIZONTAL); c.setLayoutData(data); copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; data.horizontalSpan = 2; copyFileTable.setLayoutData(data); Button b = new Button(c, SWT.PUSH); b.setText("Select file(s)"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); String separator = System.getProperty("file.separator"); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (int i = 0; i < names.length; i++) { TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(path + separator + names[i]); } } } }); b = new Button(c, SWT.PUSH); b.setText("Select directory"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(result); } } }); b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = copyFileTable.getItems(); if (items.length > 0) { status.setText(""); String[] data = new String[items.length]; for (int i = 0; i < data.length; i++) { data[i] = items[i].getText(); } clipboard.setContents( new Object[] {data}, new Transfer[] {FileTransfer.getInstance()}); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("FileTransfer:"); // $NON-NLS-1$ pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteFileTable.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (data != null && data.length > 0) { status.setText(""); pasteFileTable.removeAll(); for (int i = 0; i < data.length; i++) { TableItem item = new TableItem(pasteFileTable, SWT.NONE); item.setText(data[i]); } } else { status.setText("nothing to paste"); } } }); }
/** @param composite */ private void createInstallationDirectoryGroup(Composite parent) { Group instDirGroup = NSISWizardDialogUtil.createGroup( parent, 2, "installation.directory.group.label", null, false); // $NON-NLS-1$ NSISWizardSettings settings = mWizard.getSettings(); ((GridData) NSISWizardDialogUtil.createLabel( instDirGroup, "installation.directory.label", true, null, isScriptWizard()) .getLayoutData()) .horizontalSpan = 1; //$NON-NLS-1$ final Composite instDirComposite = new Composite(instDirGroup, SWT.NONE); instDirComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final StackLayout instDirLayout = new StackLayout(); instDirComposite.setLayout(instDirLayout); final Combo instDirCombo = NSISWizardDialogUtil.createCombo( instDirComposite, 1, NSISWizardUtil.getPathConstantsAndVariables(settings.getTargetPlatform()), settings.getInstallDir(), false, true, null); final Text instDirText = NSISWizardDialogUtil.createText(instDirComposite, settings.getInstallDir(), 1, true, null); instDirLayout.topControl = instDirCombo; Runnable r = new Runnable() { private String mInstDirParent = ""; // $NON-NLS-1$ private void updateInstDir(NSISWizardSettings settings) { Control topControl; if (isMultiUser()) { if (settings.getInstallDir().startsWith(mInstDirParent)) { String instDir = settings.getInstallDir().substring(mInstDirParent.length()); settings.setInstallDir(instDir); instDirText.setText(instDir); } topControl = instDirText; } else { if (!settings.getInstallDir().startsWith(mInstDirParent)) { String instDir = mInstDirParent + settings.getInstallDir(); settings.setInstallDir(instDir); instDirCombo.setText(instDir); } topControl = instDirCombo; } if (instDirLayout.topControl != topControl) { instDirLayout.topControl = topControl; instDirComposite.layout(true); } validateField(INSTDIR_CHECK); } public void run() { final PropertyChangeListener propertyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (NSISWizardSettings.INSTALLER_TYPE.equals(evt.getPropertyName()) || NSISWizardSettings.MULTIUSER_INSTALLATION.equals( evt.getPropertyName())) { updateInstDir(mWizard.getSettings()); } else if (NSISWizardSettings.INSTALL_DIR.equals(evt.getPropertyName())) { if (!isMultiUser()) { setInstDirParent(mWizard.getSettings()); } } } }; final INSISWizardSettingsListener settingsListener = new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, final NSISWizardSettings newSettings) { if (oldSettings != null) { oldSettings.removePropertyChangeListener(propertyListener); } setInstDirParent(newSettings); if (newSettings != null) { newSettings.addPropertyChangeListener(propertyListener); } updateInstDir(newSettings); } }; mWizard.addSettingsListener(settingsListener); mWizard.getSettings().addPropertyChangeListener(propertyListener); instDirCombo.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { mWizard.getSettings().removePropertyChangeListener(propertyListener); mWizard.removeSettingsListener(settingsListener); } }); setInstDirParent(mWizard.getSettings()); updateInstDir(mWizard.getSettings()); } private void setInstDirParent(NSISWizardSettings settings) { mInstDirParent = ""; // $NON-NLS-1$ if (settings != null) { String instDir = settings.getInstallDir(); if (!Common.isEmpty(instDir)) { int n = instDir.lastIndexOf('\\'); if (n > 0 && n < instDir.length() - 1) { mInstDirParent = instDir.substring(0, n + 1); } } } } }; r.run(); GridData gd = (GridData) instDirCombo.getLayoutData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; instDirCombo.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String text = ((Combo) e.widget).getText(); mWizard.getSettings().setInstallDir(text); validateField(INSTDIR_CHECK); } }); instDirText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String text = ((Text) e.widget).getText(); mWizard.getSettings().setInstallDir(text); validateField(INSTDIR_CHECK); } }); final Button changeInstDir = NSISWizardDialogUtil.createCheckBox( instDirGroup, "change.installation.directory.label", //$NON-NLS-1$ settings.isChangeInstallDir(), (settings.getInstallerType() != INSTALLER_TYPE_SILENT), null, false); changeInstDir.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setChangeInstallDir(((Button) e.widget).getSelection()); } }); addPageChangedRunnable( new Runnable() { public void run() { if (isCurrentPage()) { NSISWizardSettings settings = mWizard.getSettings(); instDirCombo.setText(settings.getInstallDir()); changeInstDir.setEnabled(settings.getInstallerType() != INSTALLER_TYPE_SILENT); } } }); final PropertyChangeListener propertyListener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (NSISWizardSettings.TARGET_PLATFORM.equals(evt.getPropertyName())) { NSISWizardDialogUtil.populateCombo( instDirCombo, NSISWizardUtil.getPathConstantsAndVariables( ((Integer) evt.getNewValue()).intValue()), ((NSISWizardSettings) evt.getSource()).getInstallDir()); } } }; settings.addPropertyChangeListener(propertyListener); final INSISWizardSettingsListener listener = new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, NSISWizardSettings newSettings) { if (oldSettings != null) { oldSettings.removePropertyChangeListener(propertyListener); } instDirCombo.setText(newSettings.getInstallDir()); changeInstDir.setSelection(newSettings.isChangeInstallDir()); changeInstDir.setEnabled(newSettings.getInstallerType() != INSTALLER_TYPE_SILENT); newSettings.addPropertyChangeListener(propertyListener); } }; mWizard.addSettingsListener(listener); instDirGroup.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { mWizard.removeSettingsListener(listener); mWizard.getSettings().removePropertyChangeListener(propertyListener); } }); }
private void createLanguagesGroup(Composite parent) { final Group langGroup = NSISWizardDialogUtil.createGroup( parent, 1, "language.support.group.label", null, false); // $NON-NLS-1$ GridData data = (GridData) langGroup.getLayoutData(); data.verticalAlignment = SWT.FILL; data.grabExcessVerticalSpace = true; data.horizontalAlignment = SWT.FILL; data.grabExcessHorizontalSpace = true; NSISWizardSettings settings = mWizard.getSettings(); final Button enableLangSupport = NSISWizardDialogUtil.createCheckBox( langGroup, "enable.language.support.label", settings.isEnableLanguageSupport(), true, null, false); //$NON-NLS-1$ enableLangSupport.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean selection = enableLangSupport.getSelection(); mWizard.getSettings().setEnableLanguageSupport(selection); validateField(LANG_CHECK); } }); final MasterSlaveController m = new MasterSlaveController(enableLangSupport); final Composite listsComposite = new Composite(langGroup, SWT.NONE); data = new GridData(SWT.FILL, SWT.FILL, true, true); listsComposite.setLayoutData(data); GridLayout layout = new GridLayout(2, true); layout.marginHeight = 0; layout.marginWidth = 0; listsComposite.setLayout(layout); java.util.List<NSISLanguage> selectedLanguages = settings.getLanguages(); if (selectedLanguages.isEmpty()) { NSISLanguage defaultLanguage = NSISLanguageManager.getInstance().getDefaultLanguage(); if (defaultLanguage != null) { selectedLanguages.add(defaultLanguage); } } java.util.List<NSISLanguage> availableLanguages = NSISLanguageManager.getInstance().getLanguages(); availableLanguages.removeAll(selectedLanguages); Composite leftComposite = new Composite(listsComposite, SWT.NONE); leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; leftComposite.setLayout(layout); ((GridData) NSISWizardDialogUtil.createLabel( leftComposite, "available.languages.label", //$NON-NLS-1$ true, m, false) .getLayoutData()) .horizontalSpan = 2; final List availableLangList = new List(leftComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); data = new GridData(SWT.FILL, SWT.FILL, true, true); Dialog.applyDialogFont(availableLangList); data.heightHint = Common.calculateControlSize(availableLangList, 0, 12).y; availableLangList.setLayoutData(data); m.addSlave(availableLangList); final ListViewer availableLangViewer = new ListViewer(availableLangList); CollectionContentProvider collectionContentProvider = new CollectionContentProvider(); availableLangViewer.setContentProvider(collectionContentProvider); availableLangViewer.setInput(availableLanguages); availableLangViewer.setSorter(new ViewerSorter(cLanguageCollator)); final Composite buttonsComposite1 = new Composite(leftComposite, SWT.NONE); layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; buttonsComposite1.setLayout(layout); data = new GridData(SWT.FILL, SWT.CENTER, false, false); buttonsComposite1.setLayoutData(data); final Button allRightButton = new Button(buttonsComposite1, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); allRightButton.setLayoutData(data); allRightButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("all.right.icon"))); // $NON-NLS-1$ allRightButton.setToolTipText( EclipseNSISPlugin.getResourceString("all.right.tooltip")); // $NON-NLS-1$ final Button rightButton = new Button(buttonsComposite1, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); rightButton.setLayoutData(data); rightButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("right.icon"))); // $NON-NLS-1$ rightButton.setToolTipText(EclipseNSISPlugin.getResourceString("right.tooltip")); // $NON-NLS-1$ final Button leftButton = new Button(buttonsComposite1, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); leftButton.setLayoutData(data); leftButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("left.icon"))); // $NON-NLS-1$ leftButton.setToolTipText(EclipseNSISPlugin.getResourceString("left.tooltip")); // $NON-NLS-1$ final Button allLeftButton = new Button(buttonsComposite1, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); allLeftButton.setLayoutData(data); allLeftButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("all.left.icon"))); // $NON-NLS-1$ allLeftButton.setToolTipText( EclipseNSISPlugin.getResourceString("all.left.tooltip")); // $NON-NLS-1$ Composite rightComposite = new Composite(listsComposite, SWT.NONE); rightComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; rightComposite.setLayout(layout); ((GridData) NSISWizardDialogUtil.createLabel( rightComposite, "selected.languages.label", //$NON-NLS-1$ true, m, isScriptWizard()) .getLayoutData()) .horizontalSpan = 2; final List selectedLangList = new List(rightComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); data = new GridData(SWT.FILL, SWT.FILL, true, true); Dialog.applyDialogFont(selectedLangList); data.heightHint = Common.calculateControlSize(selectedLangList, 0, 12).y; selectedLangList.setLayoutData(data); m.addSlave(selectedLangList); final ListViewer selectedLangViewer = new ListViewer(selectedLangList); selectedLangViewer.setContentProvider(collectionContentProvider); selectedLangViewer.setInput(selectedLanguages); final ListViewerUpDownMover<java.util.List<NSISLanguage>, NSISLanguage> mover = new ListViewerUpDownMover<java.util.List<NSISLanguage>, NSISLanguage>() { @Override @SuppressWarnings("unchecked") protected java.util.List<NSISLanguage> getAllElements() { return (java.util.List<NSISLanguage>) ((ListViewer) getViewer()).getInput(); } @Override protected void updateStructuredViewerInput( java.util.List<NSISLanguage> input, java.util.List<NSISLanguage> elements, java.util.List<NSISLanguage> move, boolean isDown) { (input).clear(); (input).addAll(elements); } }; mover.setViewer(selectedLangViewer); final Composite buttonsComposite2 = new Composite(rightComposite, SWT.NONE); layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; buttonsComposite2.setLayout(layout); data = new GridData(SWT.FILL, SWT.CENTER, false, false); buttonsComposite2.setLayoutData(data); final Button upButton = new Button(buttonsComposite2, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); upButton.setLayoutData(data); upButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("up.icon"))); // $NON-NLS-1$ upButton.setToolTipText(EclipseNSISPlugin.getResourceString("up.tooltip")); // $NON-NLS-1$ m.addSlave(upButton); final Button downButton = new Button(buttonsComposite2, SWT.PUSH); data = new GridData(SWT.FILL, SWT.CENTER, true, false); downButton.setLayoutData(data); downButton.setImage( EclipseNSISPlugin.getImageManager() .getImage(EclipseNSISPlugin.getResourceString("down.icon"))); // $NON-NLS-1$ downButton.setToolTipText(EclipseNSISPlugin.getResourceString("down.tooltip")); // $NON-NLS-1$ m.addSlave(downButton); Composite langOptions = langGroup; boolean showSupportedLangOption = NSISPreferences.getInstance().getNSISVersion().compareTo(INSISVersions.VERSION_2_26) >= 0; if (showSupportedLangOption) { langOptions = new Composite(langGroup, SWT.None); layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; langOptions.setLayout(layout); data = new GridData(SWT.FILL, SWT.FILL, true, false); langOptions.setLayoutData(data); } final Button selectLang = NSISWizardDialogUtil.createCheckBox( langOptions, "select.language.label", settings.isSelectLanguage(), true, m, false); //$NON-NLS-1$ final Button displaySupported; if (showSupportedLangOption) { ((GridData) selectLang.getLayoutData()).horizontalSpan = 1; displaySupported = NSISWizardDialogUtil.createCheckBox( langOptions, "display.supported.languages.label", settings.isDisplaySupportedLanguages(), // $NON-NLS-1$ true, m, false); ((GridData) displaySupported.getLayoutData()).horizontalSpan = 1; displaySupported.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setDisplaySupportedLanguages(displaySupported.getSelection()); } }); } else { displaySupported = null; } final MasterSlaveEnabler mse = new MasterSlaveEnabler() { public void enabled(Control control, boolean flag) {} @SuppressWarnings("unchecked") public boolean canEnable(Control control) { NSISWizardSettings settings = mWizard.getSettings(); if (control == allRightButton) { return settings.isEnableLanguageSupport() && availableLangViewer.getList().getItemCount() > 0; } else if (control == rightButton) { return settings.isEnableLanguageSupport() && !availableLangViewer.getSelection().isEmpty(); } else if (control == allLeftButton) { return settings.isEnableLanguageSupport() && selectedLangViewer.getList().getItemCount() > 0; } else if (control == leftButton) { return settings.isEnableLanguageSupport() && !selectedLangViewer.getSelection().isEmpty(); } else if (control == upButton) { return settings.isEnableLanguageSupport() && mover.canMoveUp(); } else if (control == downButton) { return settings.isEnableLanguageSupport() && mover.canMoveDown(); } else if (control == selectLang) { java.util.List<NSISLanguage> selectedLanguages = (java.util.List<NSISLanguage>) selectedLangViewer.getInput(); return settings.getInstallerType() != INSTALLER_TYPE_SILENT && settings.isEnableLanguageSupport() && selectedLanguages.size() > 1; } else if (control == displaySupported && displaySupported != null) { java.util.List<NSISLanguage> selectedLanguages = (java.util.List<NSISLanguage>) selectedLangViewer.getInput(); return settings.getInstallerType() != INSTALLER_TYPE_SILENT && settings.isEnableLanguageSupport() && selectedLanguages.size() > 1 && selectLang.getSelection(); } else { return true; } } }; m.addSlave(rightButton, mse); m.addSlave(allRightButton, mse); m.addSlave(leftButton, mse); m.addSlave(allLeftButton, mse); m.setEnabler(upButton, mse); m.setEnabler(downButton, mse); m.setEnabler(selectLang, mse); if (displaySupported != null) { m.setEnabler(displaySupported, mse); } selectLang.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setSelectLanguage(selectLang.getSelection()); if (displaySupported != null) { displaySupported.setEnabled(mse.canEnable(displaySupported)); } } }); final Runnable langRunnable = new Runnable() { public void run() { availableLangViewer.refresh(false); selectedLangViewer.refresh(false); allRightButton.setEnabled(mse.canEnable(allRightButton)); allLeftButton.setEnabled(mse.canEnable(allLeftButton)); rightButton.setEnabled(mse.canEnable(rightButton)); leftButton.setEnabled(mse.canEnable(leftButton)); upButton.setEnabled(mse.canEnable(upButton)); downButton.setEnabled(mse.canEnable(downButton)); selectLang.setEnabled(mse.canEnable(selectLang)); if (displaySupported != null) { displaySupported.setEnabled(mse.canEnable(displaySupported)); } setPageComplete(validateField(LANG_CHECK)); } }; rightButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent se) { moveAcross( availableLangViewer, selectedLangViewer, Common.makeGenericList( NSISLanguage.class, ((IStructuredSelection) availableLangViewer.getSelection()).toList())); langRunnable.run(); } }); allRightButton.addSelectionListener( new SelectionAdapter() { @Override @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent se) { moveAcross( availableLangViewer, selectedLangViewer, (java.util.List<NSISLanguage>) availableLangViewer.getInput()); langRunnable.run(); } }); leftButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent se) { moveAcross( selectedLangViewer, availableLangViewer, Common.makeGenericList( NSISLanguage.class, ((IStructuredSelection) selectedLangViewer.getSelection()).toList())); langRunnable.run(); } }); allLeftButton.addSelectionListener( new SelectionAdapter() { @Override @SuppressWarnings("unchecked") public void widgetSelected(SelectionEvent se) { moveAcross( selectedLangViewer, availableLangViewer, (java.util.List<NSISLanguage>) selectedLangViewer.getInput()); langRunnable.run(); } }); upButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent se) { mover.moveUp(); langRunnable.run(); } }); downButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent se) { mover.moveDown(); langRunnable.run(); } }); availableLangViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { rightButton.setEnabled(mse.canEnable(rightButton)); allRightButton.setEnabled(mse.canEnable(allRightButton)); } }); availableLangViewer .getList() .addSelectionListener( new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent event) { IStructuredSelection sel = (IStructuredSelection) availableLangViewer.getSelection(); if (!sel.isEmpty()) { moveAcross( availableLangViewer, selectedLangViewer, Common.makeGenericList(NSISLanguage.class, sel.toList())); selectedLangViewer.reveal(sel.getFirstElement()); langRunnable.run(); } } }); selectedLangViewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { leftButton.setEnabled(mse.canEnable(leftButton)); allLeftButton.setEnabled(mse.canEnable(allLeftButton)); upButton.setEnabled(mse.canEnable(upButton)); downButton.setEnabled(mse.canEnable(downButton)); selectLang.setEnabled(mse.canEnable(selectLang)); if (displaySupported != null) { displaySupported.setEnabled(mse.canEnable(displaySupported)); } } }); selectedLangViewer .getList() .addSelectionListener( new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent event) { IStructuredSelection sel = (IStructuredSelection) selectedLangViewer.getSelection(); if (!sel.isEmpty()) { moveAcross( selectedLangViewer, availableLangViewer, Common.makeGenericList(NSISLanguage.class, sel.toList())); availableLangViewer.reveal(sel.getFirstElement()); langRunnable.run(); } } }); m.updateSlaves(); listsComposite.addListener( SWT.Resize, new Listener() { boolean init = false; public void handleEvent(Event e) { if (!init) { // Stupid hack so that the height hint doesn't get changed // on the first resize, // i.e., when the page is drawn for the first time. init = true; } else { Point size = listsComposite.getSize(); GridLayout layout = (GridLayout) listsComposite.getLayout(); int heightHint = size.y - 2 * layout.marginHeight; ((GridData) availableLangList.getLayoutData()).heightHint = heightHint; ((GridData) selectedLangList.getLayoutData()).heightHint = heightHint; int totalWidth = size.x - 2 * layout.marginWidth - 3 * layout.horizontalSpacing; int listWidth = (int) (totalWidth * 0.4); int buttonWidth = (int) (0.5 * (totalWidth - 2 * listWidth)); size = availableLangList.computeSize(listWidth, SWT.DEFAULT); int delta = 0; if (size.x > listWidth) { delta = size.x - listWidth; listWidth = listWidth - delta; } ((GridData) availableLangList.getLayoutData()).widthHint = listWidth; ((GridData) buttonsComposite1.getLayoutData()).widthHint = totalWidth - 2 * (listWidth + delta) - buttonWidth; ((GridData) selectedLangList.getLayoutData()).widthHint = listWidth; ((GridData) buttonsComposite2.getLayoutData()).widthHint = buttonWidth; listsComposite.layout(); } } }); addPageChangedRunnable( new Runnable() { public void run() { if (isCurrentPage()) { selectLang.setEnabled(mse.canEnable(selectLang)); if (displaySupported != null) { displaySupported.setEnabled(mse.canEnable(displaySupported)); } } } }); mWizard.addSettingsListener( new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, NSISWizardSettings newSettings) { enableLangSupport.setSelection(newSettings.isEnableLanguageSupport()); m.updateSlaves(); selectLang.setSelection(newSettings.isSelectLanguage()); if (displaySupported != null) { displaySupported.setSelection(newSettings.isDisplaySupportedLanguages()); } java.util.List<NSISLanguage> selectedLanguages = newSettings.getLanguages(); java.util.List<NSISLanguage> availableLanguages = NSISLanguageManager.getInstance().getLanguages(); if (selectedLanguages.isEmpty()) { NSISWizardWelcomePage welcomePage = (NSISWizardWelcomePage) mWizard.getPage(NSISWizardWelcomePage.NAME); if (welcomePage != null) { if (!welcomePage.isCreateFromTemplate()) { NSISLanguage defaultLanguage = NSISLanguageManager.getInstance().getDefaultLanguage(); if (defaultLanguage != null && availableLanguages.contains(defaultLanguage)) { selectedLanguages.add(defaultLanguage); } } } } selectedLangViewer.setInput(selectedLanguages); availableLanguages.removeAll(selectedLanguages); availableLangViewer.setInput(availableLanguages); } }); }
private void createMultiUserGroup(Composite parent) { final Group multiUserGroup = NSISWizardDialogUtil.createGroup( parent, 2, "MultiUser Installation", null, false); // $NON-NLS-1$ GridData data = (GridData) multiUserGroup.getLayoutData(); data.verticalAlignment = SWT.FILL; data.horizontalAlignment = SWT.FILL; data.grabExcessHorizontalSpace = true; NSISWizardSettings settings = mWizard.getSettings(); Composite composite = new Composite(multiUserGroup, SWT.NONE); data = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(data); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); final Button multiUser = NSISWizardDialogUtil.createCheckBox( composite, EclipseNSISPlugin.getResourceString("enable.multiuser.label"), // $NON-NLS-1$ settings.isMultiUserInstallation(), settings.getInstallerType() == INSTALLER_TYPE_MUI2, null, false); multiUser.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean selection = multiUser.getSelection(); mWizard.getSettings().setMultiUserInstallation(selection); validateField(MULTIUSER_CHECK); } }); final MasterSlaveController m = new MasterSlaveController(multiUser); boolean enabled = multiUser.isEnabled() && multiUser.getSelection(); final Combo execLevel = NSISWizardDialogUtil.createCombo( composite, NSISWizardDisplayValues.MULTIUSER_EXEC_LEVELS, settings.getMultiUserExecLevel(), true, EclipseNSISPlugin.getResourceString("multiuser.exec.level.label"), // $NON-NLS-1$ enabled, m, false); ((GridData) execLevel.getLayoutData()).horizontalAlignment = SWT.FILL; ((GridData) execLevel.getLayoutData()).grabExcessHorizontalSpace = true; final Group instModeGroup = NSISWizardDialogUtil.createGroup( multiUserGroup, 1, "Installation Mode", m, false); // $NON-NLS-1$ data = (GridData) instModeGroup.getLayoutData(); data.verticalAlignment = SWT.FILL; data.horizontalAlignment = SWT.FILL; data.grabExcessHorizontalSpace = true; data.horizontalSpan = 1; MasterSlaveEnabler mse = new MasterSlaveEnabler() { public void enabled(Control control, boolean flag) {} public boolean canEnable(Control c) { return isMultiUser(); } }; m.addSlave(execLevel, mse); enabled = enabled && execLevel.getSelectionIndex() != MULTIUSER_EXEC_LEVEL_STANDARD; mse = new MasterSlaveEnabler() { public void enabled(Control control, boolean flag) {} public boolean canEnable(Control c) { return isMultiUser() && mWizard.getSettings().getMultiUserExecLevel() != MULTIUSER_EXEC_LEVEL_STANDARD; } }; execLevel.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setMultiUserExecLevel(execLevel.getSelectionIndex()); m.updateSlaves(); validateField(MULTIUSER_CHECK); } }); final Combo instMode = NSISWizardDialogUtil.createCombo( instModeGroup, NSISWizardDisplayValues.MULTIUSER_INSTALL_MODES, settings.getMultiUserInstallMode(), true, EclipseNSISPlugin.getResourceString("multiuser.install.mode.label"), enabled, m, false); //$NON-NLS-1$ ((GridData) instMode.getLayoutData()).grabExcessHorizontalSpace = true; ((GridData) instMode.getLayoutData()).horizontalAlignment = SWT.FILL; instMode.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setMultiUserInstallMode(instMode.getSelectionIndex()); validateField(MULTIUSER_CHECK); } }); m.addSlave(instMode, mse); composite = new Composite(instModeGroup, SWT.NONE); data = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(data); layout = new GridLayout(2, true); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); final Button instModeRemember = NSISWizardDialogUtil.createCheckBox( composite, EclipseNSISPlugin.getResourceString("multiuser.install.mode.remember.label"), settings.isMultiUserInstallModeRemember(), // $NON-NLS-1$ enabled, m, false); ((GridData) instModeRemember.getLayoutData()).horizontalSpan = 1; instModeRemember.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setMultiUserInstallModeRemember(instModeRemember.getSelection()); validateField(MULTIUSER_CHECK); } }); m.addSlave(instModeRemember, mse); final Button instModeAsk = NSISWizardDialogUtil.createCheckBox( composite, EclipseNSISPlugin.getResourceString("multiuser.install.mode.ask.label"), settings.isMultiUserInstallModeAsk(), // $NON-NLS-1$ enabled, m, false); ((GridData) instModeAsk.getLayoutData()).horizontalSpan = 1; instModeAsk.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { mWizard.getSettings().setMultiUserInstallModeAsk(instModeAsk.getSelection()); validateField(MULTIUSER_CHECK); } }); m.addSlave(instModeAsk, mse); m.updateSlaves(); addPageChangedRunnable( new Runnable() { public void run() { if (isCurrentPage()) { NSISWizardDialogUtil.setEnabled( multiUser, mWizard.getSettings().getInstallerType() == INSTALLER_TYPE_MUI2); m.updateSlaves(); } } }); mWizard.addSettingsListener( new INSISWizardSettingsListener() { public void settingsChanged( NSISWizardSettings oldSettings, NSISWizardSettings newSettings) { NSISWizardSettings settings = mWizard.getSettings(); multiUser.setSelection(settings.isMultiUserInstallation()); execLevel.select(settings.getMultiUserExecLevel()); instMode.select(settings.getMultiUserInstallMode()); instModeRemember.setSelection(settings.isMultiUserInstallModeRemember()); instModeAsk.setSelection(settings.isMultiUserInstallModeAsk()); NSISWizardDialogUtil.setEnabled( multiUser, settings.getInstallerType() == INSTALLER_TYPE_MUI2); m.updateSlaves(); } }); }
@Override public void createControl(final Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 3; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); label.setText("&Container:"); containerText = new Text(container, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); containerText.setLayoutData(gd); containerText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); Button button = new Button(container, SWT.PUSH); button.setText("Browse..."); button.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { handleBrowse(); } }); label = new Label(container, SWT.NULL); label.setText("&Choose a model:"); Composite middleComposite = new Composite(container, SWT.NULL); FillLayout fillLayout = new FillLayout(); middleComposite.setLayout(fillLayout); emptyModelButton = new Button(middleComposite, SWT.RADIO); emptyModelButton.setText("Empty"); emptyModelButton.setSelection(true); skeletonModelButton = new Button(middleComposite, SWT.RADIO); skeletonModelButton.setText("Skeleton"); exampleModelButton = new Button(middleComposite, SWT.RADIO); exampleModelButton.setText("Example"); emptyModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "empty"; radioChanged(); } }); exampleModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "example"; radioChanged(); } }); skeletonModelButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { typeOfModel = "skeleton"; radioChanged(); } }); /* Need to add empty label so the next controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&File name:"); fileText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); fileText.setLayoutData(gd); fileText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { Text t = (Text) e.getSource(); String fname = t.getText(); int i = fname.lastIndexOf(".gaml"); if (i > 0) { // model title = filename less extension less all non alphanumeric characters titleText.setText(fname.substring(0, i).replaceAll("[^\\p{Alnum}]", "")); } /* * else if (fname.length()>0) { * int pos = t.getSelection().x; * fname = fname.replaceAll("[[^\\p{Alnum}]&&[^_-]&&[^\\x2E]]", "_"); * t.setText(fname+".gaml"); * t.setSelection(pos); * } else { * t.setText("new.gaml"); * } */ dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Author:"); authorText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); authorText.setLayoutData(gd); authorText.setText(getComputerFullName()); authorText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Model name:"); titleText = new Text(container, SWT.BORDER | SWT.SINGLE); gd = new GridData(GridData.FILL_HORIZONTAL); titleText.setLayoutData(gd); titleText.setText("new"); titleText.addModifyListener( new ModifyListener() { @Override public void modifyText(final ModifyEvent e) { dialogChanged(); } }); /* Need to add empty label so the next two controls are pushed to the next line in the grid. */ label = new Label(container, SWT.NULL); label.setText(""); label = new Label(container, SWT.NULL); label.setText("&Model description:"); descriptionText = new Text(container, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); descriptionText.setBounds(0, 0, 250, 100); gd = new GridData(SWT.FILL, SWT.FILL, true, false); gd.verticalSpan = 4; descriptionText.setLayoutData(gd); /* * Need to add seven empty labels in order to push next controls after the descriptionText * box. */ // TODO Dirty!! Change the way to do this for (int i = 0; i < 7; i++) { label = new Label(container, SWT.NULL); label.setText(""); } label = new Label(container, SWT.NULL); label.setText("&Create a html template \nfor the model description ?"); middleComposite = new Composite(container, SWT.NULL); fillLayout = new FillLayout(); middleComposite.setLayout(fillLayout); yesButton = new Button(middleComposite, SWT.RADIO); yesButton.setText("Yes"); yesButton.setSelection(true); Button noButton = new Button(middleComposite, SWT.RADIO); noButton.setText("No"); yesButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent se) { dialogChanged(); } }); /* Finished adding the custom control */ initialize(); dialogChanged(); setControl(container); }
void createControlTransfer(Composite parent) { Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.cut(); } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.paste(); } }); text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.cut(); } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.paste(); } }); combo = new Combo(parent, SWT.NONE); combo.setItems(new String[] {"Item 1", "Item 2", "Item 3", "A longer Item"}); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); l = new Label(parent, SWT.NONE); l.setVisible(false); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.paste(); } }); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; styledText.setLayoutData(data); }
public Shell open(Display display) { clipboard = new Clipboard(display); shell = new Shell(display); shell.setText("SWT Clipboard"); shell.setLayout(new FillLayout()); ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); sc.setContent(parent); parent.setLayout(new GridLayout(2, true)); Group copyGroup = new Group(parent, SWT.NONE); copyGroup.setText("Copy From:"); GridData data = new GridData(GridData.FILL_BOTH); copyGroup.setLayoutData(data); copyGroup.setLayout(new GridLayout(3, false)); Group pasteGroup = new Group(parent, SWT.NONE); pasteGroup.setText("Paste To:"); data = new GridData(GridData.FILL_BOTH); pasteGroup.setLayoutData(data); pasteGroup.setLayout(new GridLayout(3, false)); Group controlGroup = new Group(parent, SWT.NONE); controlGroup.setText("Control API:"); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; controlGroup.setLayoutData(data); controlGroup.setLayout(new GridLayout(5, false)); Group typesGroup = new Group(parent, SWT.NONE); typesGroup.setText("Available Types"); data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; typesGroup.setLayoutData(data); typesGroup.setLayout(new GridLayout(2, false)); status = new Label(parent, SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; data.heightHint = 60; status.setLayoutData(data); createTextTransfer(copyGroup, pasteGroup); createRTFTransfer(copyGroup, pasteGroup); createHTMLTransfer(copyGroup, pasteGroup); createFileTransfer(copyGroup, pasteGroup); createMyTransfer(copyGroup, pasteGroup); createControlTransfer(controlGroup); createAvailableTypes(typesGroup); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); sc.setExpandHorizontal(true); sc.setExpandVertical(true); Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle monitorArea = shell.getMonitor().getClientArea(); shell.setSize( Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20)); shell.open(); return shell; }
/** @see OpenGLTab#createControls(Composite) */ void createControls(Composite composite) { Group movementGroup = new Group(composite, SWT.NONE); movementGroup.setText("Translation"); movementGroup.setLayout(new GridLayout(2, false)); new Label(movementGroup, SWT.NONE).setText("X:"); final Slider xMove = new Slider(movementGroup, SWT.NONE); xMove.setIncrement(1); xMove.setMaximum(12); xMove.setMinimum(0); xMove.setThumb(2); xMove.setPageIncrement(2); xMove.setSelection(5); xMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { xPos = xMove.getSelection() - 5; } }); new Label(movementGroup, SWT.NONE).setText("Y:"); final Slider yMove = new Slider(movementGroup, SWT.NONE); yMove.setIncrement(1); yMove.setMaximum(12); yMove.setMinimum(0); yMove.setThumb(2); yMove.setPageIncrement(2); yMove.setSelection(5); yMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { yPos = yMove.getSelection() - 5; } }); new Label(movementGroup, SWT.NONE).setText("Z:"); final Slider zMove = new Slider(movementGroup, SWT.NONE); zMove.setIncrement(1); zMove.setMaximum(24); zMove.setMinimum(0); zMove.setThumb(4); zMove.setPageIncrement(2); zMove.setSelection(10); zMove.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { zPos = zMove.getSelection() - 25; } }); Composite fogTypesGroup = new Composite(composite, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; fogTypesGroup.setLayout(layout); fogTypesGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(fogTypesGroup, SWT.NONE).setText("Fog Types:"); final Combo fogTypeCombo = new Combo(fogTypesGroup, SWT.READ_ONLY); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.grabExcessHorizontalSpace = true; fogTypeCombo.setLayoutData(data); fogTypeCombo.setItems(FOG_NAMES); fogTypeCombo.select(0); new Label(composite, SWT.NONE).setText("Fog Density:"); final Slider fogDensitySlider = new Slider(composite, SWT.NONE); fogDensitySlider.setIncrement(1); fogDensitySlider.setMaximum(32); fogDensitySlider.setMinimum(0); fogDensitySlider.setThumb(2); fogDensitySlider.setPageIncrement(5); fogDensitySlider.setSelection(0); fogDensitySlider.setEnabled(false); fogDensitySlider.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { float fogDensity = ((float) fogDensitySlider.getSelection()) / 100; GL.glFogf(GL.GL_FOG_DENSITY, fogDensity); } }); fogTypeCombo.addListener( SWT.Selection, new Listener() { public void handleEvent(Event e) { int currentSelection = fogTypeCombo.getSelectionIndex(); // fog type GL.GL_LINEAR does not utilize fogDensity, but the other fog types do fogDensitySlider.setEnabled(currentSelection != 0); GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[currentSelection]); } }); }
/** @see PreferencePage#createContents(Composite) */ protected Control createContents(Composite ancestor) { Composite parent = new Composite(ancestor, SWT.NULL); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; parent.setLayout(layout); // layout the top table & its buttons Label label = new Label(parent, SWT.LEFT); label.setText(XMLCompareMessages.XMLComparePreference_topTableLabel); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; label.setLayoutData(data); fIdMapsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); fIdMapsTable.setHeaderVisible(true); data = new GridData(GridData.FILL_BOTH); data.heightHint = fIdMapsTable.getItemHeight() * 4; fIdMapsTable.setLayoutData(data); fIdMapsTable.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { selectionChanged(); } }); String column2Text = XMLCompareMessages.XMLComparePreference_topTableColumn2; String column3Text = XMLCompareMessages.XMLComparePreference_topTableColumn3; ColumnLayoutData columnLayouts[] = { new ColumnWeightData(1), new ColumnPixelData(convertWidthInCharsToPixels(column2Text.length() + 2), true), new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 5), true) }; TableLayout tablelayout = new TableLayout(); fIdMapsTable.setLayout(tablelayout); for (int i = 0; i < 3; i++) tablelayout.addColumnData(columnLayouts[i]); TableColumn column = new TableColumn(fIdMapsTable, SWT.NONE); column.setText(XMLCompareMessages.XMLComparePreference_topTableColumn1); column = new TableColumn(fIdMapsTable, SWT.NONE); column.setText(column2Text); column = new TableColumn(fIdMapsTable, SWT.NONE); column.setText(column3Text); fillIdMapsTable(); Composite buttons = new Composite(parent, SWT.NULL); buttons.setLayout(new GridLayout()); data = new GridData(); data.verticalAlignment = GridData.FILL; data.horizontalAlignment = GridData.FILL; buttons.setLayoutData(data); fAddIdMapButton = new Button(buttons, SWT.PUSH); fAddIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topAdd); fAddIdMapButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addIdMap(fAddIdMapButton.getShell()); } }); data = new GridData(); data.horizontalAlignment = GridData.FILL; // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); fAddIdMapButton.setLayoutData(data); fRenameIdMapButton = new Button(buttons, SWT.PUSH); fRenameIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRename); fRenameIdMapButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { renameIdMap(fRenameIdMapButton.getShell()); } }); data = new GridData(); data.horizontalAlignment = GridData.FILL; // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, fAddIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); fRenameIdMapButton.setLayoutData(data); fRemoveIdMapButton = new Button(buttons, SWT.PUSH); fRemoveIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topRemove); fRemoveIdMapButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { removeIdMap(fRemoveIdMapButton.getShell()); } }); data = new GridData(); data.horizontalAlignment = GridData.FILL; // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, fRemoveIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); fRemoveIdMapButton.setLayoutData(data); createSpacer(buttons); fEditIdMapButton = new Button(buttons, SWT.PUSH); fEditIdMapButton.setText(XMLCompareMessages.XMLComparePreference_topEdit); fEditIdMapButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { editIdMap(fEditIdMapButton.getShell()); } }); data = new GridData(); data.horizontalAlignment = GridData.FILL; // data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, fEditIdMapButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); fEditIdMapButton.setLayoutData(data); // Spacer label = new Label(parent, SWT.LEFT); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; label.setLayoutData(data); // layout the middle table & its buttons label = new Label(parent, SWT.LEFT); label.setText(XMLCompareMessages.XMLComparePreference_middleTableLabel); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; label.setLayoutData(data); fMappingsTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); fMappingsTable.setHeaderVisible(true); data = new GridData(GridData.FILL_BOTH); data.heightHint = fMappingsTable.getItemHeight() * 4; data.widthHint = convertWidthInCharsToPixels(70); fMappingsTable.setLayoutData(data); column3Text = XMLCompareMessages.XMLComparePreference_middleTableColumn3; String column4Text = XMLCompareMessages.XMLComparePreference_middleTableColumn4; columnLayouts = new ColumnLayoutData[] { new ColumnWeightData(10), new ColumnWeightData(18), new ColumnPixelData(convertWidthInCharsToPixels(column3Text.length() + 1), true), new ColumnPixelData(convertWidthInCharsToPixels(column4Text.length() + 3), true) }; tablelayout = new TableLayout(); fMappingsTable.setLayout(tablelayout); for (int i = 0; i < 4; i++) tablelayout.addColumnData(columnLayouts[i]); column = new TableColumn(fMappingsTable, SWT.NONE); column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn1); column = new TableColumn(fMappingsTable, SWT.NONE); column.setText(XMLCompareMessages.XMLComparePreference_middleTableColumn2); column = new TableColumn(fMappingsTable, SWT.NONE); column.setText(column3Text); column = new TableColumn(fMappingsTable, SWT.NONE); column.setText(column4Text); buttons = new Composite(parent, SWT.NULL); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); fNewMappingsButton = new Button(buttons, SWT.PUSH); fNewMappingsButton.setLayoutData(getButtonGridData(fNewMappingsButton)); fNewMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleNew); fNewMappingsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addMapping(fAddIdMapButton.getShell()); } }); fEditMappingsButton = new Button(buttons, SWT.PUSH); fEditMappingsButton.setLayoutData(getButtonGridData(fEditMappingsButton)); fEditMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleEdit); fEditMappingsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { editMapping(fEditMappingsButton.getShell()); } }); fRemoveMappingsButton = new Button(buttons, SWT.PUSH); fRemoveMappingsButton.setLayoutData(getButtonGridData(fRemoveMappingsButton)); fRemoveMappingsButton.setText(XMLCompareMessages.XMLComparePreference_middleRemove); fRemoveMappingsButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { removeMapping(fRemoveMappingsButton.getShell()); } }); createSpacer(buttons); // layout the botton table & its buttons label = new Label(parent, SWT.LEFT); label.setText(XMLCompareMessages.XMLComparePreference_bottomTableLabel); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; label.setLayoutData(data); fOrderedTable = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); fOrderedTable.setHeaderVisible(true); data = new GridData(GridData.FILL_BOTH); data.heightHint = fOrderedTable.getItemHeight() * 2; data.widthHint = convertWidthInCharsToPixels(70); fOrderedTable.setLayoutData(data); columnLayouts = new ColumnLayoutData[] {new ColumnWeightData(1), new ColumnWeightData(1)}; tablelayout = new TableLayout(); fOrderedTable.setLayout(tablelayout); for (int i = 0; i < 2; i++) tablelayout.addColumnData(columnLayouts[i]); column = new TableColumn(fOrderedTable, SWT.NONE); column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn1); column = new TableColumn(fOrderedTable, SWT.NONE); column.setText(XMLCompareMessages.XMLComparePreference_bottomTableColumn2); buttons = new Composite(parent, SWT.NULL); buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttons.setLayout(layout); fNewOrderedButton = new Button(buttons, SWT.PUSH); fNewOrderedButton.setLayoutData(getButtonGridData(fNewOrderedButton)); fNewOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomNew); fNewOrderedButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { addOrdered(fNewOrderedButton.getShell()); } }); fEditOrderedButton = new Button(buttons, SWT.PUSH); fEditOrderedButton.setLayoutData(getButtonGridData(fEditOrderedButton)); fEditOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomEdit); fEditOrderedButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { editOrdered(fEditOrderedButton.getShell()); } }); fRemoveOrderedButton = new Button(buttons, SWT.PUSH); fRemoveOrderedButton.setLayoutData(getButtonGridData(fRemoveOrderedButton)); fRemoveOrderedButton.setText(XMLCompareMessages.XMLComparePreference_bottomRemove); fRemoveOrderedButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { removeOrdered(fRemoveOrderedButton.getShell()); } }); createSpacer(buttons); fIdMapsTable.setSelection(0); fIdMapsTable.setFocus(); selectionChanged(); return parent; }
@Override protected Control createControl(Composite parent) { Composite propertyComposite = new Composite(parent, SWT.BORDER); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; propertyComposite.setLayout(layout); if (mPage instanceof Page) { ((Page) mPage) .init( new IPageSite() { public void registerContextMenu( String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {} public IActionBars getActionBars() { return null; } public IWorkbenchPage getPage() { return getWorkbenchWindow().getActivePage(); } public ISelectionProvider getSelectionProvider() { return null; } public Shell getShell() { return getWorkbenchWindow().getShell(); } public IWorkbenchWindow getWorkbenchWindow() { return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } public void setSelectionProvider(ISelectionProvider provider) {} @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { return null; } @SuppressWarnings("unchecked") public Object getService(Class api) { return null; } @SuppressWarnings("unchecked") public boolean hasService(Class api) { return false; } }); } if (mPage instanceof PropertySheetPage) { ((PropertySheetPage) mPage).setPropertySourceProvider(this); } mPage.createControl(propertyComposite); mPage.setActionBars(new DummyActionBars()); final Control control = mPage.getControl(); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); if (control instanceof Tree) { final Tree tree = (Tree) control; data.heightHint = tree.getItemHeight() * 13 + (tree.getLinesVisible() ? 12 * tree.getGridLineWidth() : 0) + (tree.getHeaderVisible() ? tree.getHeaderHeight() : 0) + 2 * tree.getBorderWidth() + (tree.getHorizontalBar() != null ? tree.getHorizontalBar().getSize().x : 0); tree.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle area = tree.getClientArea(); TreeColumn[] columns = tree.getColumns(); if (area.width > 0) { columns[0].setWidth(area.width * 40 / 100); columns[1].setWidth(area.width - columns[0].getWidth() - 4); } } }); } else if (control instanceof Composite) { control.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { ((Composite) control).layout(true, true); } }); } control.setLayoutData(data); ISelection selection; if (mCurrentWidget == null) { Collection<InstallOptionsModelTypeDef> typeDefs = InstallOptionsModel.INSTANCE.getControlTypeDefs(); if (typeDefs.size() > 0) { InstallOptionsModelTypeDef typeDef = typeDefs.iterator().next(); InstallOptionsElementFactory factory = InstallOptionsElementFactory.getFactory(typeDef.getType()); mCurrentWidget = (InstallOptionsWidget) factory.getNewObject(); mDialog.addChild(mCurrentWidget); } } if (mCurrentWidget != null) { mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); if (mCurrentWidget.getParent() != null) { mCurrentWidget.getParent().addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); } selection = new StructuredSelection(mCurrentWidget); } else { selection = StructuredSelection.EMPTY; } mPage.selectionChanged(null, selection); PlatformUI.getWorkbench().getHelpSystem().setHelp(mPage.getControl(), HELP_CONTEXT); PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyComposite, HELP_CONTEXT); return propertyComposite; }
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; shell.setLayout(gridLayout); ToolBar toolbar = new ToolBar(shell, SWT.NONE); ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH); itemBack.setText("Back"); ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH); itemForward.setText("Forward"); ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH); itemStop.setText("Stop"); ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH); itemRefresh.setText("Refresh"); ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH); itemGo.setText("Go"); GridData data = new GridData(); data.horizontalSpan = 3; toolbar.setLayoutData(data); Label labelAddress = new Label(shell, SWT.NONE); labelAddress.setText("Address"); final Text location = new Text(shell, SWT.BORDER); data = new GridData(); data.horizontalAlignment = GridData.FILL; data.horizontalSpan = 2; data.grabExcessHorizontalSpace = true; location.setLayoutData(data); final Browser browser; try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } data = new GridData(); data.horizontalAlignment = GridData.FILL; data.verticalAlignment = GridData.FILL; data.horizontalSpan = 3; data.grabExcessHorizontalSpace = true; data.grabExcessVerticalSpace = true; browser.setLayoutData(data); final Label status = new Label(shell, SWT.NONE); data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2; status.setLayoutData(data); final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE); data = new GridData(); data.horizontalAlignment = GridData.END; progressBar.setLayoutData(data); /* event handling */ Listener listener = new Listener() { @Override public void handleEvent(Event event) { ToolItem item = (ToolItem) event.widget; String string = item.getText(); if (string.equals("Back")) browser.back(); else if (string.equals("Forward")) browser.forward(); else if (string.equals("Stop")) browser.stop(); else if (string.equals("Refresh")) browser.refresh(); else if (string.equals("Go")) browser.setUrl(location.getText()); } }; browser.addProgressListener( new ProgressListener() { @Override public void changed(ProgressEvent event) { if (event.total == 0) return; int ratio = event.current * 100 / event.total; progressBar.setSelection(ratio); } @Override public void completed(ProgressEvent event) { progressBar.setSelection(0); } }); browser.addStatusTextListener( new StatusTextListener() { @Override public void changed(StatusTextEvent event) { status.setText(event.text); } }); browser.addLocationListener( new LocationListener() { @Override public void changed(LocationEvent event) { if (event.top) location.setText(event.location); } @Override public void changing(LocationEvent event) {} }); itemBack.addListener(SWT.Selection, listener); itemForward.addListener(SWT.Selection, listener); itemStop.addListener(SWT.Selection, listener); itemRefresh.addListener(SWT.Selection, listener); itemGo.addListener(SWT.Selection, listener); location.addListener( SWT.DefaultSelection, new Listener() { @Override public void handleEvent(Event e) { browser.setUrl(location.getText()); } }); shell.open(); browser.setUrl("http://eclipse.org"); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }