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.team.ui.SaveablePartDialog.java
License:Open Source License
/** * Save any changes to the compare editor. *//*from w ww . ja v a2 s .co m*/ private void saveChanges() { MessageDialog dialog = new MessageDialog(getShell(), TeamUIMessages.ParticipantCompareDialog_2, null, TeamUIMessages.ParticipantCompareDialog_3, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0); // YES is the default if (input.isDirty() && dialog.open() == IDialogConstants.OK_ID) { BusyIndicator.showWhile(null, new Runnable() { public void run() { input.doSave(new NullProgressMonitor()); } }); } }
From source file:org.eclipse.team.ui.synchronize.ModelParticipantAction.java
License:Open Source License
/** * Convenience method that prompts to save changes in the given dirty model. * @param shell a shell//from w ww. j a v a 2 s .co m * @param saveable a dirty saveable model * @param allowCancel whether canceling the action is an option * @return whether the user choose to save (<code>true</code>) or revert (<code>false</code>() the model * @throws InterruptedException thrown if the user choose to cancel */ public static boolean promptToSaveChanges(final Shell shell, final SaveableComparison saveable, final boolean allowCancel) throws InterruptedException { final int[] result = new int[] { 0 }; Runnable runnable = new Runnable() { public void run() { String[] options; if (allowCancel) { options = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; } else { options = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; } MessageDialog dialog = new MessageDialog(shell, TeamUIMessages.ModelParticipantAction_0, null, NLS.bind(TeamUIMessages.ModelParticipantAction_1, saveable.getName()), MessageDialog.QUESTION, options, result[0]); result[0] = dialog.open(); } }; shell.getDisplay().syncExec(runnable); if (result[0] == 2) throw new InterruptedException(); return result[0] == 0; }
From source file:org.eclipse.thym.ui.wizard.export.NativeBinaryDestinationPage.java
License:Open Source License
@Override public String queryOverwrite(String pathString) { final MessageDialog dialog = new MessageDialog(getShell(), "Overwrite Files?", null, pathString + " already exists. Would you like to overwrite it?", MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);//from w w w. j av a2s . c om String[] response = new String[] { YES, NO, CANCEL }; //most likely to be called from non-ui thread getControl().getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()]; }
From source file:org.eclipse.thym.ui.wizard.export.NativeProjectDestinationPage.java
License:Open Source License
@Override public String queryOverwrite(String pathString) { final MessageDialog dialog = new MessageDialog(getShell(), "Overwrite Files?", null, "Directory " + pathString + " already exists. Would you like to overwrite it?", MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0);//w w w .ja va2 s .c om String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL }; //most likely to be called from non-ui thread getControl().getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()]; }
From source file:org.eclipse.titan.log.viewer.preferences.DecipheringPreferenceHandler.java
License:Open Source License
/** * Imports all of the rulesets from the given file. * If a ruleset with the same name already exists, a dialog will be displayed to the user. * * @param file/*from w w w . j a v a 2s . c om*/ * @throws ImportFailedException */ public static void importFromFile(final File file) throws ImportFailedException { FileInputStream stream = null; try { stream = new FileInputStream(file); final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); InputSource inputSource = new InputSource(stream); Document document = builder.parse(inputSource); Element documentElement = document.getDocumentElement(); if (!documentElement.getNodeName().contentEquals(TAG_ROOT)) { throw new ImportFailedException("The xml file is not valid"); } final List<String> alreadyExistingRulesets = getAvailableRuleSets(); NodeList rulesets = document.getElementsByTagName(TAG_RULE_SET); Boolean overwriteAll = null; for (int i = 0; i < rulesets.getLength(); ++i) { Element ruleElement = (Element) rulesets.item(i); NodeList nameList = ruleElement.getElementsByTagName(TAG_NAME); if (nameList.getLength() == 0) { throw new ImportFailedException("The ruleset's name is missing."); } final String rulesetName = nameList.item(0).getTextContent(); if (rulesetName.length() == 0) { throw new ImportFailedException("The ruleset name can not be the empty string."); } NodeList messageTypeListList = ruleElement.getElementsByTagName(TAG_MSG_TYPE_LIST); if (messageTypeListList.getLength() == 0) { throw new ImportFailedException( "The message type list for the ruleset '" + rulesetName + "' is missing."); } Element messageTypeListElement = (Element) messageTypeListList.item(0); NodeList msgTypeList = messageTypeListElement.getElementsByTagName(TAG_MSG_TYPE); Map<String, List<String>> msgTypesMap = importMessageTypes(rulesetName, msgTypeList); if (!alreadyExistingRulesets.contains(rulesetName)) { alreadyExistingRulesets.add(rulesetName); DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap); continue; } if (overwriteAll == null) { final MessageDialog msgdialog = new MessageDialog(null, "Ruleset exists", null, "The following ruleset already exists: " + rulesetName + ".\nOverwrite the existing ruleset?", MessageDialog.QUESTION, new String[] { "Yes", "No", "Yes to All", "No to All" }, 1); final int result = msgdialog.open(); if (result == 2) { overwriteAll = true; } else if (result == 3) { overwriteAll = false; } if (result == 2 || result == 0) { DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap); alreadyExistingRulesets.add(rulesetName); } } else if (overwriteAll) { DecipheringPreferenceHandler.addRuleSet(rulesetName, msgTypesMap); alreadyExistingRulesets.add(rulesetName); } } PreferencesHandler.getInstance().setImportLastDir(file.getParentFile().getPath()); } catch (ParserConfigurationException e) { throw new ImportFailedException("Error while parsing the file: " + e.getMessage()); } catch (SAXException e) { throw new ImportFailedException("Error while parsing the file: " + e.getMessage()); } catch (IOException e) { throw new ImportFailedException("Error while parsing the file: " + e.getMessage()); } finally { IOUtils.closeQuietly(stream); } }
From source file:org.eclipse.tm.te.rcp.application.ApplicationWorkbenchAdvisor.java
License:Open Source License
/** * Initialize the listener for settings changes. *//*from ww w. j a v a 2s.c om*/ private void initializeSettingsChangeListener() { settingsChangeListener = new Listener() { boolean currentHighContrast = Display.getCurrent().getHighContrast(); public void handleEvent(org.eclipse.swt.widgets.Event event) { if (Display.getCurrent().getHighContrast() == currentHighContrast) return; currentHighContrast = !currentHighContrast; // make sure they really want to do this if (new MessageDialog(null, Messages.SystemSettingsChange_title, null, Messages.SystemSettingsChange_message, MessageDialog.QUESTION, new String[] { Messages.SystemSettingsChange_yes, Messages.SystemSettingsChange_no }, 1) .open() == Window.OK) { PlatformUI.getWorkbench().restart(); } } }; }
From source file:org.eclipse.tm.te.tcf.filesystem.internal.autosave.SaveAllListener.java
License:Open Source License
/** * Merge those conflicting nodes.//from w w w.j a v a2s . c o m * * @param conflicts The conflicting nodes. */ private void mergeConflicts(List<FSTreeNode> conflicts) { for (FSTreeNode node : conflicts) { String title = Messages.SaveAllListener_StateChangedDialogTitle; String message = NLS.bind(Messages.SaveAllListener_SingularMessage, node.name); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); Shell parent = window.getShell(); MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION, new String[] { Messages.SaveAllListener_Merge, Messages.SaveAllListener_SaveAnyway, Messages.SaveAllListener_Cancel }, 0); int index = msgDialog.open(); if (index == 0) { // Merge LocalTypedElement local = new LocalTypedElement(node); RemoteTypedElement remote = new RemoteTypedElement(node); MergeEditorInput mergeInput = new MergeEditorInput(local, remote, page); CompareUI.openCompareDialog(mergeInput); } else if (index == 1) { // Save anyway CacheManager.getInstance().upload(conflicts.toArray(new FSTreeNode[conflicts.size()])); } } }
From source file:org.eclipse.tm.te.tcf.filesystem.internal.autosave.SaveListener.java
License:Open Source License
@Override public void postExecuteSuccess(String commandId, Object returnValue) { if (dirtyNode != null) { try {//from ww w.j a va 2 s . com // Refresh the fDirtyNode's state. StateManager.getInstance().refreshState(dirtyNode); if (PersistenceManager.getInstance().isAutoSaving()) { CacheState state = StateManager.getInstance().getCacheState(dirtyNode); switch (state) { case conflict: String title = Messages.SaveListener_StateChangedDialogTitle; String message = NLS.bind(Messages.SaveListener_StateChangedMessage, dirtyNode.name); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); Shell parent = window.getShell(); MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION, new String[] { Messages.SaveListener_Merge, Messages.SaveListener_SaveAnyway, Messages.SaveListener_Cancel }, 0); int index = msgDialog.open(); if (index == 0) {// Merge LocalTypedElement local = new LocalTypedElement(dirtyNode); RemoteTypedElement remote = new RemoteTypedElement(dirtyNode); MergeEditorInput mergeInput = new MergeEditorInput(local, remote, page); CompareUI.openCompareDialog(mergeInput); } else if (index == 1) {// Save anyway. CacheManager.getInstance().upload(dirtyNode); } break; case modified: // Save anyway CacheManager.getInstance().upload(dirtyNode); break; case consistent: break; case outdated: break; } } } catch (TCFException tcfe) { Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog.openError(parent, Messages.StateManager_RefreshFailureTitle, tcfe.getLocalizedMessage()); } } }
From source file:org.eclipse.tm.te.tcf.filesystem.internal.handlers.CommitHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event); FSTreeNode node = (FSTreeNode) selection.getFirstElement(); try {/*from w ww.ja va2 s .c o m*/ // Refresh the node to get the latest state. StateManager.getInstance().refreshState(node); Shell parent = HandlerUtil.getActiveShell(event); File file = CacheManager.getInstance().getCacheFile(node); if (file.exists()) { CacheState state = StateManager.getInstance().getCacheState(node); switch (state) { case conflict: String title = Messages.CmmitHandler_StateChangedDialogTitle; String message = NLS.bind(Messages.CmmitHandler_StateChangedMessage, node.name); MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION, new String[] { Messages.CmmitHandler_Merge, Messages.CmmitHandler_CommitAnyway, Messages.CmmitHandler_Cancel }, 0); int index = msgDialog.open(); if (index == 0) {// Merge LocalTypedElement local = new LocalTypedElement(node); RemoteTypedElement remote = new RemoteTypedElement(node); IWorkbenchPage page = HandlerUtil.getActiveSite(event).getPage(); MergeEditorInput input = new MergeEditorInput(local, remote, page); CompareUI.openCompareDialog(input); } else if (index == 1) { // Commit anyway CacheManager.getInstance().upload(node); } break; case modified: // Commit it normally. CacheManager.getInstance().upload(node); break; case consistent: break; case outdated: break; } } else { String message = NLS.bind(Messages.CmmitHandler_FileDeleted, file.getName()); MessageDialog.openError(parent, Messages.CmmitHandler_ErrorTitle, message); } } catch (TCFException e) { Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageDialog.openError(parent, Messages.StateManager_RefreshFailureTitle, e.getLocalizedMessage()); } return null; }
From source file:org.eclipse.tm.te.tcf.filesystem.internal.handlers.OpenFileHandler.java
License:Open Source License
/** * Open the file node in an editor of the specified workbench page. If the * local cache file of the node is stale, then download it. Then open its * local cache file./*from w w w . j av a 2 s. co m*/ * * @param node * The file node to be opened. * @param page * The workbench page in which the editor is opened. */ private void openFile(FSTreeNode node, IWorkbenchPage page) { File file = CacheManager.getInstance().getCacheFile(node); if (!file.exists()) { // If the file node's local cache does not exist yet, download it. boolean successful = CacheManager.getInstance().download(node); if (!successful) { return; } } if (!PersistenceManager.getInstance().isAutoSaving()) { openEditor(page, node); } else { try { StateManager.getInstance().refreshState(node); } catch (TCFException e) { Shell parent = page.getWorkbenchWindow().getShell(); MessageDialog.openError(parent, Messages.StateManager_RefreshFailureTitle, e.getLocalizedMessage()); return; } CacheState state = StateManager.getInstance().getCacheState(node); switch (state) { case consistent: openEditor(page, node); break; case modified: { // If the file node's local cache has been modified, upload it // before open it. boolean successful = CacheManager.getInstance().upload(node); if (successful) openEditor(page, node); } break; case outdated: { // If the file node's local cache does not exist yet, download // it. boolean successful = CacheManager.getInstance().download(node); if (successful) openEditor(page, node); } break; case conflict: { String title = Messages.OpenFileHandler_ConflictingTitle; String message = NLS.bind(Messages.OpenFileHandler_ConflictingMessage, node.name); Shell parent = page.getWorkbenchWindow().getShell(); MessageDialog msgDialog = new MessageDialog(parent, title, null, message, MessageDialog.QUESTION, new String[] { Messages.OpenFileHandler_Merge, Messages.OpenFileHandler_OpenAnyway, Messages.OpenFileHandler_Cancel }, 0); int index = msgDialog.open(); if (index == 0) { LocalTypedElement local = new LocalTypedElement(node); RemoteTypedElement remote = new RemoteTypedElement(node); MergeEditorInput input = new MergeEditorInput(local, remote, page); CompareUI.openCompareDialog(input); } else if (index == 1) { openEditor(page, node); } } break; } } }