List of usage examples for org.eclipse.jface.dialogs MessageDialog QUESTION
int QUESTION
To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.
Click Source Link
From source file:org.eclipse.datatools.enablement.sybase.asa.schemaobjecteditor.examples.tableeditor.pages.columns.ASATableEditorColumnsViewerCellModifier.java
License:Open Source License
private boolean removeReferencingUniqueConstraints(ASATableEditorColumnRowData asaRow, boolean onlyRemovePK) { // If current is nullable and it's referenced by unique constraint/pk, should remove it from the constraint if (asaRow.getColumn() != null) { BaseTable table = (BaseTable) asaRow.getColumn().eContainer(); List matches = TableModelUtil.getMatchedColumnUniqueConstraint(table, asaRow.getColumn()); if (onlyRemovePK) { Iterator iter = matches.iterator(); matches = new ArrayList(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof PrimaryKey) { matches.add(obj);/*from w w w . j a v a2 s .c o m*/ break; } } } if (matches.size() > 0) { if (true) { MessageDialog d = new MessageDialog(_viewer.getControl().getShell(), Messages.ASATableEditorColumnsViewerCellModifier_remove_constraints, null, Messages.ASATableEditorColumnsViewerCellModifier_constraints_remove_also + TableModelUtil.constructConstraintNamesList(matches) + Messages.ASATableEditorColumnsViewerCellModifier_continue, MessageDialog.QUESTION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); d.open(); int result = d.getReturnCode(); switch (result) { case MessageDialog.OK: Iterator iter = matches.iterator(); List uniquesTobeRemoved = new ArrayList(); // table.eSetDeliver(true); while (iter.hasNext()) { uniquesTobeRemoved.add(iter.next()); } table.getConstraints().removeAll(uniquesTobeRemoved); // table.eSetDeliver(false); return true; case MessageDialog.CANCEL: asaRow.updateValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN, "false"); //$NON-NLS-1$ _viewer.refresh(); return false; default: break; } } else { Iterator iter = matches.iterator(); // table.eSetDeliver(true); while (iter.hasNext()) { table.getConstraints().remove(iter.next()); } // table.eSetDeliver(false); return true; } } boolean nullable = false; if (asaRow.getValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN) != null) { nullable = Boolean.valueOf((String) asaRow.getValue(ASATableEditorColumnsTableData.NULLABLE_COLUMN)) .booleanValue(); } // If current column is selected to be nullable, should remove it from unique constraints if (nullable) { TableModelUtil.removeColumnFromRefConstraints(table, asaRow.getColumn()); } boolean isPK = false; if (asaRow.getValue(ASATableEditorColumnsTableData.PRI_KEY_COLUMN) != null) { isPK = Boolean.valueOf((String) asaRow.getValue(ASATableEditorColumnsTableData.PRI_KEY_COLUMN)) .booleanValue(); } // If current column is deleted from PK, remove it from PK if (table.getPrimaryKey() != null && !isPK) { table.getPrimaryKey().getMembers().remove(asaRow.getColumn()); } } return true; }
From source file:org.eclipse.datatools.sqltools.plan.internal.ui.actions.SavePlanAction.java
License:Open Source License
/** * If the file exists then popup a dialog to promte overwrite or not, if choose yes, then overwrite it, if choose * No,go back to the save dialog, if choose Cancel, close the dialog and do nothing. * //w w w. j a v a2 s .c o m * @param file * @param backInputDlg * @return the input file name */ private String checkFileExists(String file, boolean backInputDlg) { if (file == null) { return ""; } if (backInputDlg) { FileDialog dlg = new FileDialog(PlanViewPlugin.getActiveWorkbenchShell(), SWT.SAVE); // dlg.setFileName(file); String retFile = dlg.open(); if (retFile == null) { return ""; } return checkFileExists(retFile, false); } File f = new File(file); if (f.exists()) { String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL, IDialogConstants.get().CANCEL_LABEL }; String question = NLS.bind(Messages.SavePlanAction_overwrite_q, (new Object[] { file })); // pop up a new dialog to promote overwrite or not MessageDialog d = new MessageDialog(PlanViewPlugin.getActiveWorkbenchWindow().getShell(), Messages.SavePlanAction_question, null, question, MessageDialog.QUESTION, buttons, 0); switch (d.open()) { case 0: // Yes return file; case 1: // No // return to input file dialog return checkFileExists(file, true); case 2: // Cancel return ""; default: return ""; } } return file; }
From source file:org.eclipse.datatools.sqltools.result.internal.ui.actions.SaveResultInstanceAction.java
License:Open Source License
public void run() { IStructuredSelection selection = (IStructuredSelection) _provider.getSelection(); Object[] obj = selection.toArray(); if (obj == null || obj.length == 0 || obj.length > 1) { // should not happen return;//from w w w. j a va 2s . c o m } IResultInstance instance = (IResultInstance) obj[0]; FileDialog dialog = new FileDialog(_shell, SWT.SAVE); dialog.setText(Messages.SaveResultInstanceAction_save_hisotry_title); String filename = ""; //$NON-NLS-1$ boolean selectAgain = false; do { filename = dialog.open(); if (filename == null) { return; } File file = new File(filename); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL, IDialogConstants.get().CANCEL_LABEL }; String question = NLS.bind(Messages.ResultExportWizard_overwrite, new Object[] { filename }); MessageDialog d = new MessageDialog(_shell, Messages.ResultExportWizard_question, null, question, MessageDialog.QUESTION, buttons, 0); int overwrite = d.open(); switch (overwrite) { case 0: // Yes selectAgain = false; break; case 1: // No selectAgain = true; break; case 2: // Cancel default: return; } } } while (selectAgain); try { FileOutputStream fos = new FileOutputStream(new File(filename)); PrintWriter w = new PrintWriter(new BufferedWriter((new OutputStreamWriter(fos, "UTF-8")))); printResultInstance(w, instance, "", true); w.close(); } catch (IOException ex) { _log.error("SaveResultInstanceAction_cant_export_result_log", ex); //$NON-NLS-1$ ErrorDialog.openError(_shell, Messages.SaveResultInstanceAction_save_error, Messages.SaveResultInstanceAction_can_not_save, new Status(IStatus.ERROR, ResultsViewUIPlugin.PLUGIN_ID, 0, ex.getMessage(), ex)); } }
From source file:org.eclipse.datatools.sqltools.result.internal.ui.export.ResultExportWizard.java
License:Open Source License
public boolean performFinish() { final String pathName = _formatPage.getFileName(); if (pathName == null || pathName.length() < 1) { return false; }// w ww . j a v a 2 s . c o m //The user may not have made this absolute so do it for them IPath path = (new Path(pathName)).makeAbsolute(); if (path.toFile().exists()) { String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL, IDialogConstants.get().CANCEL_LABEL }; String question = NLS.bind(Messages.ResultExportWizard_overwrite, new Object[] { path.toOSString() }); MessageDialog d = new MessageDialog(getShell(), Messages.ResultExportWizard_question, null, question, MessageDialog.QUESTION, buttons, 0); int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return false; case 2: // Cancel default: return false; } } try { final Properties options = new Properties(); final AbstractOutputter outputter = _formatPage.getOutputterDesp().getOutputter(); if (_formatPage.getDelimiter().equals(OutputterConstants.USER_DEFINED)) { options.setProperty(IResultConstants.USERDEFINED_DELIMITER, _formatPage.getUserDefinedDelimiter()); } options.setProperty(IResultConstants.DELIMITER, _formatPage.getDelimiter()); options.setProperty(IResultConstants.ENCODING, _formatPage.getEncoding()); if (_resultObject != null) { Runnable exportRunnable = new Runnable() { public void run() { try { outputter.output(_resultObject, options, pathName); } catch (final Exception e) { Display display = getContainer() != null ? getContainer().getShell().getDisplay() : ResultsViewUIPlugin.getDefault().getWorkbench().getDisplay(); display.syncExec(new Runnable() { public void run() { ErrorDialog.openError(getShell(), Messages.ResultExportWizard_export_error, Messages.ResultExportWizard_failed_to_export_result_set, new Status(IStatus.ERROR, ResultsViewUIPlugin.PLUGIN_ID, 0, e.getMessage(), e)); } }); } } }; Thread exportThread = new Thread(exportRunnable); exportThread.start(); } if (_instance != null) { Runnable exportRunnable = new Runnable() { public void run() { try { outputter.output(_instance, options, pathName); } catch (final Exception e) { Display display = getContainer() != null ? getContainer().getShell().getDisplay() : ResultsViewUIPlugin.getDefault().getWorkbench().getDisplay(); display.syncExec(new Runnable() { public void run() { ErrorDialog.openError(getShell(), Messages.ResultExportWizard_export_error, Messages.ResultExportWizard_failed_to_export_result_set, new Status(IStatus.ERROR, ResultsViewUIPlugin.PLUGIN_ID, 0, e.getMessage(), e)); } }); } } }; Thread exportThread = new Thread(exportRunnable); exportThread.start(); } return true; } catch (Exception ex) { ErrorDialog.openError(getShell(), Messages.ResultExportWizard_export_error, Messages.ResultExportWizard_failed_to_export_result_set, new Status(IStatus.ERROR, ResultsViewUIPlugin.PLUGIN_ID, 0, ex.getMessage(), ex)); return false; } }
From source file:org.eclipse.datatools.sqltools.result.internal.ui.export.SaveResultSetDialog.java
License:Open Source License
protected void okPressed() { String filename = _resourceGroup.getResource(); IOutputterDescriptor descriptor = _resourceGroup.getOutputterDesp(); IPath path = _resourceGroup.getContainerFullPath().append(filename); /**// w w w . j av a 2 s . c o m * If the user does not supply a file extension, add a file extension based on the format */ if (path.getFileExtension() == null) { if (filename != null) { int pos = filename.lastIndexOf('.'); if (pos < 0) { filename = filename + "." + descriptor.getFileExtension(); path = path.addFileExtension(descriptor.getFileExtension()); } } } // If the path already exists then confirm overwrite. IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.get().YES_LABEL, IDialogConstants.get().NO_LABEL, IDialogConstants.get().CANCEL_LABEL }; String question = NLS.bind(Messages.SaveResultSetDialog_overwrite, new Object[] { path.toOSString() }); MessageDialog d = new MessageDialog(getShell(), Messages.SaveResultSetDialog_question, null, question, MessageDialog.QUESTION, buttons, 0); int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return; case 2: // Cancel default: cancelPressed(); return; } } // Store path and close. _result = path; try { Properties options = new Properties(); String resource = _resourceGroup.getContainerFullPath().toString(); if (ResourcesPlugin.getWorkspace().getRoot().findMember(resource) != null) { String fullpath = ResourcesPlugin.getWorkspace().getRoot().findMember(resource).getLocation() .toOSString() + File.separator + filename; AbstractOutputter outputter = descriptor.getOutputter(); if (_resourceGroup.getDelimiter().equals(OutputterConstants.USER_DEFINED)) { options.setProperty(IResultConstants.USERDEFINED_DELIMITER, _resourceGroup.getUserDefinedDelimiter()); } options.setProperty(IResultConstants.DELIMITER, _resourceGroup.getDelimiter()); options.setProperty(IResultConstants.ENCODING, _resourceGroup.getEncoding()); if (_resultset != null) { outputter.output(_resultset, options, fullpath); } if (_resultInstance != null) { outputter.output(_resultInstance, options, fullpath); } try { if (file != null && file.getProject() != null) { file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); // set the correct charset for this file file.setCharset(_resourceGroup.getEncoding(), new NullProgressMonitor()); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); // IDE.openEditor(page, file, true); } } catch (CoreException e) { _log.error("common_error", e); //$NON-NLS-1$ } } } catch (IOException ex) { ErrorDialog.openError(getShell(), Messages.ResultExportWizard_export_error, Messages.ResultExportWizard_failed_to_export_result_set, new Status(IStatus.ERROR, ResultsViewUIPlugin.getPluginId(), 0, ex.getMessage(), ex)); } close(); }
From source file:org.eclipse.datatools.sqltools.schemaobjecteditor.ui.action.RefreshSchemaEditorAction.java
License:Open Source License
public void run() { if (_editor == null) { return;/*from w w w . j a v a 2 s. c o m*/ } if (_editor.isDirty()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; MessageDialog d = new MessageDialog(SOEUIPlugin.getActiveWorkbenchShell(), Messages.RefreshSchemaEditorAction_referesh_editor, null, Messages.RefreshSchemaEditorAction_question, MessageDialog.QUESTION, buttons, 0); int result = d.open(); switch (result) { case IDialogConstants.CANCEL_ID: return; default: break; } } ISchemaObjectEditorHandler handler = _editor.getEditorHandler(); RefreshSchemaEditorJob refreshJob = new RefreshSchemaEditorJob( Messages.RefreshSchemaEditorAction_refresh_job, handler); refreshJob.setUser(true); refreshJob.schedule(); }
From source file:org.eclipse.datatools.sqltools.schemaobjecteditor.ui.core.DefaultSchemaObjectEditorHandler.java
License:Open Source License
/** * If the model object is lost, prompt the user to save the DDL, and close the editor. *//*w ww . java2 s. co m*/ private void promptSaveAndCloseEditor() { MessageDialog dialog = new MessageDialog(SOEUIPlugin.getActiveWorkbenchShell(), Messages.MainSQLObjectLostPromoptSavingTitle, null, Messages.MainSQLObjectLostPromoptSavingMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); if (dialog.open() == IDialogConstants.OK_ID) { ISchemaObjectEditModel schemaObjectEditModel = getEditorInput().getEditModelObject(); String ddl = null; if (schemaObjectEditModel instanceof AbstractSchemaObjectEditModel) { ddl = ((AbstractSchemaObjectEditModel) schemaObjectEditModel).getBackupedDDL(); } final SaveAsDialog dia = new SaveAsDialog(SOEUIPlugin.getActiveWorkbenchShell(), ddl); dia.setOriginalName(_editor.getDisplayName() + "_ddl.sql"); dia.setOpenMode(getOpenFileAfterSaveasOption()); dia.open(); IEditorPart editor = dia.getEditor(); if (editor != null && (editor instanceof SQLEditor)) { ISchemaObjectEditorInput input = (ISchemaObjectEditorInput) _editor.getEditorInput(); DatabaseIdentifier databaseIdentifier = input.getDatabaseIdentifier(); ISQLEditorConnectionInfo connInfo = new SQLEditorConnectionInfo( SQLToolsFacade.getConfigurationByProfileName(databaseIdentifier.getProfileName()) .getDatabaseVendorDefinitionId(), databaseIdentifier.getProfileName(), databaseIdentifier.getDBname(), databaseIdentifier.getDBname()); ((SQLEditor) editor).setConnectionInfo(connInfo); } } final IWorkbenchPage workPage = SOEUIPlugin.getActiveWorkbenchPage(); workPage.closeEditor((IEditorPart) _editor, false); }
From source file:org.eclipse.datatools.sqltools.schemaobjecteditor.ui.core.DefaultSchemaObjectEditorHandler.java
License:Open Source License
/** * Do check based on the parameter doCheck. * /*from w w w . ja v a 2 s . c o m*/ * @param doCheck * @return * @author sul */ public boolean checkSchemaObjectExistence(boolean doCheck) { if (!doCheck) { return true; } ISchemaObjectEditModel editModel = getEditorInput().getEditModelObject(); if (!editModel.checkModelExistence()) { promptObjectLost(editModel); MessageDialog dialog = new MessageDialog(SOEUIPlugin.getActiveWorkbenchShell(), Messages.MainSQLObjectLostPromoptSavingTitle, null, Messages.MainSQLObjectLostPromoptSavingMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); ISchemaObjectEditModel schemaObjectEditModel = getEditorInput().getEditModelObject(); String ddl = null; if (schemaObjectEditModel instanceof AbstractSchemaObjectEditModel) { ddl = ((AbstractSchemaObjectEditModel) schemaObjectEditModel).getBackupedDDL(); } // if ddl is not null, prompt to save it. if (ddl != null && dialog.open() == IDialogConstants.OK_ID) { final SaveAsDialog dia = new SaveAsDialog(SOEUIPlugin.getActiveWorkbenchShell(), ddl); dia.setOriginalName(_editor.getDisplayName() + "_ddl.sql"); dia.setOpenMode(getOpenFileAfterSaveasOption()); // SOEUIPlugin.getActiveWorkbenchShell().getDisplay().asyncExec(new Runnable() { public void run() { dia.open(); IEditorPart editor = dia.getEditor(); if (editor != null && (editor instanceof SQLEditor)) { ISchemaObjectEditorInput input = (ISchemaObjectEditorInput) _editor.getEditorInput(); DatabaseIdentifier databaseIdentifier = input.getDatabaseIdentifier(); ISQLEditorConnectionInfo connInfo = new SQLEditorConnectionInfo( SQLToolsFacade .getConfigurationByProfileName(databaseIdentifier.getProfileName()) .getDatabaseVendorDefinitionId(), databaseIdentifier.getProfileName(), databaseIdentifier.getDBname(), databaseIdentifier.getDBname()); ((SQLEditor) editor).setConnectionInfo(connInfo); } } }); } final IWorkbenchPage workPage = SOEUIPlugin.getActiveWorkbenchPage(); SOEUIPlugin.getActiveWorkbenchShell().getDisplay().asyncExec(new Runnable() { public void run() { workPage.closeEditor((IEditorPart) _editor, false); } }); return false; } return true; }
From source file:org.eclipse.datatools.sqltools.schemaobjecteditor.ui.internal.preference.SchemaObjectEditorPreferencePage.java
License:Open Source License
protected Control createContents(Composite parent) { _parent = parent;/* www . ja v a 2 s . c o m*/ GridLayout layout = new GridLayout(); parent.setLayout(layout); Composite container = new Composite(parent, SWT.NONE); layout = new GridLayout(); container.setLayout(layout); GridData gd = new GridData(GridData.FILL_BOTH); container.setLayoutData(gd); Group editorsComp = new Group(container, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); layout = new GridLayout(); layout.numColumns = 4; layout.makeColumnsEqualWidth = true; editorsComp.setLayout(layout); editorsComp.setText(Messages.SchemaObjectEditorPreferencePage_available_editors); editorsComp.setLayoutData(gd); Composite dbdefsComp = new Composite(editorsComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; dbdefsComp.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; dbdefsComp.setLayoutData(gd); Label dbTypeLabel = new Label(dbdefsComp, SWT.NONE); dbTypeLabel.setText(Messages.SchemaObjectEditorPreferencePage_databaseType); _dbType = new Combo(dbdefsComp, SWT.READ_ONLY); gd = new GridData(GridData.FILL_HORIZONTAL); gd.minimumWidth = 130; _dbType.setLayoutData(gd); Composite edComp = new Composite(editorsComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; edComp.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 2; edComp.setLayoutData(gd); Label editorTypeLabel = new Label(edComp, SWT.NONE); editorTypeLabel.setText(Messages.SchemaObjectEditorPreferencePage_editors); _editorName = new Combo(edComp, SWT.READ_ONLY); gd = new GridData(GridData.FILL_HORIZONTAL); gd.minimumWidth = 130; _editorName.setLayoutData(gd); Group pagesComp = new Group(container, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); layout = new GridLayout(); layout.numColumns = 3; pagesComp.setLayout(layout); pagesComp.setLayoutData(gd); pagesComp.setText(Messages.SchemaObjectEditorPreferencePage_pagesSetting); Composite selectedComposite = new Composite(pagesComp, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); selectedComposite.setLayoutData(gd); layout = new GridLayout(); selectedComposite.setLayout(layout); Label selectedPages = new Label(selectedComposite, SWT.NONE); selectedPages.setText(Messages.SchemaObjectEditorPreferencePage_selected_pages); gd = new GridData(); gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; selectedPages.setLayoutData(gd); _displayedPages = new List(selectedComposite, SWT.BORDER | SWT.MULTI); gd = new GridData(GridData.FILL_BOTH); _displayedPages.setLayoutData(gd); Composite buttonsComp = new Composite(pagesComp, SWT.NONE); gd = new GridData(GridData.FILL_VERTICAL); buttonsComp.setLayoutData(gd); layout = new GridLayout(); buttonsComp.setLayout(layout); GC gc = new GC(buttonsComp); int maxAddRemoveButtonsWidth = computeMaxAddRemoveButtonsWidth(gc); gc.dispose(); new Label(buttonsComp, SWT.NONE); _rightOne = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _rightOne.setLayoutData(gd); _rightOne.setText(Messages.SchemaObjectEditorPreferencePage_remove); _rightOne.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { String[] selectedItems = _displayedPages.getSelection(); boolean isSucceeded = false; int movedNum = 0; for (int i = 0; i < selectedItems.length; i++) { String name = selectedItems[i]; Object data = _displayedPages.getData(name); IEditorPageDescriptor page = (IEditorPageDescriptor) data; if (page.isRequired()) { continue; } _hiddenPages.add(name); _hiddenPages.setData(name, data); _displayedPages.remove(name); isSucceeded = true; movedNum++; } setOrClearErrorMsg(); if (!isSucceeded) { String[] buttons = new String[] { IDialogConstants.OK_LABEL }; MessageDialog d = new MessageDialog(_parent.getShell(), Messages.SchemaObjectEditorPreferencePage_error, null, Messages.SchemaObjectEditorPreferencePage_can_not_remove, MessageDialog.ERROR, buttons, 0); d.open(); } else { _dirty = true; int[] indecies = new int[movedNum]; for (int i = 0; i < movedNum; i++) { indecies[i] = _hiddenPages.getItemCount() - 1 - i; } _hiddenPages.setSelection(indecies); } setButtonStatus(); } }); _rightAll = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _rightAll.setLayoutData(gd); _rightAll.setText(Messages.SchemaObjectEditorPreferencePage_remove_all); _rightAll.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { String[] selectedItems = _displayedPages.getItems(); boolean isSucceeded = false; for (int i = 0; i < selectedItems.length; i++) { String name = selectedItems[i]; Object data = _displayedPages.getData(name); IEditorPageDescriptor page = (IEditorPageDescriptor) data; if (page.isRequired()) { continue; } _hiddenPages.add(name); _hiddenPages.setData(name, data); _displayedPages.remove(name); isSucceeded = true; } setOrClearErrorMsg(); setButtonStatus(); if (!isSucceeded) { String[] buttons = new String[] { IDialogConstants.OK_LABEL }; MessageDialog d = new MessageDialog(_parent.getShell(), Messages.SchemaObjectEditorPreferencePage_erroe, null, Messages.SchemaObjectEditorPreferencePage_can_not_remove, MessageDialog.ERROR, buttons, 0); d.open(); } else { _dirty = true; } } }); _leftOne = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _leftOne.setLayoutData(gd); _leftOne.setText(Messages.SchemaObjectEditorPreferencePage_add); _leftOne.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { String[] selectedItems = _hiddenPages.getSelection(); int movedNum = 0; for (int i = 0; i < selectedItems.length; i++) { String name = selectedItems[i]; Object data = _hiddenPages.getData(name); IEditorDescriptor editor = (IEditorDescriptor) _editorName.getData(_editorName.getText()); IEditorPageDescriptor page = (IEditorPageDescriptor) data; boolean isPageMandatoryFirstOne = editor.getMandatoryFirstPage() != null && editor.getMandatoryFirstPage().getPageId().equals(page.getPageId()); boolean isPageMandatoryLastOne = editor.getMandatoryLastPage() != null && editor.getMandatoryLastPage().getPageId().equals(page.getPageId()); if (isPageMandatoryFirstOne) { _displayedPages.add(name, 0); _displayedPages.setData(name, data); } else if (isPageMandatoryLastOne) { _displayedPages.add(name, _displayedPages.getItemCount()); _displayedPages.setData(name, data); } else { // Check if the last visible page is a mandatory page if (_displayedPages.getItemCount() > 0) { String displayedLastOne = _displayedPages.getItem(_displayedPages.getItemCount() - 1); IEditorPageDescriptor displayedLast = (IEditorPageDescriptor) _displayedPages .getData(displayedLastOne); boolean isLastPageMandatory = editor.getMandatoryLastPage() != null && editor.getMandatoryLastPage().getPageId().equals(displayedLast.getPageId()); if (isLastPageMandatory) { _displayedPages.add(name, _displayedPages.getItemCount() - 1); _displayedPages.setData(name, data); } else { _displayedPages.add(name); _displayedPages.setData(name, data); } } else { _displayedPages.add(name); _displayedPages.setData(name, data); } } _hiddenPages.remove(name); movedNum++; } setOrClearErrorMsg(); if (movedNum > 0) { _dirty = true; } int[] indecies = new int[movedNum]; for (int i = 0; i < movedNum; i++) { indecies[i] = _displayedPages.getItemCount() - 1 - i; } _displayedPages.setSelection(indecies); setButtonStatus(); } }); _leftAll = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _leftAll.setLayoutData(gd); _leftAll.setText(Messages.SchemaObjectEditorPreferencePage_add_all); _leftAll.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { String[] selectedItems = _hiddenPages.getItems(); for (int i = 0; i < selectedItems.length; i++) { _dirty = true; String name = selectedItems[i]; Object data = _hiddenPages.getData(name); IEditorDescriptor editor = (IEditorDescriptor) _editorName.getData(_editorName.getText()); IEditorPageDescriptor page = (IEditorPageDescriptor) data; boolean isPageMandatoryFirstOne = editor.getMandatoryFirstPage() != null && editor.getMandatoryFirstPage().getPageId().equals(page.getPageId()); boolean isPageMandatoryLastOne = editor.getMandatoryLastPage() != null && editor.getMandatoryLastPage().getPageId().equals(page.getPageId()); if (isPageMandatoryFirstOne) { _displayedPages.add(name, 0); _displayedPages.setData(name, data); } else if (isPageMandatoryLastOne) { _displayedPages.add(name, _displayedPages.getItemCount()); _displayedPages.setData(name, data); } else { // Check if the last visible page is a mandatory page if (_displayedPages.getItemCount() > 0) { String displayedLastOne = _displayedPages.getItem(_displayedPages.getItemCount() - 1); IEditorPageDescriptor displayedLast = (IEditorPageDescriptor) _displayedPages .getData(displayedLastOne); boolean isLastPageMandatory = editor.getMandatoryLastPage() != null && editor.getMandatoryLastPage().getPageId().equals(displayedLast.getPageId()); if (isLastPageMandatory) { _displayedPages.add(name, _displayedPages.getItemCount() - 1); _displayedPages.setData(name, data); } else { _displayedPages.add(name); _displayedPages.setData(name, data); } } else { _displayedPages.add(name); _displayedPages.setData(name, data); } } _hiddenPages.remove(name); } setOrClearErrorMsg(); setButtonStatus(); } }); _upMove = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _upMove.setLayoutData(gd); _upMove.setText(Messages.SchemaObjectEditorPreferencePage_move_up); _upMove.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { moveItem(_displayedPages, true); } }); _downMove = new Button(buttonsComp, SWT.NONE | SWT.LEFT); gd = new GridData(); gd.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER; gd.widthHint = maxAddRemoveButtonsWidth; _downMove.setLayoutData(gd); _downMove.setText(Messages.SchemaObjectEditorPreferencePage_move_down); _downMove.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { moveItem(_displayedPages, false); } }); Composite availableComp = new Composite(pagesComp, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); availableComp.setLayoutData(gd); layout = new GridLayout(); availableComp.setLayout(layout); Label availablePages = new Label(availableComp, SWT.NONE); availablePages.setText(Messages.SchemaObjectEditorPreferencePage_available_pages); gd = new GridData(); gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; availablePages.setLayoutData(gd); _hiddenPages = new List(availableComp, SWT.BORDER | SWT.MULTI); gd = new GridData(GridData.FILL_BOTH); _hiddenPages.setLayoutData(gd); final Map editorsMap = SchemaObjectEditorUtils.getEditorsCatalogedByDBDefinition(); // Sort the dbdefinitions java.util.List keys = new ArrayList(); Iterator iter = editorsMap.keySet().iterator(); while (iter.hasNext()) { String dbdefi = (String) iter.next(); keys.add(dbdefi); } Collections.sort(keys); iter = keys.iterator(); while (iter.hasNext()) { String dbdefi = (String) iter.next(); _dbType.add(dbdefi); } _dbType.setFocus(); _dbType.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { String dbdefi = _dbType.getText(); if (dbdefi != null && dbdefi.trim().length() != 0) { _editorName.removeAll(); java.util.List editors = (java.util.List) editorsMap.get(dbdefi); if (editors != null) { Collections.sort(editors, new EditorComparator()); Iterator iter = editors.iterator(); while (iter.hasNext()) { IEditorDescriptor editor = (IEditorDescriptor) iter.next(); _editorName.add(editor.getEditorName()); _editorName.setData(editor.getEditorName(), editor); } } if (_editorName.getItemCount() > 0) { _editorName.select(0); _editorName.notifyListeners(SWT.Selection, new Event()); } } } }); _editorName.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { String name = _editorName.getText(); if (_dirty && isValid()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; MessageDialog d = new MessageDialog(_parent.getShell(), Messages.SchemaObjectEditorPreferencePage_question, null, Messages.SchemaObjectEditorPreferencePage_save_modification, MessageDialog.QUESTION, buttons, 0); int result = d.open(); switch (result) { case 0: savePreferences(); break; case 1: break; default: break; } } _dirty = false; if (name != null && name.trim().length() != 0) { _displayedPages.removeAll(); _hiddenPages.removeAll(); IEditorDescriptor editor = (IEditorDescriptor) _editorName.getData(name); if (editor != null) { IEditorPageDescriptor[] pages = editor.getPageDescriptors(); for (int i = 0; i < pages.length; i++) { if (!_store.getBoolean(Constants.EDITOR_PAGE_VISIABILITY + pages[i].getEditorId() + pages[i].getPageId())) { _hiddenPages.add(pages[i].getPageName()); _hiddenPages.setData(pages[i].getPageName(), pages[i]); } } IEditorPageDescriptor[] sortedPages = editor.getSortedPages(); for (int j = 0; j < sortedPages.length; j++) { if (sortedPages[j].isSelectedToShow()) { _displayedPages.add(sortedPages[j].getPageName()); _displayedPages.setData(sortedPages[j].getPageName(), sortedPages[j]); } } } setOrClearErrorMsg(); setButtonStatus(); } } }); String preDBdef = _store.getString(Constants.PREFERENCE_PREVIOUS_DB_DEFINITION); String preEditor = _store.getString(Constants.PREFERENCE_PREVIOUS_EDIOR_NAME); if (preDBdef != null) { int index = _dbType.indexOf(preDBdef); if (index != -1) { _dbType.select(index); _dbType.notifyListeners(SWT.Selection, new Event()); } } if (preEditor != null) { int index = _editorName.indexOf(preEditor); if (index != -1) { _editorName.select(index); _editorName.notifyListeners(SWT.Selection, new Event()); } } _displayedPages.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { setButtonStatus(); } }); _hiddenPages.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { setButtonStatus(); } }); setButtonStatus(); _alwaysShowPreview = new Button(container, SWT.CHECK); _alwaysShowPreview.setText(Messages.SchemaObjectEditorPreferencePage_always_show_preview); _alwaysShowPreview.setSelection(_store.getBoolean(Constants.PREFERENCE_ALWAYS_SHOW_PREVIEW)); _promptIfNoExactEditorFound = new Button(container, SWT.CHECK); _promptIfNoExactEditorFound.setText(Messages.SchemaObjectEditorPreferencePage_use_latest_version_to_open); _promptIfNoExactEditorFound .setToolTipText(Messages.SchemaObjectEditorPreferencePage_latest_version_open_tooltip); _promptIfNoExactEditorFound.setSelection(_store.getBoolean(Constants.PREFERENCE_USE_LATEST_VERSION)); // add by sul - CR470356-2 _checkWhenActivated = new Button(container, SWT.CHECK); _checkWhenActivated.setText(Messages.SchemaObjectEditorPreferencePage_check_existence_when_activated); _checkWhenActivated.setSelection(_store.getBoolean(Constants.PREFERENCE_CHECK_EXISTENCE)); _checkWhenActivated .setToolTipText(Messages.SchemaObjectEditorPreferencePage_check_existence_when_activated_tooltip); // add end // add by sul - CR497357-1 _openFileAfterSaveas = new Button(container, SWT.CHECK); _openFileAfterSaveas.setText(Messages.SchemaObjectEditorPreferencePage_open_file_after_saveas); _openFileAfterSaveas.setSelection(_store.getBoolean(Constants.PREFERENCE_OPEN_FILE_AFTER_SAVEAS)); _openFileAfterSaveas .setToolTipText(Messages.SchemaObjectEditorPreferencePage_open_file_after_saveas_tooltip); // add end return container; }
From source file:org.eclipse.datatools.sqltools.schemaobjecteditor.ui.internal.ui.SaveAsDialog.java
License:Open Source License
protected void okPressed() { String filename = _resourceGroup.getResource(); IPath path = _resourceGroup.getContainerFullPath().append(filename); // If the path already exists then confirm overwrite. IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; String question = NLS.bind(Messages.SaveAsDialog_overwrite, new Object[] { path.toOSString() }); MessageDialog d = new MessageDialog(getShell(), Messages.SaveAsDialog_question, null, question, MessageDialog.QUESTION, buttons, 0); int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return; case 2: // Cancel default:/* w w w. j av a 2 s . c o m*/ cancelPressed(); return; } } // Store path and close. _result = path; try { String resource = _resourceGroup.getContainerFullPath().toString(); if (ResourcesPlugin.getWorkspace().getRoot().findMember(resource) != null) { String fullpath = ResourcesPlugin.getWorkspace().getRoot().findMember(resource).getLocation() .toOSString() + File.separator + filename; PrintWriter output = new PrintWriter( new OutputStreamWriter(new FileOutputStream(fullpath), ENCODING)); //$NON-NLS-1$ if (_content != null) { output.write(_content); } if (output != null) { output.close(); } try { if (file != null && file.getProject() != null) { file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); // set the correct charset for this file file.setCharset(ENCODING, new NullProgressMonitor()); //$NON-NLS-1$ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IDE.openEditor(page, file, true); } } catch (CoreException e) { _log.error("SaveAsDialog_open_error", e); //$NON-NLS-1$ } } } catch (IOException ex) { ErrorDialog.openError(getShell(), Messages.SaveAsDialog_error, Messages.SaveAsDialog_error_msg, new Status(IStatus.ERROR, SOEUIPlugin.PLUGIN_ID, 0, ex.getMessage(), ex)); } close(); }