private void updateDefaultEditorMappingIfAbsent() { final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry(); for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) { final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor(); if (null == defaultEditor) { final String extension = editorMapping.getExtension(); LOGGER.info("No default editor is associated with files with extension: '." + extension + "'."); final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID); if (null != defaultTextEditor) { ((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor); String editorName = defaultTextEditor.getLabel(); if (null == editorName) { editorName = defaultTextEditor.getId(); } if (null != editorName) { LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'."); } } } } registry.saveAssociations(); PrefUtil.savePrefs(); }
/** * Prompts the user for whether to switch perspectives. * * @param window * The workbench window in which to switch perspectives; must not * be <code>null</code> * @param finalPersp * The perspective to switch to; must not be <code>null</code>. * * @return <code>true</code> if it's OK to switch, <code>false</code> * otherwise */ private static boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDescriptor finalPersp) { IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); String pspm = store.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); if (!IDEInternalPreferences.PSPM_PROMPT.equals(pspm)) { // Return whether or not we should always switch return IDEInternalPreferences.PSPM_ALWAYS.equals(pspm); } String desc = finalPersp.getDescription(); String message; if (desc == null || desc.length() == 0) message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessage, finalPersp.getLabel()); else message = NLS.bind(ResourceMessages.NewProject_perspSwitchMessageWithDesc, new String[] { finalPersp.getLabel(), desc }); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ResourceMessages.NewProject_perspSwitchTitle, message, null /* use the default message for the toggle */, false /* toggle is initially unchecked */, store, IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE); int result = dialog.getReturnCode(); // If we are not going to prompt anymore propogate the choice. if (dialog.getToggleState()) { String preferenceValue; if (result == IDialogConstants.YES_ID) { // Doesn't matter if it is replace or new window // as we are going to use the open perspective setting preferenceValue = IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE; } else { preferenceValue = IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE; } // update PROJECT_OPEN_NEW_PERSPECTIVE to correspond PrefUtil.getAPIPreferenceStore().setValue(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE, preferenceValue); } return result == IDialogConstants.YES_ID; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IResource resource = getFromActiveEditor(event); if(resource == null){ resource = getFromSelection(event); } if(resource == null){ resource = ResourcesPlugin.getWorkspace().getRoot(); } String hint = "To unlock, create empty stopLockJob file in " + System.getProperty("user.home") + " directory or cancel the lock job!"; boolean confirm = MessageDialog.openConfirm( HandlerUtil.getActiveShell(event), "Confirm lock", "Lock " + resource + "?" + "\n " + hint); if (confirm) { System.out.println(hint); IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if(window != null){ try { PrefUtil.getAPIPreferenceStore().setValue(IWorkbenchPreferenceConstants.SHOW_SYSTEM_JOBS, true); window.getActivePage().showView(IPageLayout.ID_PROGRESS_VIEW); } catch (PartInitException e) { // ignore } } LockJob job = new LockJob("Locking " + resource, resource); job.schedule(); } return null; }
public static IPreferenceStore getApiPrefStore() { IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); return apiStore; }
@Test public void testAddBinding() throws Exception { command1 = commandManager.getCommand("aa"); final Binding binding = createBinding(command1, BINDING_CONTEXT_ID, KeySequence.getInstance("M1+A")); MKeyBinding keyBinding = helper.addBinding(binding); assertNull(keyBinding); final List<MCommand> commands = new ArrayList<MCommand>(); commands.add(createCommand("aa")); commands.add(createCommand("bb")); when(application.getCommands()).thenReturn(commands); when(application.getBindingTables()).thenReturn(Arrays.asList(bindingTable)); bindingTable.setBindingContext(TestBindingContext.createBindingContext(BINDING_CONTEXT_ID)); final TestKeyBinding keyBinding1 = new TestKeyBinding(); keyBinding1.setElementId("cc"); keyBinding1.getTransientData().put(EBindingService.MODEL_TO_BINDING_KEY, binding); final TestCommand mcmd = new TestCommand(); mcmd.setElementId("bb"); keyBinding1.setCommand(mcmd); ((TestBindingTable) bindingTable).addBinding(keyBinding1); keyBinding = helper.addBinding(binding); assertEquals(keyBinding1, keyBinding); assertNull(keyBinding.getTags()); command2 = commandManager.getCommand("bb"); final Binding binding2 = createBinding(command2, BINDING_CONTEXT_ID, KeySequence.getInstance("M1+1")); // --- PrefUtil.setUICallback(new PrefUtil.ICallback() { @Override public IPreferenceStore getPreferenceStore() { return new ScopedPreferenceStore(DefaultScope.INSTANCE, "test"); } @Override public void savePreferences() { // do nothing } }); keyBinding = helper.addBinding(binding2); assertEquals(KeySequence.getInstance("M1+1").toString(), keyBinding.getKeySequence()); assertEquals(1, keyBinding.getTags().size()); assertEquals("schemeId:default", keyBinding.getTags().get(0)); // back to default final Set<String> defaultCtx = new HashSet<String>(1); defaultCtx.add(BINDING_CONTEXT_ID); helper.setDefault(defaultCtx); }