Search in sources :

Example 1 with IPersistentPreferenceStore

use of org.eclipse.jface.preference.IPersistentPreferenceStore in project eclipse.platform.text by eclipse.

the class TemplateStore method save.

/**
 * Saves the templates to the preferences.
 *
 * @throws IOException if the templates cannot be written
 */
public void save() throws IOException {
    ArrayList<TemplatePersistenceData> custom = new ArrayList<>();
    for (TemplatePersistenceData data : fTemplates) {
        if (// don't save deleted user-added templates
        data.isCustom() && !(data.isUserAdded() && data.isDeleted()))
            custom.add(data);
    }
    StringWriter output = new StringWriter();
    TemplateReaderWriter writer = new TemplateReaderWriter();
    writer.save(custom.toArray(new TemplatePersistenceData[custom.size()]), output);
    fIgnorePreferenceStoreChanges = true;
    try {
        fPreferenceStore.setValue(fKey, output.toString());
        if (fPreferenceStore instanceof IPersistentPreferenceStore)
            ((IPersistentPreferenceStore) fPreferenceStore).save();
    } finally {
        fIgnorePreferenceStoreChanges = false;
    }
}
Also used : StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Example 2 with IPersistentPreferenceStore

use of org.eclipse.jface.preference.IPersistentPreferenceStore in project abstools by abstools.

the class FileAddLocationHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    Object firstElement = selection.getFirstElement();
    if (firstElement instanceof IFile) {
        IFile file = (IFile) firstElement;
        IProject project = file.getProject();
        AbsNature nature = UtilityFunctions.getAbsNature(project);
        if (nature == null)
            return null;
        IPersistentPreferenceStore projectStore = nature.getProjectPreferenceStore();
        boolean locationTypecheckingEnabled = projectStore.getBoolean(Constants.LOCATION_TYPECHECK);
        if (!locationTypecheckingEnabled) {
            MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Locationtypechecking", "Location type checking is disabled. Please enable for this function to work!");
            return null;
        }
        UtilityFunctions.saveEditor(file, false);
        Map<LocationTypeVariable, LocationType> locationTypeInferrerResult = nature.getLocationTypeInferrerResult();
        if (locationTypeInferrerResult != null) {
            Map<LocationTypeVariable, LocationType> filteredResults = new HashMap<LocationTypeVariable, LocationType>();
            ASTNode<?> node;
            CompilationUnit cu;
            for (Entry<LocationTypeVariable, LocationType> entry : locationTypeInferrerResult.entrySet()) {
                node = entry.getKey().getNode();
                if (node == null)
                    continue;
                cu = node.getCompilationUnit();
                if (cu == null)
                    continue;
                if (file.getLocation().toFile().getAbsolutePath().equals(cu.getFileName())) {
                    filteredResults.put(entry.getKey(), entry.getValue());
                }
            }
            InferMain inferMain = new InferMain();
            String commandId = event.getCommand().getId();
            if ("org.abs-models.abs.plugin.fileaddalllocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.values());
            } else if ("org.abs-models.abs.plugin.fileaddclasslocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.CLASSES);
            } else if ("org.abs-models.abs.plugin.fileaddfieldlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FIELDS);
            } else if ("org.abs-models.abs.plugin.fileaddfunctionlocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.FUNCTIONS);
            } else if ("org.abs-models.abs.plugin.fileaddinterfacelocations".equals(commandId)) {
                inferMain.setConfig(InferMain.Config.INTERFACES);
            }
            try {
                inferMain.writeInferenceResultsBack(filteredResults);
                try {
                    file.refreshLocal(IResource.DEPTH_INFINITE, null);
                } catch (CoreException e) {
                    Activator.logException(e);
                }
            } catch (IOException e) {
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Error while inserting locations", "An error occurred while inserting locations!\n" + e.getLocalizedMessage());
            }
        }
    }
    return null;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) IFile(org.eclipse.core.resources.IFile) InferMain(abs.frontend.typechecker.locationtypes.infer.InferMain) HashMap(java.util.HashMap) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) LocationTypeVariable(abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable) CoreException(org.eclipse.core.runtime.CoreException) LocationType(abs.frontend.typechecker.locationtypes.LocationType) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 3 with IPersistentPreferenceStore

