List of usage examples for org.eclipse.jface.dialogs MessageDialog openQuestion
public static boolean openQuestion(Shell parent, String title, String message)
From source file:com.aptana.webserver.ui.preferences.ServersPreferencePage.java
License:Open Source License
@Override protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setFont(parent.getFont()); composite.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create()); viewer = new ListViewer(composite, SWT.SINGLE | SWT.BORDER); viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); viewer.setContentProvider(new ArrayContentProvider() { @Override// w ww. j av a 2s . com public Object[] getElements(Object inputElement) { if (inputElement instanceof IServerManager) { inputElement = ((IServerManager) inputElement).getServers(); // $codepro.audit.disable // questionableAssignment } return super.getElements(inputElement); } }); viewer.setLabelProvider(new LabelProvider() { @Override public Image getImage(Object element) { return null; // TODO: use ImageAssociations } @Override public String getText(Object element) { if (element instanceof IServer) { return ((IServer) element).getName(); } return super.getText(element); } }); viewer.setInput(WebServerCorePlugin.getDefault().getServerManager()); Composite buttonContainer = new Composite(composite, SWT.NONE); buttonContainer.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create()); buttonContainer.setLayout(GridLayoutFactory.swtDefaults().create()); Button newButton = new Button(buttonContainer, SWT.PUSH); newButton.setText(StringUtil.ellipsify(CoreStrings.NEW)); newButton .setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER) .hint(Math.max(newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH)), SWT.DEFAULT) .create()); final Button editButton = new Button(buttonContainer, SWT.PUSH); editButton.setText(StringUtil.ellipsify(CoreStrings.EDIT)); editButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).create()); final Button deleteButton = new Button(buttonContainer, SWT.PUSH); deleteButton.setText(CoreStrings.DELETE); deleteButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).create()); newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { ListDialog dlg = new ListDialog(getShell()); dlg.setContentProvider(ArrayContentProvider.getInstance()); dlg.setLabelProvider(new LabelProvider() { @Override public Image getImage(Object element) { return null; // TODO: use ImageAssociations } @Override public String getText(Object element) { if (element instanceof IServerType) { return ((IServerType) element).getName(); } return super.getText(element); } }); dlg.setInput(WebServerCorePlugin.getDefault().getServerManager().getServerTypes()); dlg.setTitle(Messages.ServersPreferencePage_Title); Object[] result; if (dlg.open() == Window.OK && (result = dlg.getResult()) != null && result.length == 1) { // $codepro.audit.disable assignmentInCondition String typeId = ((IServerType) result[0]).getId(); try { IServer newConfiguration = WebServerCorePlugin.getDefault().getServerManager() .createServer(typeId); if (newConfiguration != null) { if (editServerConfiguration(newConfiguration)) { WebServerCorePlugin.getDefault().getServerManager().add(newConfiguration); viewer.refresh(); } } } catch (CoreException e) { IdeLog.logError(WebServerUIPlugin.getDefault(), e); } } } }); editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IServer selection = (IServer) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection != null && editServerConfiguration(selection)) { viewer.refresh(); } } }); deleteButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IServer selection = (IServer) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection != null && MessageDialog.openQuestion(getShell(), Messages.ServersPreferencePage_DeletePrompt_Title, Messages.ServersPreferencePage_DeletePrompt_Message)) { WebServerCorePlugin.getDefault().getServerManager().remove(selection); viewer.refresh(); } } }); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IServer selection = (IServer) ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection != null && editServerConfiguration(selection)) { viewer.refresh(); } } }); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { boolean hasSelection = !event.getSelection().isEmpty(); editButton.setEnabled(hasSelection); deleteButton.setEnabled(hasSelection); } }); viewer.setSelection(StructuredSelection.EMPTY); return composite; }
From source file:com.arc.cdt.debug.seecode.ui.display.CustomDisplayCallback.java
License:Open Source License
@Override protected boolean showConfirmDialog(String msg) { return MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Confirm", msg); }
From source file:com.archimatetool.canvas.templates.wizard.SaveCanvasAsTemplateWizard.java
License:Open Source License
@Override public boolean performFinish() { // This before the thread starts fZipFile = new File(fPage1.getFileName()); // Make sure the file does not already exist if (fZipFile.exists()) { boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.SaveCanvasAsTemplateWizard_1, NLS.bind(Messages.SaveCanvasAsTemplateWizard_2, fZipFile)); if (!result) { return false; }// ww w .j a v a 2 s.co m } fTemplateName = fPage1.getTemplateName(); fTemplateDescription = fPage1.getTemplateDescription(); fIncludeThumbnail = fPage1.includeThumbnail(); fDoStoreInCollection = fPage2.doStoreInCollection(); fSelectedTemplateGroup = fPage2.getTemplateGroup(); BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { @Override public void run() { try { createZipFile(fZipFile); if (fDoStoreInCollection) { fTemplateManager.addTemplateEntry(fZipFile, fSelectedTemplateGroup); } } catch (final IOException ex) { ex.printStackTrace(); Display.getCurrent().asyncExec(new Runnable() { // Display after wizard closes public void run() { MessageDialog.openError(getShell(), Messages.SaveCanvasAsTemplateWizard_3, ex.getMessage()); } }); } } }); return true; }
From source file:com.archimatetool.csv.CSVExporter.java
License:Open Source License
/** * Ask user for file name to save to/*from ww w . j av a 2s .c o m*/ */ private File askSaveFile() { FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE); dialog.setText(Messages.CSVExporter_1); dialog.setFilterExtensions(new String[] { "*.csv", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ String path = dialog.open(); if (path == null) { return null; } // Only Windows adds the extension by default if (dialog.getFilterIndex() == 0 && !path.endsWith(".csv")) { //$NON-NLS-1$ path += ".csv"; //$NON-NLS-1$ } File file = new File(path); // Make sure the file does not already exist if (file.exists()) { boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.CSVExporter_1, NLS.bind(Messages.CSVExporter_2, file)); if (!result) { return null; } } return file; }
From source file:com.archimatetool.csv.export.ExportAsCSVWizard.java
License:Open Source License
@Override public boolean performFinish() { String folderPath = fPage.getExportFolderPath(); if (folderPath == null) { return false; }//from ww w. jav a2 s. c o m // Set file prefix fExporter.setFilePrefix(fPage.getFilenamePrefix()); // Set delimiter fExporter.setDelimiter(DELIMITERS[fPage.getDelimiterIndex()]); // Strip newlines fExporter.setStripNewLines(fPage.getStripNewlines()); // Leading chars hack fExporter.setUseLeadingCharsHack(fPage.getUseLeadingCharsHack()); File folder = new File(folderPath); // Make folder folder.mkdirs(); // Make sure the elements file does not already exist File elementsFile = new File(folder, fExporter.createElementsFileName()); if (elementsFile.exists()) { boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.ExportAsCSVWizard_1, Messages.ExportAsCSVWizard_2); if (!result) { return false; } } // Store Preferences fPage.storePreferences(); // Export try { fExporter.export(folder); } catch (IOException ex) { ex.printStackTrace(); MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.ExportAsCSVWizard_3, Messages.ExportAsCSVWizard_4 + " " + ex.getMessage()); //$NON-NLS-1$ return false; } return true; }
From source file:com.archimatetool.editor.actions.CheckForNewVersionAction.java
License:Open Source License
@Override public void run() { try {/*from ww w.j ava2 s.c o m*/ URL url = new URL(versionFile); String newVersion = getOnlineVersion(url); // Get this app's main version number String thisVersion = System.getProperty(Application.APPLICATION_VERSIONID); if (StringUtils.compareVersionNumbers(newVersion, thisVersion) > 0) { boolean reply = MessageDialog.openQuestion(null, Messages.CheckForNewVersionAction_1, Messages.CheckForNewVersionAction_2 + " (" + newVersion + "). " + //$NON-NLS-1$ //$NON-NLS-2$ Messages.CheckForNewVersionAction_3); if (reply) { IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); IWebBrowser browser = support.getExternalBrowser(); if (browser != null) { URL url2 = new URL(downloadPage); browser.openURL(url2); } } } else { MessageDialog.openInformation(null, Messages.CheckForNewVersionAction_1, Messages.CheckForNewVersionAction_4); } } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); showErrorMessage(Messages.CheckForNewVersionAction_5); return; } catch (PartInitException ex) { ex.printStackTrace(); } }
From source file:com.archimatetool.editor.actions.InstallPluginAction.java
License:Open Source License
@Override public void run() { File file = askOpenFile();/*from w w w. j av a 2 s. co m*/ if (file == null) { return; } try { // Not an Archi plug-in zip file if (!PluginInstaller.isPluginZipFile(file)) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.InstallPluginAction_0, Messages.InstallPluginAction_1); return; } // Unpack zip to install folder PluginInstaller.unpackZipPackageToInstallFolder(file); } catch (IOException ex) { ex.printStackTrace(); MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.InstallPluginAction_2, ex.getMessage()); } // Restart now? boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.InstallPluginAction_0, Messages.InstallPluginAction_3); if (result) { PlatformUI.getWorkbench().restart(); } }
From source file:com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand.java
License:Open Source License
boolean checkToReuseExistingRelationship() { EClass classType = (EClass) fRequest.getNewObjectType(); if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) { IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource; IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget; // If there is already a relation of this type in the model... IArchimateRelationship relation = getExistingRelationshipOfType(classType, source.getArchimateConcept(), target.getArchimateConcept()); if (relation != null) { // ...then ask the user if they want to re-use it boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.CreateArchimateConnectionWithDialogCommand_0, NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target))); // Yes... if (answer) { // ...set connection's relationship to the existing relation fConnection = createNewConnection(); ((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(relation); return true; }//from w w w. ja v a 2 s. c om } } return false; }
From source file:com.archimatetool.editor.diagram.wizard.ExportAsImageWizard.java
License:Open Source License
@Override public boolean performFinish() { final ImageExportProviderInfo provider = fPage.getSelectedProvider(); if (provider == null) { return false; }// w w w .ja va2 s . co m final File file = new File(fPage.getFileName()); // Check valid file name try { file.getCanonicalPath(); } catch (IOException ex) { MessageDialog.openError(getShell(), Messages.ExportAsImageWizard_1, Messages.ExportAsImageWizard_2); return false; } // Make sure the file does not already exist if (file.exists()) { boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.ExportAsImageWizard_3, NLS.bind(Messages.ExportAsImageWizard_4, file)); if (!result) { return false; } } BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { @Override public void run() { try { provider.getProvider().export(provider.getID(), file); fPage.storePreferences(); } catch (Throwable ex) { ex.printStackTrace(); MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.ExportAsImageWizard_5, Messages.ExportAsImageWizard_6 + " " + ex.getMessage()); //$NON-NLS-1$ } } }); return true; }
From source file:com.archimatetool.editor.model.impl.EditorModelManager.java
License:Open Source License
@Override public IArchimateModel loadModel(File file) { if (file == null || !file.exists()) { return null; }/*from w w w.j ava 2 s.c o m*/ // If it is already loaded return it IArchimateModel model = locateLoadedModel(file); if (model != null) { return model; } // Ascertain if this is an archive file boolean useArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file); // Create the Resource Resource resource = ArchimateResourceFactory .createNewResource(useArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath())); // Check model compatibility ModelCompatibility modelCompatibility = new ModelCompatibility(resource); // Load the model file try { resource.load(null); } catch (IOException ex) { // Error occured loading model. try { modelCompatibility.checkErrors(); } catch (IncompatibleModelException ex1) { // Was it a disaster? MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_2, NLS.bind(Messages.EditorModelManager_3, file) + "\n" + ex1.getMessage()); //$NON-NLS-1$ return null; } } model = (IArchimateModel) resource.getContents().get(0); // Once loaded - check for later model version boolean isLaterModelVersion = modelCompatibility.isLaterModelVersion(ModelVersion.VERSION); if (isLaterModelVersion) { boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_4, NLS.bind(Messages.EditorModelManager_5, file, model.getVersion())); if (!answer) { return null; } } // Check for unknown model features which might be OK to load else { List<Diagnostic> exceptions = modelCompatibility.getAcceptableExceptions(); if (!exceptions.isEmpty()) { String message = ""; //$NON-NLS-1$ for (int i = 0; i < exceptions.size(); i++) { if (i == 3) { message += (exceptions.size() - 3) + " " + Messages.EditorModelManager_12; //$NON-NLS-1$ break; } message += exceptions.get(i).getMessage() + "\n"; //$NON-NLS-1$ } boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.EditorModelManager_4, NLS.bind(Messages.EditorModelManager_13, file) + "\n\n" + message); //$NON-NLS-1$ if (!answer) { return null; } } } // And then fix any backward compatibility issues try { modelCompatibility.fixCompatibility(); } catch (CompatibilityHandlerException ex) { } model.setFile(file); model.setDefaults(); getModels().add(model); model.eAdapters().add(new ECoreAdapter()); // New Command Stack createNewCommandStack(model); // New Archive Manager createNewArchiveManager(model); // Initiate all diagram models to be marked as "saved" - this is for the editor view persistence markDiagramModelsAsSaved(model); // This last firePropertyChange(this, PROPERTY_MODEL_LOADED, null, model); return model; }