public Shell open(Display display) { shell = new Shell(display); shell.setLayout(new FillLayout()); shell.addShellListener( new ShellAdapter() { @Override public void shellClosed(ShellEvent e) { e.doit = closeAddressBook(); } }); createMenuBar(); searchDialog = new SearchDialog(shell); searchDialog.setSearchAreaNames(columnNames); searchDialog.setSearchAreaLabel(resAddressBook.getString("Column")); searchDialog.addFindListener( new FindListener() { public boolean find() { return findEntry(); } }); table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setMenu(createPopUpMenu()); table.addSelectionListener( new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length > 0) editEntry(items[0]); } }); for (int i = 0; i < columnNames.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(columnNames[i]); column.setWidth(150); final int columnIndex = i; column.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { sort(columnIndex); } }); } newAddressBook(); shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); return shell; }
public Shell open(Display display) { // Window dressing - the icon windowIcon = new Image(display, getClass().getClassLoader().getResourceAsStream("icons/joanju.gif")); shell = new Shell(display); shell.setLayout(new FillLayout()); shell.addShellListener( new ShellAdapter() { public void shellClosed(ShellEvent e) { e.doit = closeAddressBook(); } }); shell.setImage(windowIcon); createMenuBar(); searchDialog = new SearchDialog(shell); searchDialog.setSearchAreaNames(columnNames); searchDialog.setSearchAreaLabel(resMessages.getString("Column")); searchDialog.addFindListener( new FindListener() { public boolean find() { return findEntry(); } }); table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setMenu(createPopUpMenu()); table.addSelectionListener( new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { TableItem[] items = table.getSelection(); if (items.length > 0) launchEditor(items[0]); } }); int[] widths = {150, 50, 200, 200}; for (int i = 0; i < columnNames.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(columnNames[i]); column.setWidth(widths[i]); final int columnIndex = i; column.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { sort(columnIndex); } }); } newAddressBook(); shell.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { windowIcon.dispose(); } }); shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300); shell.open(); return shell; }
/** @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; }
private Control createProfilesContainer(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.numColumns = 2; layout.verticalSpacing = 3; layout.horizontalSpacing = 3; container.setLayout(layout); Label caption = new Label(container, SWT.NONE); caption.setText("Profiles"); caption.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); profilesTable = new Table(container, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK); profilesTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4)); profilesTable.setHeaderVisible(true); profilesTable.setLinesVisible(true); TableColumn nameColumn = new TableColumn(profilesTable, SWT.LEFT); nameColumn.setText("Name"); nameColumn.setWidth(150); TableColumn pathColumn = new TableColumn(profilesTable, SWT.LEFT); pathColumn.setText("Target directory"); pathColumn.setWidth(300); TableColumn fileColumn = new TableColumn(profilesTable, SWT.LEFT); fileColumn.setText("Target file"); fileColumn.setWidth(150); profilesTable.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateTableSelection(); } }); addProfileButton = new Button(container, SWT.PUSH); addProfileButton.setText("Add..."); addProfileButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); addProfileButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { addProfile(); } }); editProfileButton = new Button(container, SWT.PUSH); editProfileButton.setText("Edit..."); editProfileButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); editProfileButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { editProfile(); } }); removeProfileButton = new Button(container, SWT.PUSH); removeProfileButton.setText("Remove"); removeProfileButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); removeProfileButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deleteProfile(); } }); return container; }
@Override protected Control createContents(final Composite parent) { Composite composite = UIUtils.createPlaceholder(parent, 1, 5); { typeTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION); typeTable.setLayoutData(new GridData(GridData.FILL_BOTH)); UIUtils.createTableColumn(typeTable, SWT.LEFT, "Name"); UIUtils.createTableColumn(typeTable, SWT.LEFT, "Description"); typeTable.setHeaderVisible(true); typeTable.setLayoutData(new GridData(GridData.FILL_BOTH)); typeTable.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { showSelectedType(getSelectedType()); } }); Composite tableGroup = UIUtils.createPlaceholder(composite, 2, 5); tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Button newButton = new Button(tableGroup, SWT.PUSH); newButton.setText("New"); newButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String name; for (int i = 1; ; i++) { name = "Type" + i; boolean hasName = false; for (DBPConnectionType type : changedInfo.keySet()) { if (type.getName().equals(name)) { hasName = true; break; } } if (!hasName) { break; } } DBPConnectionType newType = new DBPConnectionType( SecurityUtils.generateUniqueId(), name, "255,255,255", "New type", true, false); addTypeToTable(newType, newType); typeTable.select(typeTable.getItemCount() - 1); typeTable.showSelection(); showSelectedType(newType); } }); deleteButton = new Button(tableGroup, SWT.PUSH); deleteButton.setText("Delete"); deleteButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { DBPConnectionType connectionType = getSelectedType(); if (!UIUtils.confirmAction( deleteButton.getShell(), "Delete connection type", "Are you sure you want to delete connection type '" + connectionType.getName() + "'?\n" + "All connections of this type will be reset to default type (" + DBPConnectionType.DEFAULT_TYPE.getName() + ")")) { return; } changedInfo.remove(connectionType); int index = typeTable.getSelectionIndex(); typeTable.remove(index); if (index > 0) index--; typeTable.select(index); showSelectedType(getSelectedType()); } }); } { Group groupSettings = UIUtils.createControlGroup( composite, "Settings", 2, GridData.VERTICAL_ALIGN_BEGINNING, 300); groupSettings.setLayoutData(new GridData(GridData.FILL_BOTH)); typeName = UIUtils.createLabelText(groupSettings, "Name", null); typeName.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { getSelectedType().setName(typeName.getText()); updateTableInfo(); } }); typeDescription = UIUtils.createLabelText(groupSettings, "Description", null); typeDescription.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { getSelectedType().setDescription(typeDescription.getText()); updateTableInfo(); } }); { UIUtils.createControlLabel(groupSettings, "Color"); Composite colorGroup = UIUtils.createPlaceholder(groupSettings, 2, 5); colorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); colorPicker = new CImageCombo(colorGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); colorPicker.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); colorPicker.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getSelectedType() .setColor( StringConverter.asString( colorPicker .getItem(colorPicker.getSelectionIndex()) .getBackground() .getRGB())); updateTableInfo(); } }); Button pickerButton = new Button(colorGroup, SWT.PUSH); pickerButton.setText("..."); pickerButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { DBPConnectionType connectionType = getSelectedType(); ColorDialog colorDialog = new ColorDialog(parent.getShell()); colorDialog.setRGB(StringConverter.asRGB(connectionType.getColor())); RGB rgb = colorDialog.open(); if (rgb != null) { Color color = null; int count = colorPicker.getItemCount(); for (int i = 0; i < count; i++) { TableItem item = colorPicker.getItem(i); if (item.getBackground() != null && item.getBackground().getRGB().equals(rgb)) { color = item.getBackground(); break; } } if (color == null) { color = new Color(colorPicker.getDisplay(), rgb); colorPicker.add(null, COLOR_TEXT, color, color); } colorPicker.select(color); getSelectedType().setColor(StringConverter.asString(color.getRGB())); updateTableInfo(); } } }); } GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 2; autocommitCheck = UIUtils.createCheckbox(groupSettings, "Auto-commit by default", false); autocommitCheck.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getSelectedType().setAutocommit(autocommitCheck.getSelection()); } }); autocommitCheck.setLayoutData(gd); confirmCheck = UIUtils.createCheckbox(groupSettings, "Confirm SQL execution", false); confirmCheck.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { getSelectedType().setConfirmExecute(confirmCheck.getSelection()); } }); confirmCheck.setLayoutData(gd); } performDefaults(); return composite; }