List of usage examples for org.eclipse.jface.viewers DialogCellEditor create
public void create(Composite parent)
From source file:eu.geclipse.jsdl.ui.widgets.DataStageInTable.java
License:Open Source License
/** * @param parent// ww w. j av a2 s . c o m * @param input * @param buttonsPosition */ public DataStageInTable(final Composite parent, final List<DataStagingType> input, final int buttonsPosition) { this.input = input; this.mainComp = new Composite(parent, SWT.NONE); GridLayout gLayout; if (buttonsPosition == DataStageInTable.BUTTONS_RIGHT) { gLayout = new GridLayout(2, false); } else { gLayout = new GridLayout(1, false); } this.mainComp.setLayout(gLayout); GridData gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL); this.mainComp.setLayoutData(gData); this.table = new Table(this.mainComp, SWT.BORDER | SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); gData = new GridData(GridData.FILL_BOTH); gData.grabExcessVerticalSpace = true; gData.widthHint = 400; gData.heightHint = 100; this.table.setLayoutData(gData); TableLayout tableLayout = new TableLayout(); this.table.setLayout(tableLayout); TableColumn nameColumn = new TableColumn(this.table, SWT.CENTER); ColumnLayoutData data = new ColumnWeightData(100); tableLayout.addColumnData(data); data = new ColumnWeightData(100); tableLayout.addColumnData(data); data = new ColumnWeightData(150); tableLayout.addColumnData(data); nameColumn.setText(Messages.getString("DataStageInTable.source_location_field_label")); //$NON-NLS-1$ TableColumn typeColumn = new TableColumn(this.table, SWT.LEFT); typeColumn.setText(Messages.getString("DataStageInTable.name_field_label")); //$NON-NLS-1$ this.tableViewer = new TableViewer(this.table); IStructuredContentProvider contentProvider = new DataStageInContentProvider(); this.tableViewer.setContentProvider(contentProvider); this.tableViewer.setColumnProperties( new String[] { Messages.getString("DataStageInTable.source_location_field_label"), //$NON-NLS-1$ Messages.getString("DataStageInTable.name_field_label") //$NON-NLS-1$ }); this.tableViewer.setLabelProvider(new DataStageInContentLabelProvider()); if (this.input == null) { this.input = new ArrayList<DataStagingType>(); } this.tableViewer.setInput(this.input); this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { updateButtons(); } }); Composite buttonsComp = new Composite(this.mainComp, SWT.NONE); if (buttonsPosition == DataStageInTable.BUTTONS_BOTTOM) { gLayout = new GridLayout(3, true); } else { gLayout = new GridLayout(1, false); } buttonsComp.setLayout(gLayout); this.addButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END); buttonsComp.setLayoutData(gData); gData = new GridData(GridData.FILL_BOTH); this.addButton.setLayoutData(gData); this.addButton.setText(Messages.getString("DataStageInTable.add_button_label")); //$NON-NLS-1$ this.addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { editDataStagingEntry(null); } }); this.editButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.FILL_BOTH); this.editButton.setLayoutData(gData); this.editButton.setText(Messages.getString("DataStageInTable.edit_button_label")); //$NON-NLS-1$ this.editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { editDataStagingEntry(getSelectedObject()); } }); this.removeButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.FILL_BOTH); this.removeButton.setLayoutData(gData); this.removeButton.setText(Messages.getString("DataStageInTable.remove_button_label")); //$NON-NLS-1$ this.removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent event) { DataStageInTable.this.input.remove(getSelectedObject()); DataStageInTable.this.tableViewer.refresh(); } }); DialogCellEditor editor = new DialogCellEditor() { @Override protected Object openDialogBox(final Control cellEditorWindow) { String filename = (String) doGetValue(); GridFileDialog dialog = new GridFileDialog(DataStageInTable.this.mainComp.getShell(), GridFileDialog.STYLE_ALLOW_ONLY_EXISTING | GridFileDialog.STYLE_ALLOW_ONLY_FILES); if (dialog.open() == Window.OK) { URI[] uris = dialog.getSelectedURIs(); if ((uris != null) && (uris.length > 0)) { filename = uris[0].toString(); } } // IGridConnectionElement connection = GridFileDialog.openFileDialog( // DataStageInTable.this.mainComp.getShell(), // Messages.getString( "DataStageInTable.grid_file_dialog_title" ), // //$NON-NLS-1$ // null, // true ); // if( connection != null ) { // try { // filename = connection.getConnectionFileStore().toString(); // } catch( CoreException cExc ) { // ProblemException exception = new ProblemException( // ICoreProblems.NET_CONNECTION_FAILED, // cExc, // Activator.PLUGIN_ID ); // ProblemDialog.openProblem( DataStageInTable.this.mainComp.getShell(), // Messages.getString( "DataStageInTable.error" ), //$NON-NLS-1$ // Messages.getString( "DataStageInTable.error" ), //$NON-NLS-1$ // exception ); // } // } return filename; } }; CellEditor[] table1 = new CellEditor[1]; table1[0] = editor; editor.create(this.table); this.tableViewer.setCellModifier(new ICellModifier() { public boolean canModify(final Object element, final String property) { return true; } public Object getValue(final Object element, final String property) { int columnIndex = -1; if (property.equals(Messages.getString("DataStageInTable.source_location_field_label"))) { //$NON-NLS-1$ columnIndex = 0; } if (property.equals(Messages.getString("DataStageInTable.name_field_label"))) { //$NON-NLS-1$ columnIndex = 1; } Object result = null; DataStagingType data1 = (DataStagingType) element; switch (columnIndex) { case 0: result = data1.getSource().getURI(); break; case 1: result = data1.getFileName(); break; default: result = ""; //$NON-NLS-1$ } return result; } public void modify(final Object element, final String property, final Object value) { int columnIndex = -1; if (property.equals(Messages.getString("DataStageInTable.source_location_field_label"))) { //$NON-NLS-1$ columnIndex = 0; } if (property.equals(Messages.getString("DataStageInTable.name_field_label"))) { //$NON-NLS-1$ columnIndex = 1; } TableItem item = (TableItem) element; DataStagingType dataOld = (DataStagingType) item.getData(); DataStagingType dataNew = null; switch (columnIndex) { case 0: dataNew = getNewDataStagingType(dataOld.getFileName(), (String) value); if (!dataNew.getFileName().equals(dataOld.getFileName()) || !dataNew.getSource().getURI().equals(dataOld.getSource().getURI())) { if (!isDataInInput(dataNew)) { // DataStageInTable.this.input.add( dataNew ); // DataStageInTable.this.input.remove( dataOld ); updateDataStaging(dataOld, dataNew.getFileName(), dataNew.getSource()); DataStageInTable.this.tableViewer.refresh(); } else { MessageDialog.openError(DataStageInTable.this.mainComp.getShell(), Messages.getString("DataStageInTable.edit_dialog_title"), //$NON-NLS-1$ Messages.getString("DataStageInTable.value_exists_dialog_message")); //$NON-NLS-1$ } } break; case 1: dataNew = getNewDataStagingType((String) value, dataOld.getSource().getURI()); if (!dataNew.getFileName().equals(dataOld.getFileName()) || !dataNew.getSource().getURI().equals(dataOld.getSource().getURI())) { if (!isDataInInput(dataNew)) { // DataStageInTable.this.input.add( dataNew ); // DataStageInTable.this.input.remove( dataOld ); updateDataStaging(dataOld, dataNew.getFileName(), dataNew.getSource()); DataStageInTable.this.tableViewer.refresh(); } else { MessageDialog.openError(DataStageInTable.this.mainComp.getShell(), Messages.getString("DataStageInTable.edit_dialog_title"), //$NON-NLS-1$ Messages.getString("DataStageInTable.value_exists_dialog_message")); //$NON-NLS-1$ } } break; } } }); CellEditor[] edTable = new CellEditor[] { editor, new TextCellEditor(this.tableViewer.getTable()) }; this.tableViewer.setCellEditors(edTable); TableViewerEditor.create(this.tableViewer, new ColumnViewerEditorActivationStrategy(this.tableViewer), ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL); updateButtons(); }
From source file:eu.geclipse.jsdl.ui.widgets.DataStageOutTable.java
License:Open Source License
/** * Creates new instance of table, table viewer, buttons (add, edit and * remove)./*from w w w .j a v a2s . co m*/ * * @param parent controls' parent * @param input input for a table * @param buttonsPosition */ public DataStageOutTable(final Composite parent, final List<DataStagingType> input, final int buttonsPosition) { this.input = input; this.mainComp = new Composite(parent, SWT.NONE); GridLayout gLayout; if (buttonsPosition == DataStageOutTable.BUTTONS_BOTTOM) { gLayout = new GridLayout(1, false); } else { gLayout = new GridLayout(2, false); } this.mainComp.setLayout(gLayout); GridData gData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH); this.mainComp.setLayoutData(gData); this.table = new Table(this.mainComp, SWT.BORDER | SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); gData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL); gData.grabExcessVerticalSpace = true; gData.widthHint = 400; gData.heightHint = 100; this.table.setLayoutData(gData); TableLayout tableLayout = new TableLayout(); this.table.setLayout(tableLayout); TableColumn nameColumn = new TableColumn(this.table, SWT.CENTER); ColumnLayoutData data = new ColumnWeightData(100); tableLayout.addColumnData(data); data = new ColumnWeightData(100); tableLayout.addColumnData(data); data = new ColumnWeightData(150); tableLayout.addColumnData(data); nameColumn.setText(Messages.getString("DataStageInTable.name_field_label")); //$NON-NLS-1$ TableColumn locationColumn = new TableColumn(this.table, SWT.LEFT); locationColumn.setText(Messages.getString("DataStageInTable.target_location_field_label")); //$NON-NLS-1$ this.tableViewer = new TableViewer(this.table); IStructuredContentProvider contentProvider = new DataStageInContentProvider(); this.tableViewer.setContentProvider(contentProvider); this.tableViewer.setColumnProperties(new String[] { Messages.getString("DataStageInTable.name_field_label"), //$NON-NLS-1$ Messages.getString("DataStageInTable.target_location_field_label") //$NON-NLS-1$ }); this.tableViewer.setLabelProvider(new DataStageInContentLabelProvider()); if (this.input == null) { this.input = new ArrayList<DataStagingType>(); } this.tableViewer.setInput(this.input); this.tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { updateButtons(); } }); Composite buttonsComp = new Composite(this.mainComp, SWT.NONE); if (buttonsPosition == DataStageOutTable.BUTTONS_BOTTOM) { gLayout = new GridLayout(3, true); } else { gLayout = new GridLayout(1, false); } buttonsComp.setLayout(gLayout); this.addButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END); buttonsComp.setLayoutData(gData); gData = new GridData(GridData.FILL_BOTH); this.addButton.setLayoutData(gData); this.addButton.setText(Messages.getString("DataStageInTable.add_button_label")); //$NON-NLS-1$ this.addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { editDataStagingEntry(null); } }); this.editButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.FILL_BOTH); this.editButton.setLayoutData(gData); this.editButton.setText(Messages.getString("DataStageInTable.edit_button_label")); //$NON-NLS-1$ this.editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { editDataStagingEntry(getSelectedObject()); } }); this.removeButton = new Button(buttonsComp, SWT.PUSH); gData = new GridData(GridData.FILL_BOTH); this.removeButton.setLayoutData(gData); this.removeButton.setText(Messages.getString("DataStageInTable.remove_button_label")); //$NON-NLS-1$ this.removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { DataStageOutTable.this.input.remove(getSelectedObject()); DataStageOutTable.this.tableViewer.refresh(); } }); DialogCellEditor editor = new DialogCellEditor() { @Override protected Object openDialogBox(final Control cellEditorWindow) { String filename = (String) doGetValue(); cellEditorWindow.getData(); GridFileDialog dialog = new GridFileDialog(DataStageOutTable.this.mainComp.getShell(), GridFileDialog.STYLE_ALLOW_ONLY_FILES); if (dialog.open() == Window.OK) { URI[] uris = dialog.getSelectedURIs(); if ((uris != null) && (uris.length > 0)) { filename = uris[0].toString(); } } return filename; } }; CellEditor[] table1 = new CellEditor[1]; table1[0] = editor; editor.create(this.table); this.tableViewer.setCellModifier(new ICellModifier() { public boolean canModify(final Object element, final String property) { return true; } public Object getValue(final Object element, final String property) { int columnIndex = -1; if (property.equals(Messages.getString("DataStageInTable.name_field_label"))) { //$NON-NLS-1$ columnIndex = 0; } if (property.equals(Messages.getString("DataStageInTable.target_location_field_label"))) { //$NON-NLS-1$ columnIndex = 1; } Object result = null; DataStagingType data1 = (DataStagingType) element; switch (columnIndex) { case 0: result = data1.getFileName(); break; case 1: result = data1.getTarget().getURI(); break; default: result = ""; //$NON-NLS-1$ } return result; } public void modify(final Object element, final String property, final Object value) { int columnIndex = -1; if (property.equals(Messages.getString("DataStageInTable.name_field_label"))) { //$NON-NLS-1$ columnIndex = 0; } if (property.equals(Messages.getString("DataStageInTable.target_location_field_label"))) { //$NON-NLS-1$ columnIndex = 1; } TableItem item = (TableItem) element; DataStagingType dataOld = (DataStagingType) item.getData(); DataStagingType dataNew = null; switch (columnIndex) { case 0: dataNew = getNewDataStagingType((String) value, dataOld.getTarget().getURI()); if (!dataNew.getFileName().equals(dataOld.getFileName()) || !dataNew.getTarget().getURI().equals(dataOld.getTarget().getURI())) { if (!isDataInInput(dataNew)) { DataStageOutTable.this.input.add(dataNew); DataStageOutTable.this.input.remove(dataOld); DataStageOutTable.this.tableViewer.refresh(); } else { MessageDialog.openError(DataStageOutTable.this.mainComp.getShell(), Messages.getString("DataStageOutTable.edit_dialog_title"), //$NON-NLS-1$ Messages.getString("DataStageOutTable.data_exists_error")); //$NON-NLS-1$ } } break; case 1: dataNew = getNewDataStagingType(dataOld.getFileName(), (String) value); if (!dataNew.getFileName().equals(dataOld.getFileName()) || !dataNew.getTarget().getURI().equals(dataOld.getTarget().getURI())) { if (!isDataInInput(dataNew)) { DataStageOutTable.this.input.add(dataNew); DataStageOutTable.this.input.remove(dataOld); DataStageOutTable.this.tableViewer.refresh(); } else { MessageDialog.openError(DataStageOutTable.this.mainComp.getShell(), Messages.getString("DataStageOutTable.edit_dialog_title"), //$NON-NLS-1$ Messages.getString("DataStageOutTable.data_exists_error")); //$NON-NLS-1$ } } break; } } }); CellEditor[] edTable = new CellEditor[] { new TextCellEditor(this.tableViewer.getTable()), editor }; this.tableViewer.setCellEditors(edTable); TableViewerEditor.create(this.tableViewer, new ColumnViewerEditorActivationStrategy(this.tableViewer), ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL); updateButtons(); }