List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_ID
int YES_ID
To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_ID.
Click Source Link
From source file:com.motorola.studio.android.common.utilities.FileUtil.java
License:Apache License
public static boolean extractZipArchive(File file, File destination, List<String> selectedEntries, IProgressMonitor monitor) throws IOException { SubMonitor subMonitor = SubMonitor.convert(monitor); ZipFile zipFile = null;//from w w w . j a va 2s . c om CRC32 crc = new CRC32(); byte[] buf = new byte[BUFFER_SIZE]; File extractDestination = destination != null ? destination : file.getParentFile(); if (!extractDestination.exists()) { extractDestination.mkdirs(); } boolean unziped = true; try { zipFile = new ZipFile(file); } catch (Throwable e) { unziped = false; StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() //$NON-NLS-1$ + " to " + extractDestination, e); //$NON-NLS-1$ } if (zipFile != null) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); subMonitor.beginTask("Extracting files", Collections.list(entries).size()); //$NON-NLS-1$ entries = zipFile.entries(); InputStream input = null; FileOutputStream output = null; int diagReturn = IDialogConstants.YES_ID; while (entries.hasMoreElements()) { crc.reset(); try { ZipEntry entry = entries.nextElement(); if (selectedEntries.contains(entry.getName())) { File newFile = new File(extractDestination, entry.getName()); if ((diagReturn != IDialogConstants.YES_TO_ALL_ID) && newFile.exists()) { diagReturn = EclipseUtils.showQuestionYesAllCancelDialog( UtilitiesNLS.FileUtil_File_Exists_Title, NLS.bind(UtilitiesNLS.FileUtil_File_Exists_Message, newFile.getAbsolutePath())); } if ((diagReturn == IDialogConstants.YES_ID) || (diagReturn == IDialogConstants.YES_TO_ALL_ID)) { newFile.delete(); if (entry.isDirectory()) { newFile.mkdirs(); } else { newFile.getParentFile().mkdirs(); if (newFile.createNewFile()) { input = zipFile.getInputStream(entry); output = new FileOutputStream(newFile); int length = 0; while ((length = input.read(buf, 0, BUFFER_SIZE)) > 1) { output.write(buf, 0, length); crc.update(buf, 0, length); } if (crc.getValue() != entry.getCrc()) { throw new IOException(); } } } } else { diagReturn = IDialogConstants.YES_ID; //Attempt to extract next entry } } } catch (IOException e) { unziped = false; StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$ + extractDestination, e); throw e; } catch (Throwable t) { unziped = false; StudioLogger.error(FileUtil.class, "Error extracting file: " + file.getAbsolutePath() + " to " //$NON-NLS-1$ //$NON-NLS-2$ + extractDestination, t); } finally { try { if (input != null) { input.close(); } if (output != null) { output.close(); } } catch (Throwable t) { //do nothing } subMonitor.worked(1); } } } return unziped; }
From source file:com.motorolamobility.preflighting.ui.handlers.AnalyzeApkHandler.java
License:Apache License
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbench workbench = PlatformUI.getWorkbench(); if ((workbench != null) && !workbench.isClosing()) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { ISelection selection = null; if (initialSelection != null) { selection = initialSelection; } else { selection = window.getSelectionService().getSelection(); }/*from ww w .j a v a 2s .c o m*/ if (selection instanceof IStructuredSelection) { IStructuredSelection sselection = (IStructuredSelection) selection; Iterator<?> it = sselection.iterator(); String sdkPath = AndroidUtils.getSDKPathByPreference(); if (monitor != null) { monitor.setTaskName(PreflightingUiNLS.ApplicationValidation_monitorTaskName); monitor.beginTask(PreflightingUiNLS.ApplicationValidation_monitorTaskName, sselection.size() + 1); monitor.worked(1); } ArrayList<PreFlightJob> jobList = new ArrayList<PreFlightJob>(); boolean isHelpExecution = false; IPreferenceStore preferenceStore = PreflightingUIPlugin.getDefault().getPreferenceStore(); boolean showMessageDialog = true; if (preferenceStore.contains( PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG)) { showMessageDialog = MessageDialogWithToggle.ALWAYS.equals(preferenceStore.getString( PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG)); } if (showMessageDialog && (!preferenceStore.contains(PreflightingUIPlugin.OUTPUT_LIMIT_VALUE)) && preferenceStore.contains(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY) && (!(preferenceStore.getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY)) .equals(PreflightingUIPlugin.DEFAULT_BACKWARD_COMMANDLINE))) { String commandLine = PreflightingUIPlugin.getDefault().getPreferenceStore() .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Title, NLS.bind(PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Message, commandLine), PreflightingUiNLS.AnalyzeApkHandler_Do_Not_Show_Again, false, preferenceStore, PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG); int returnCode = dialog.getReturnCode(); if (returnCode == IDialogConstants.YES_ID) { EclipseUtils.openPreference( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_PAGE); } } String userParamsStr = preferenceStore .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY); downgradeErrors = preferenceStore .contains(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE) ? preferenceStore .getBoolean(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE) : true; //we look for a help parameter: -help or -list-checkers //in such case we execute app validator only once, //since all executions will have the same output if (userParamsStr.length() > 0) { String regex = "((?!(\\s+" + "-" + ")).)*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Pattern pat = Pattern.compile(regex); Matcher matcher = pat.matcher(userParamsStr); while (matcher.find()) { String parameterValues = userParamsStr.substring(matcher.start(), matcher.end()); if (parameterValues.equals("-" //$NON-NLS-1$ + ApplicationParameterInterpreter.PARAM_HELP) || parameterValues.equals( "-" //$NON-NLS-1$ + ApplicationParameterInterpreter.PARAM_LIST_CHECKERS)) { isHelpExecution = true; } } } while (it.hasNext()) { IResource analyzedResource = null; Object resource = it.next(); String path = null; if (resource instanceof IFile) { IFile apkfile = (IFile) resource; analyzedResource = apkfile; if (apkfile.getFileExtension().equals("apk") && apkfile.exists() //$NON-NLS-1$ && apkfile.getLocation().toFile().canRead()) { /* * For each apk, execute all verifications passaing the two needed parameters */ path = apkfile.getLocation().toOSString(); } else { MessageDialog.openError(window.getShell(), PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle, PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage); } } else if (resource instanceof File) { File apkfile = (File) resource; if (apkfile.getName().endsWith(".apk") && apkfile.exists() //$NON-NLS-1$ && apkfile.canRead()) { /* * For each apk, execute all verifications passaing the two needed parameters */ path = apkfile.getAbsolutePath(); } else { MessageDialog.openError(window.getShell(), PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle, PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage); } enableMarkers = false; } else if (resource instanceof IProject) { IProject project = (IProject) resource; analyzedResource = project; path = project.getLocation().toOSString(); } else if (resource instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) resource; IProject project = (IProject) adaptable.getAdapter(IProject.class); analyzedResource = project; if (project != null) { path = project.getLocation().toOSString(); } } if (path != null) { PreFlightJob job = new PreFlightJob(path, sdkPath, analyzedResource); jobList.add(job); if (isHelpExecution) { //app validator is executed only once for help commands break; } } } if (enableMarkers) { // Show and activate problems view Runnable showProblemsView = new Runnable() { public void run() { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .showView(PROBLEMS_VIEW_ID); } catch (PartInitException e) { PreflightingLogger.error("Error showing problems view."); //$NON-NLS-1$ } } }; Display.getDefault().asyncExec(showProblemsView); } //show console for external apks else { showApkConsole(); } ParentJob parentJob = new ParentJob( PreflightingUiNLS.AnalyzeApkHandler_PreflightingToolNameMessage, jobList); parentJob.setUser(true); parentJob.schedule(); try { if (monitor != null) { monitor.done(); } } catch (Exception e) { //Do nothing } } } } return null; }
From source file:com.motorolamobility.studio.android.certmanager.command.DeleteKeystoreHandler.java
License:Apache License
private boolean showQuestion(List<ITreeNode> nodesToDelete) { final Boolean[] reply = new Boolean[2]; final String keystoreName = nodesToDelete.size() == 1 ? nodesToDelete.get(0).getName() : null; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override/* w w w . j a va 2 s . c o m*/ public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Title, keystoreName != null ? CertificateManagerNLS.bind( CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Description, keystoreName) : CertificateManagerNLS.DeleteKeystoreHandler_Delete_Selected_Keystores, CertificateManagerNLS.DeleteKeystoreHandler_ConfirmationQuestionDialog_Toggle, false, null, null); reply[0] = (dialog.getReturnCode() == IDialogConstants.YES_ID); reply[1] = dialog.getToggleState(); } }); toggleState = reply[1]; return reply[0]; }
From source file:com.motorolamobility.studio.android.db.core.ui.wizards.createdb.CreateDatabaseWizard.java
License:Apache License
private boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDescriptor perspective) { IPreferenceStore store = DbCoreActivator.getDefault().getPreferenceStore(); String preference = store.getString(SWITCH_MOTODEV_DATABASE_PERSPECTIVE); if (preference.equals("")) //$NON-NLS-1$ {/* ww w.j av a2s. c om*/ store.setValue(SWITCH_MOTODEV_DATABASE_PERSPECTIVE, MessageDialogWithToggle.PROMPT); preference = MessageDialogWithToggle.PROMPT; } boolean result; if (MessageDialogWithToggle.ALWAYS.equals(preference)) { result = true; } else if (MessageDialogWithToggle.NEVER.equals(preference)) { result = false; } else { MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), DbCoreNLS.UI_CreateDatabaseWizard_ChangePerspectiveTitle, DbCoreNLS.UI_CreateDatabaseWizard_ChangePerspectiveQuestion, null, false, store, SWITCH_MOTODEV_DATABASE_PERSPECTIVE); int dialogResult = dialog.getReturnCode(); result = dialogResult == IDialogConstants.YES_ID; } return result; }
From source file:com.nokia.carbide.cpp.internal.project.ui.editors.common.CarbideFormEditor.java
License:Open Source License
/** * Confirm editing should be allowed. If needed, interacts with the * Team VCS provider to check that file can be modified. * @return true if ok to proceed with changes. *///from w w w .j a v a2s .c o m public boolean preflightEdit() { IFile fileInput = getInputFile(); if (fileInput == null) { return true; } Shell shell = getEditorSite().getShell(); // If files are modified as a result of a version control // operation then our resource listener will pick it up. IStatus status = FileUtils.validateEdit(fileInput, shell); if (status.isOK()) { // check to see if the file is derived if (fileInput.isDerived()) { final String warnKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED; IPreferenceStore store = EditorsUI.getPreferenceStore(); if (!store.getBoolean(warnKey)) return true; MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion( getSite().getShell(), Messages.CarbideFormEditor_warning_derived_title, Messages.CarbideFormEditor_warning_derived_message, Messages.CarbideFormEditor_warning_derived_dontShowAgain, false, null, null); store.setValue(warnKey, !toggleDialog.getToggleState()); return toggleDialog.getReturnCode() == IDialogConstants.YES_ID; } } return status.isOK(); }
From source file:com.nokia.carbide.cpp.internal.project.ui.ProjectUIPlugin.java
License:Open Source License
public static void projectCreated(final IProject project) { // expand the project root so the user can see the contents UIJob job = new UIJob("") { //$NON-NLS-1$ public IStatus runInUIThread(IProgressMonitor monitor) { try { expandProject(project);/*from w w w. j a v a2 s . c o m*/ } catch (CoreException e) { Logging.log(plugin, e.getStatus()); e.printStackTrace(); } return Status.OK_STATUS; } }; job.setSystem(true); job.setRule(null); // no rule needed here - could just block important jobs job.schedule(); if (isQtProject(project)) return; // Qt project wizards flip to their own perspective // set the perspective to Carbide C/C++ try { IWorkbench workbench = getDefault().getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow == null) { IWorkbenchWindow windows[] = workbench.getWorkbenchWindows(); activeWorkbenchWindow = windows[0]; } final IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry() .findPerspectiveWithId("com.nokia.carbide.cpp.CarbideCppPerspective"); //$NON-NLS-1$ final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage != null) { if (activePage.getPerspective().getId().equals(perspective.getId())) return; // already on the default perspective for this projects } if (activePage != null) { job = new UIJob("") { //$NON-NLS-1$ public IStatus runInUIThread(IProgressMonitor monitor) { boolean switchToDefaultPerspective = false; IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); if (store != null) { String promptSetting = store .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if ((promptSetting.equals(MessageDialogWithToggle.ALWAYS))) { switchToDefaultPerspective = true; } else if ((promptSetting.equals(MessageDialogWithToggle.PROMPT))) { MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion( WorkbenchUtils.getActiveShell(), Messages.getString("PerspectiveSwitchDialog_Title"), Messages.getString("PerspectiveSwitchDialog_Query"), Messages.getString("PerspectiveSwitchDialog_RememberDecisionText"), false, null, null); boolean toggleState = toggleDialog.getToggleState(); switchToDefaultPerspective = toggleDialog .getReturnCode() == IDialogConstants.YES_ID; // set the store if (toggleState) { if (switchToDefaultPerspective) store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.ALWAYS); else store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.NEVER); } } } if (switchToDefaultPerspective) { activePage.setPerspective(perspective); } return Status.OK_STATUS; } }; job.setSystem(true); job.setRule(null); // no rule needed here - could just block important jobs job.schedule(); } } catch (IllegalStateException e) { // PlatformUI.getWorkbench() throws if running headless } }
From source file:com.nokia.carbide.cpp.internal.qt.ui.QtUIPlugin.java
License:Open Source License
public static void switchToQtPerspective() { // set the perspective to Qt C++ try {/*from ww w. ja va2s . c om*/ IWorkbench workbench = getDefault().getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); if (activeWorkbenchWindow == null) { IWorkbenchWindow windows[] = workbench.getWorkbenchWindows(); activeWorkbenchWindow = windows[0]; } final IPerspectiveDescriptor perspective = workbench.getPerspectiveRegistry() .findPerspectiveWithId("com.trolltech.qtcppproject.QtCppPerspective"); //$NON-NLS-1$ final IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage != null) { if (activePage.getPerspective().getId().equals(perspective.getId())) return; // already on the default perspective for this projects } if (activePage != null) { UIJob job = new UIJob("") { //$NON-NLS-1$ public IStatus runInUIThread(IProgressMonitor monitor) { boolean switchToDefaultPerspective = false; IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); if (store != null) { String promptSetting = store .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if ((promptSetting.equals(MessageDialogWithToggle.ALWAYS))) { switchToDefaultPerspective = true; } else if ((promptSetting.equals(MessageDialogWithToggle.PROMPT))) { MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion( WorkbenchUtils.getActiveShell(), Messages.PerspectiveSwitchDialog_Title, Messages.PerspectiveSwitchDialog_Query, Messages.PerspectiveSwitchDialog_RememberDecisionText, false, null, null); boolean toggleState = toggleDialog.getToggleState(); switchToDefaultPerspective = toggleDialog .getReturnCode() == IDialogConstants.YES_ID; // set the store if (toggleState) { if (switchToDefaultPerspective) store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.ALWAYS); else store.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE, MessageDialogWithToggle.NEVER); } } } if (switchToDefaultPerspective) { activePage.setPerspective(perspective); } return Status.OK_STATUS; } }; job.setSystem(true); job.setRule(null); // no rule needed here - could just block important jobs job.schedule(); } } catch (IllegalStateException e) { // PlatformUI.getWorkbench() throws if running headless } }
From source file:com.nokia.cpp.internal.api.utils.ui.QueryWithTristatePrefDialog.java
License:Open Source License
/** * Main method to query for a setting. If the preference setting * is at the "don't skip" value then the dialog is run. If the * preference setting is at the skip value then the retained value * is always returned.<p>/* w ww . j a v a2 s. c o m*/ * If the user clicks OK with the "don't ask" checkbox checked * then the preference setting is automatically updated. * @return true if the "always" pref is set or the positive value (yes/ok) * was selected, false if the "never" pref or the negative value (no/cancel) * was selected. */ public boolean doQuery() { String value = preferences.contains(prefName) ? preferences.getString(prefName) : null; if (value != null) { if (value.equals(MessageDialogWithToggle.ALWAYS)) return true; if (value.equals(MessageDialogWithToggle.NEVER)) return false; // else, bogus, and go to dialog } MessageDialogWithToggle dialog; boolean confirmed = false; if (type == QUERY_YES_NO) { dialog = MessageDialogWithToggle.openYesNoQuestion(parentShell, title, prompt, "Don't ask to manage dependencies again.", initialSetting, preferences, prefName); confirmed = dialog.getReturnCode() == IDialogConstants.YES_ID; } else if (type == QUERY_OK_CANCEL) { dialog = MessageDialogWithToggle.openYesNoQuestion(parentShell, title, prompt, null, initialSetting, preferences, prefName); confirmed = dialog.getReturnCode() == IDialogConstants.OK_ID; } else Check.checkState(false); return confirmed; }
From source file:com.nokia.s60tools.creator.job.ConfirmFileReplaceDialog.java
License:Open Source License
protected void createButtonsForButtonBar(Composite parent) { GridLayout gdl = new GridLayout(1, false); GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER); parent.setLayout(gdl);/*from www.ja va 2s . co m*/ parent.setLayoutData(gd); createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true); createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, true); }
From source file:com.nokia.s60tools.creator.job.RunInDeviceJob.java
License:Open Source License
/** * Check if user wants to replace existing file * @return <code>true</code> if replace, <code>false</code> otherwise. * @throws JobCancelledByUserException /* www .j a v a2s.com*/ */ private boolean showReplaceFileDialog() throws JobCancelledByUserException { Runnable runDlg = new Runnable() { public void run() { // Shell shell = CreatorActivator.getCurrentlyActiveWbWindowShell(); ConfirmFileReplaceDialog dlg = new ConfirmFileReplaceDialog(shell, destFilePath); dlg.open(); confirmDialogSelection = dlg.getSelection(); } }; Display.getDefault().syncExec(runDlg); if (confirmDialogSelection == IDialogConstants.CANCEL_ID) { throwJobCancelledException(); } boolean replace = confirmDialogSelection == IDialogConstants.YES_ID ? true : false; return replace; }