use of org.eclipse.jface.preference.IPersistentPreferenceStore in project n4js by eclipse.

the class AbstractN4JSPreferencePage method performOk.

@Override
public boolean performOk() {
    IWorkbenchPreferenceContainer container = (IWorkbenchPreferenceContainer) getContainer();
    if (!processChanges(container)) {
        return false;
    }
    boolean retVal = super.performOk();
    if (retVal && isProjectPreferencePage()) {
        try {
            IPreferenceStore preferenceStore = preferenceStoreAccessImpl.getWritablePreferenceStore(getProject());
            if (preferenceStore instanceof IPersistentPreferenceStore) {
                ((IPersistentPreferenceStore) preferenceStore).save();
            }
        } catch (Exception e) {
            System.err.println(e);
            retVal = false;
        }
    }
    return retVal;
}
Also used : IWorkbenchPreferenceContainer(org.eclipse.ui.preferences.IWorkbenchPreferenceContainer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 4 with IPersistentPreferenceStore

use of org.eclipse.jface.preference.IPersistentPreferenceStore in project egit by eclipse.

the class RebaseInteractiveView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);
    final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
        }
    });
    form = createForm(parent, toolkit);
    createCommandToolBar(form, toolkit);
    planTreeViewer = createPlanTreeViewer(form.getBody(), toolkit);
    planLayout = new PlanLayout();
    planTreeViewer.getTree().getParent().setLayout(planLayout);
    createColumns(planLayout);
    createStepActionToolBar(toolkit);
    createPopupMenu(planTreeViewer);
    setupListeners();
    createLocalDragandDrop();
    planTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            PlanElement element = (PlanElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (element == null)
                return;
            RepositoryCommit commit = loadCommit(element.getCommit());
            if (commit != null)
                CommitEditor.openQuiet(commit);
        }

        private RepositoryCommit loadCommit(AbbreviatedObjectId abbreviatedObjectId) {
            if (abbreviatedObjectId != null) {
                try (RevWalk walk = new RevWalk(RebaseInteractiveView.this.currentRepository)) {
                    Collection<ObjectId> resolved = walk.getObjectReader().resolve(abbreviatedObjectId);
                    if (resolved.size() == 1) {
                        RevCommit commit = walk.parseCommit(resolved.iterator().next());
                        return new RepositoryCommit(RebaseInteractiveView.this.currentRepository, commit);
                    }
                } catch (IOException e) {
                    return null;
                }
            }
            return null;
        }
    });
    prefListener = new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
                return;
            }
            final Repository repo = currentRepository;
            if (repo == null)
                return;
            if (Activator.getDefault().getRepositoryUtil().contains(repo))
                return;
            // Unselect repository as it has been removed
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    currentRepository = null;
                    showRepository(null);
                }
            });
        }
    };
    InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
    uiPrefsListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property) || UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(property)) {
                refresh();
            }
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbar = actionBars.getToolBarManager();
    listenOnRepositoryViewSelection = RebaseInteractivePreferences.isReactOnSelection();
    // link with selection
    Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, UIText.InteractiveRebaseView_LinkSelection) {

        @Override
        public void apply(boolean value) {
            listenOnRepositoryViewSelection = value;
        }
    };
    linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
    toolbar.add(linkSelectionAction);
    switchRepositoriesAction = new RepositoryToolbarAction(false, () -> currentRepository, repo -> setInput(new StructuredSelection(repo)));
    toolbar.add(switchRepositoriesAction);
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, getSite());
    getSite().setSelectionProvider(new RepositorySelectionProvider(planTreeViewer, () -> currentRepository));
}
Also used : AdapterUtils(org.eclipse.egit.core.AdapterUtils) UIPreferences(org.eclipse.egit.ui.UIPreferences) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DND(org.eclipse.swt.dnd.DND) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) RepositoryState(org.eclipse.jgit.lib.RepositoryState) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ProcessStepsRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ProcessStepsRebaseCommand) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IEditorPart(org.eclipse.ui.IEditorPart) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) ToolItem(org.eclipse.swt.widgets.ToolItem) AbstractRebaseCommandHandler(org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) Transfer(org.eclipse.swt.dnd.Transfer) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) UIText(org.eclipse.egit.ui.internal.UIText) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) SWT(org.eclipse.swt.SWT) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) ElementType(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementType) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) ViewPart(org.eclipse.ui.part.ViewPart) RevCommit(org.eclipse.jgit.revwalk.RevCommit) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Format(org.eclipse.jgit.util.GitDateFormatter.Format) JFaceResources(org.eclipse.jface.resource.JFaceResources) RebaseInteractivePlan(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Font(org.eclipse.swt.graphics.Font) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IViewSite(org.eclipse.ui.IViewSite) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) IActionBars(org.eclipse.ui.IActionBars) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) Form(org.eclipse.ui.forms.widgets.Form) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) ToolTip(org.eclipse.jface.window.ToolTip) Repository(org.eclipse.jgit.lib.Repository) ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) ToolBar(org.eclipse.swt.widgets.ToolBar) IToolBarManager(org.eclipse.jface.action.IToolBarManager) SWTKeySupport(org.eclipse.jface.bindings.keys.SWTKeySupport) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) GC(org.eclipse.swt.graphics.GC) ISelectionListener(org.eclipse.ui.ISelectionListener) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Collection(java.util.Collection) GitDateFormatter(org.eclipse.jgit.util.GitDateFormatter) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) List(java.util.List) Tree(org.eclipse.swt.widgets.Tree) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) UIIcons(org.eclipse.egit.ui.internal.UIIcons) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ContinueRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ContinueRebaseCommand) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) TreeItem(org.eclipse.swt.widgets.TreeItem) ObjectId(org.eclipse.jgit.lib.ObjectId) IResource(org.eclipse.core.resources.IResource) UIUtils(org.eclipse.egit.ui.UIUtils) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) RepositoriesView(org.eclipse.egit.ui.internal.repository.RepositoriesView) Control(org.eclipse.swt.widgets.Control) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand) DisposeListener(org.eclipse.swt.events.DisposeListener) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) IAction(org.eclipse.jface.action.IAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) Action(org.eclipse.jface.action.Action) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IActionBars(org.eclipse.ui.IActionBars) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) Repository(org.eclipse.jgit.lib.Repository) IToolBarManager(org.eclipse.jface.action.IToolBarManager) Collection(java.util.Collection) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction)

