List of usage examples for org.eclipse.jface.preference IPreferenceStore getString
String getString(String name);
From source file:com.motorola.studio.android.adt.MotodevHProfDumpHandler.java
License:Apache License
private void extractLocalHprof(final byte[] data, final Client client, IProgressMonitor monitor) { monitor.beginTask(AndroidNLS.DumpHprofFile_GeneratingMemoryAnalysisOutput, 100); IPreferenceStore preferenceStore = DdmsPlugin.getDefault().getPreferenceStore(); String value = preferenceStore.getString(PreferenceInitializer.ATTR_HPROF_ACTION); if (SAVE_ACTION.equals(value)) { warnAboutSaveHprofPreference();// w ww .j a v a 2 s . c o m } value = preferenceStore.getString(PreferenceInitializer.ATTR_HPROF_ACTION); if (OPEN_ACTION.equals(value)) { try { monitor.setTaskName(AndroidNLS.DumpHprofFile_SavingTempFile); File tempHprofFile = saveTempFile(data, HPROF_FILE_EXTENSION); monitor.worked(50); monitor.setTaskName(AndroidNLS.DumpHprofFile_OpeningMemoryAnalysisFile); openHprofFileInEditor(tempHprofFile.getAbsolutePath()); monitor.worked(50); } catch (Exception e) { String errorMsg = e.getMessage(); displayErrorFromUiThread( AndroidNLS.UI_Hprof_Handler_Dialog_Unable_to_Save_Hprof_Data + FORMATTED_ERROR_STRING_2, errorMsg != null ? ":\n" + errorMsg //$NON-NLS-1$ : "."); //$NON-NLS-1$ } } else { monitor.setTaskName(AndroidNLS.DumpHprofFile_SavingFile); promptAndSave(client.getClientData().getClientDescription() + HPROF_FILE_EXTENSION, data, AndroidNLS.UI_Hprof_Handler_Save_Prompt); monitor.worked(100); } monitor.done(); }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Shows a dialog with "Yes" and "No" buttons. * The dialog is opened only if it is the first time that the dialog is * shown or if the user did not check the option "Do not show this window * again" when the dialog had been opened previously. * * @param preferenceKey the key to use when persisting the user's preference. * @param title the dialog's title, or <code>null</code> if none. * @param message the dialog's message./*from w w w . j av a2 s. c o m*/ * @return if the dialog was opened: true, if the user pressed "Yes". * if the dialog was not opened: true, if the option was set to "Always". */ public static boolean showQuestion(final String preferenceKey, final String title, final String message) { final Boolean[] reply = new Boolean[1]; final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, title, message, UtilitiesNLS.UI_DoNotShowMEAgain, false, store, prefKey); reply[0] = (dialog.getReturnCode() == IDialogConstants.YES_ID); } else { reply[0] = preferenceValue.equals(MessageDialogWithToggle.ALWAYS); } } }); return reply[0]; }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Shows an information dialog to user. The dialog is opened * only if it is the first time that the dialog is shown or if the user did not checked * the option "Do not show this window again" when the dialog had been opened previously. * * @param preferenceKey the key to use when persisting the user's preference * @param title the dialog's title, or <code>null</code> if none * @param message the dialogs message//from w w w . java 2 s . c o m * */ public static void showInformation(final String preferenceKey, final String title, final String message) { final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle.openInformation(shell, title, message, UtilitiesNLS.UI_DoNotShowMEAgain, false, store, prefKey); } } }); }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Shown a warning dialog. The dialog is opened * only if it is the first time that the dialog is shown or if the user did not checked * the option "Do not show this window again" when the dialog had been opened previously. * * @param preferenceKey the key to use when persisting the user's preference * @param title the dialog's title, or <code>null</code> if none * @param message the dialogs message/* w w w .j a va 2 s .c om*/ * */ public static void showWarning(final String preferenceKey, final String title, final String message) { final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle.openWarning(shell, title, message, UtilitiesNLS.UI_DoNotShowMEAgain, false, store, prefKey); } } }); }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Show a confirmation message./*from w ww . j a v a 2 s .co m*/ * * @param preferenceKey the key to use when persisting the user's preference; * <code>null</code> if you don't want it persisted. * @param title the dialog's title, or <code>null</code> if none * @param message the dialogs message */ public static boolean showConfirmation(final String preferenceKey, final String title, final String message) { final Boolean[] reply = new Boolean[1]; final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(shell, title, message, UtilitiesNLS.UI_AlwaysProceed, false, store, prefKey); reply[0] = (dialog.getReturnCode() == IDialogConstants.OK_ID); } else { reply[0] = preferenceValue.equals(MessageDialogWithToggle.ALWAYS); } } }); return reply[0]; }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Shows an error dialog. The dialog is opened * only if it is the first time that the dialog is shown or if the user did not checked * the option "Do not show this window again" when the dialog had been opened previously. * * @param preferenceKey the key to use when persisting the user's preference * @param title the dialog's title, or <code>null</code> if none * @param message the dialogs message// w ww.ja v a 2 s.co m * */ public static void showError(final String preferenceKey, final String title, final String message) { final String prefKey = preferenceKey + TOGGLE_DIALOG; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AbstractUIPlugin plugin = CommonPlugin.getDefault(); IPreferenceStore store = plugin.getPreferenceStore(); String preferenceValue = store.getString(prefKey); if (MessageDialogWithToggle.PROMPT.equals(preferenceValue) || (preferenceValue.length() == 0)) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); Shell shell = ww.getShell(); MessageDialogWithToggle.openError(shell, title, message, UtilitiesNLS.UI_DoNotShowMEAgain, false, store, prefKey); } } }); }
From source file:com.motorola.studio.android.common.preferences.DialogWithToggleUtils.java
License:Apache License
/** * Get a preference toggle dialog preference key * This key is used to toggle dialogs. Do not use it for general proposes * @param preferenceKey//from w ww .j av a 2 s . c o m * @return the key, or null if it is default (not set) */ public static String getToggleDialogPreferenceKey(final String preferenceKey) { final String prefKey = preferenceKey + TOGGLE_DIALOG; IPreferenceStore store = CommonPlugin.getDefault().getPreferenceStore(); String prefValue = null; if (!store.isDefault(prefKey)) { prefValue = store.getString(prefKey); } return prefValue; }
From source file:com.motorola.studio.android.emulator.logic.StartEmulatorProcessLogic.java
License:Apache License
public void execute(final IAndroidLogicInstance instance, int timeout, IProgressMonitor monitor) throws InstanceStartException, StartTimeoutException, StartCancelledException { long timeoutLimit = AndroidLogicUtils.getTimeoutLimit(timeout); info("Starting the Android Emulator process: " + instance); instance.setWindowHandle(0);/*www .ja v a 2s .c o m*/ File userData = instance.getUserdata(); if (userData != null) { File userdataDir = userData.getParentFile(); if ((userdataDir != null) && (!userdataDir.exists())) { userdataDir.mkdirs(); } } selectedEmulatorPath = retrieveEmulatorExecutableName(instance); File emulatorExe = new File(SdkUtils.getSdkPath(), selectedEmulatorPath); List<String> cmdList = new LinkedList<String>(); cmdList.add(emulatorExe.getAbsolutePath()); cmdList.add(EMULATOR_VM_PARAMETER); cmdList.add(instance.getName()); Properties propArgs = instance.getCommandLineArgumentsAsProperties(); IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore(); String adtEmuOptions = store.getString(AdtPrefs.PREFS_EMU_OPTIONS); StringTokenizer adtOptionsTokenizer = new StringTokenizer(adtEmuOptions, " "); while (adtOptionsTokenizer.hasMoreTokens()) { String nextToken = adtOptionsTokenizer.nextToken(); cmdList.add(nextToken); } for (Object key : propArgs.keySet()) { String value = propArgs.getProperty(key.toString()); if (key.equals("other")) { StringTokenizer stringTokenizer = new StringTokenizer(value, " "); while (stringTokenizer.hasMoreTokens()) { cmdList.add(stringTokenizer.nextToken()); } } else { if ((value.trim().length() > 0) && !value.equals(Boolean.TRUE.toString())) { cmdList.add(key.toString()); if (Platform.getOS().equals(Platform.OS_MACOSX)) { if (value.contains(" ")) { value = "\"" + value + "\""; } } else { if (value.contains("\\")) { value = value.replace("\\", "\\\\"); } if (value.contains(" ")) { value = value.replace(" ", "\\ "); } } cmdList.add(value); } else if ((value.trim().length() > 0) && value.equals(Boolean.TRUE.toString())) { cmdList.add(key.toString()); } } } // add proxy in case it is needed Properties properties = instance.getProperties(); if (properties != null) { String useProxy = properties.getProperty(IDevicePropertiesConstants.useProxy, IDevicePropertiesConstants.defaultUseProxyValue); if (Boolean.TRUE.toString().equals(useProxy)) { addEmulatorProxyParameter(cmdList); } } StringBuffer cmdLog = new StringBuffer(""); boolean httpProxyParamFound = false; boolean logHttpProxyUsage = false; for (String param : cmdList) { // Do not log -http-proxy information if (!httpProxyParamFound) { if (!param.equals(EMULATOR_HTTP_PROXY_PARAMETER)) { if (param.startsWith(emulatorExe.getAbsolutePath())) { // do not log emulator full path cmdLog.append(selectedEmulatorPath + " "); } else { cmdLog.append(param + " "); } } else { httpProxyParamFound = true; logHttpProxyUsage = true; } } else { httpProxyParamFound = false; } } // Append http proxy usage to log if (logHttpProxyUsage) { cmdLog.append("\nProxy settings are being used by the started emulator (-http-proxy parameter)."); } // add command to not start from snapshot if (properties != null) { String startFromSnapshot = properties.getProperty(IDevicePropertiesConstants.startFromSnapshot, IDevicePropertiesConstants.defaultstartFromSnapshotValue); if (Boolean.FALSE.toString().equals(startFromSnapshot)) { cmdList.add(EMULATOR_NO_SNAPSHOT_LOAD); } } // Add the command to not save snapshot if (properties != null) { String saveSnapshot = properties.getProperty(IDevicePropertiesConstants.saveSnapshot, IDevicePropertiesConstants.defaulSaveSnapshot); if (Boolean.FALSE.toString().equals(saveSnapshot)) { cmdList.add(EMULATOR_NO_SNAPSHOT_SAVE); } } Process p; try { p = AndroidLogicUtils.executeProcess(cmdList.toArray(new String[0]), cmdLog.toString()); } catch (AndroidException e) { throw new InstanceStartException(e); } info("Wait until and emulator with the VM " + instance.getName() + " is up "); AndroidLogicUtils.testProcessStatus(p); instance.setProcess(p); instance.setComposite(null); final String avdName = instance.getName(); if (!Platform.getOS().equals(Platform.OS_MACOSX)) { Collection<IViewPart> openedAndroidViews = EclipseUtils.getAllOpenedViewsWithId(EMULATOR_VIEW); if (!openedAndroidViews.isEmpty()) { Runnable runnable = new Runnable() { public void run() { long windowHandle = -1; long timeOutToFindWindow = System.currentTimeMillis() + 30000; do { try { Thread.sleep(250); } catch (InterruptedException e) { // do nothing } try { AndroidLogicUtils.testTimeout(timeOutToFindWindow, ""); } catch (StartTimeoutException e) { debug("Emulator window could not be found, instance :" + avdName); break; } try { int port = AndroidLogicUtils .getEmulatorPort(DDMSFacade.getSerialNumberByName(instance.getName())); if (port > 0) { windowHandle = NativeUIUtils.getWindowHandle(instance.getName(), port); } } catch (Exception t) { t.getCause().getMessage(); System.out.println(t.getCause().getMessage()); } } while (windowHandle <= 0); if (windowHandle > 0) { instance.setWindowHandle(windowHandle); NativeUIUtils.hideWindow(windowHandle); } } }; Thread getHandleThread = new Thread(runnable, "Window Handle Thread"); getHandleThread.start(); } } if (instance.getProperties() .getProperty(IDevicePropertiesOSConstants.useVnc, NativeUIUtils.getDefaultUseVnc()) .equals(Boolean.TRUE.toString())) { do { try { Thread.sleep(450); } catch (InterruptedException e) { // do nothing } AndroidLogicUtils.testCanceled(monitor); try { AndroidLogicUtils.testTimeout(timeoutLimit, NLS.bind(EmulatorNLS.EXC_TimeoutWhileStarting, avdName)); } catch (StartTimeoutException e) { debug("Emulator start timeout has been reached, instance :" + avdName + " has device: " + instance.hasDevice() + "isOnline? " + DDMSFacade.isDeviceOnline(DDMSFacade.getSerialNumberByName(avdName))); throw e; } } while (!isEmulatorReady(avdName)); } Thread t = new Thread("Process Error") { @Override public void run() { boolean shouldTryAgain = true; for (int i = 0; (i < 90) && shouldTryAgain; i++) { try { sleep(500); Process p = instance.getProcess(); if (p != null) { AndroidLogicUtils.testProcessStatus(p); } } catch (Exception e) { StudioLogger.info(StartEmulatorProcessLogic.class, "Trying to stop the emulator process: execution stopped too early"); DialogWithToggleUtils.showError(EmulatorPlugin.EMULATOR_UNEXPECTEDLY_STOPPED, EmulatorNLS.GEN_Error, NLS.bind(EmulatorNLS.ERR_AndroidLogicPlugin_EmulatorStopped, instance.getName())); shouldTryAgain = false; try { instance.stop(true); } catch (InstanceStopException ise) { StudioLogger.error(StartEmulatorProcessLogic.class, "Error trying to stop instance on process error", ise); } } } } }; t.start(); debug("Emulator instance is now up and running... " + instance); }
From source file:com.motorola.studio.android.localization.translators.GoogleTranslator.java
License:Apache License
private static String getApiKey() { String apiKey = GoogleTranslatorConstants.API_KEY; IPreferenceStore prefStore = TranslationPlugin.getDefault().getPreferenceStore(); if (!prefStore.isDefault(GoogleTranslatorConstants.API_KEY_VALUE_PREFERENCE)) { apiKey = prefStore.getString(GoogleTranslatorConstants.API_KEY_VALUE_PREFERENCE); if (apiKey == null) { apiKey = GoogleTranslatorConstants.API_KEY; }/*from w w w. ja va 2 s . c o m*/ } return apiKey; }
From source file:com.motorola.studio.android.localization.translators.preferences.ui.TranslationPreferencePage.java
License:Apache License
/** * get the apikey//from ww w. j av a2s . c om * @return the apikey or an empty string for the default one */ private static String getApiKey() { String apiKey = ""; //$NON-NLS-1$ IPreferenceStore prefStore = TranslationPlugin.getDefault().getPreferenceStore(); if (!prefStore.isDefault(GoogleTranslatorConstants.API_KEY_VALUE_PREFERENCE)) { apiKey = prefStore.getString(GoogleTranslatorConstants.API_KEY_VALUE_PREFERENCE); if (apiKey == null) { apiKey = ""; //$NON-NLS-1$ } } return apiKey; }