Example 5 with IPersistentPreferenceStore

use of org.eclipse.jface.preference.IPersistentPreferenceStore in project egit by eclipse.

the class GitDecoratorPreferencePage method performOk.

/**
 * OK was clicked. Store the preferences to the plugin store
 *
 * @return whether it is okay to close the preference page
 */
@Override
public boolean performOk() {
    IPreferenceStore store = getPreferenceStore();
    final boolean okToClose = performOk(store);
    if (store.needsSaving()) {
        try {
            ((IPersistentPreferenceStore) store).save();
            Activator.broadcastPropertyChange(new PropertyChangeEvent(this, Activator.DECORATORS_CHANGED, null, null));
        } catch (IOException e) {
            Activator.handleError(e.getMessage(), e, true);
        }
    }
    return okToClose;
}
Also used : PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IOException(java.io.IOException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Aggregations

IPersistentPreferenceStore (org.eclipse.jface.preference.IPersistentPreferenceStore)14 IOException (java.io.IOException)8 CoreException (org.eclipse.core.runtime.CoreException)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 LocationType (abs.frontend.typechecker.locationtypes.LocationType)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 BooleanPrefAction (org.eclipse.egit.ui.internal.actions.BooleanPrefAction)3 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)2 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)2 Collection (java.util.Collection)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 Action (org.eclipse.jface.action.Action)2 IAction (org.eclipse.jface.action.IAction)2