Search in sources :

Example 66 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project org.csstudio.display.builder by kasemir.

the class Preferences method getCacheTimeout.

/**
 * @return Cache timeout [sec]
 */
public static int getCacheTimeout() {
    int timeout = 60;
    final IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs != null)
        timeout = prefs.getInt(ModelPlugin.ID, CACHE_TIMEOUT, timeout, null);
    return timeout;
}
Also used : IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 67 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project liferay-ide by liferay.

the class PortalCore method getPreference.

public static String getPreference(String key) {
    IScopeContext[] scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };
    IPreferencesService preferencesService = Platform.getPreferencesService();
    return preferencesService.getString(PLUGIN_ID, key, null, scopes);
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 68 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ReconcilingStrategy method reconcileSyntax.

/**
 * Activates incremental reconciling of the syntax of the specified
 * dirty region.
 *
 * @param dirtyRegion
 *                the document region which has been changed
 */
public void reconcileSyntax(final DirtyRegion dirtyRegion) {
    double parserStart = System.nanoTime();
    if (document == null) {
        return;
    }
    int lineBreaks = 0;
    try {
        if (DirtyRegion.INSERT.equals(dirtyRegion.getType())) {
            lineBreaks = calculateLineBreaks(dirtyRegion.getText(), delimeters);
            actualCode.insert(dirtyRegion.getOffset(), dirtyRegion.getText());
        } else {
            lineBreaks = calculateLineBreaks(actualCode.substring(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength()), delimeters);
            actualCode.delete(dirtyRegion.getOffset(), dirtyRegion.getOffset() + dirtyRegion.getLength());
        }
    } catch (StringIndexOutOfBoundsException e) {
        ErrorReporter.logExceptionStackTrace(e);
        ErrorReporter.logError("String length: " + actualCode.length() + " region type: " + dirtyRegion.getType() + " region offset: " + dirtyRegion.getOffset() + " region length: " + dirtyRegion.getLength() + " region text: '" + dirtyRegion.getText() + "'\n" + "Actual size of the document: " + document.get().length());
        actualCode = new StringBuilder(document.get());
    }
    if (dirtyRegion.getOffset() == 0 && editor != null && document.getLength() == dirtyRegion.getLength()) {
        // thing
        if (!editor.isDirty()) {
            return;
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
            analyze(false);
        }
        return;
    }
    int firstLine;
    try {
        firstLine = document.getLineOfOffset(dirtyRegion.getOffset());
    } catch (BadLocationException e) {
        ErrorReporter.logWarningExceptionStackTrace(e);
        ErrorReporter.logWarning("Offset became invalid, fallback method used. Document length: " + document.getLength() + " region offset: " + dirtyRegion.getOffset());
        firstLine = 0;
    }
    final IFile editedFile = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (editedFile == null || ResourceExclusionHelper.isExcluded(editedFile)) {
        return;
    }
    final TTCN3ReparseUpdater reparser;
    int length = dirtyRegion.getLength();
    if (DirtyRegion.REMOVE.equals(dirtyRegion.getType())) {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, -1 * lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset() + length, -1 * length);
    } else {
        reparser = new TTCN3ReparseUpdater(editedFile, actualCode.toString(), firstLine + 1, lineBreaks, dirtyRegion.getOffset(), dirtyRegion.getOffset(), length);
    }
    final IProject project = editedFile.getProject();
    if (project == null) {
        return;
    }
    if (lastIncrementalSyntaxCheck != null) {
        try {
            lastIncrementalSyntaxCheck.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    lastIncrementalSyntaxCheck = sourceParser.updateSyntax(editedFile, reparser);
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    if (store.getBoolean(PreferenceConstants.DISPLAYDEBUGINFORMATION)) {
        TITANDebugConsole.println("Refreshing the syntax took " + (System.nanoTime() - parserStart) * (1e-9) + " secs");
    }
    WorkspaceJob op = new WorkspaceJob(FOLDING_UPDATE) {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    // TODO optimize for incremental
                    // usage
                    List<Position> positions = (new TTCN3FoldingSupport()).calculatePositions(getDocument());
                    getEditor().updateFoldingStructure(positions);
                }
            });
            return Status.OK_STATUS;
        }
    };
    op.setPriority(Job.LONG);
    op.setSystem(true);
    op.setUser(false);
    op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
    op.setRule(editedFile);
    op.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TTCN3ReparseUpdater(org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 69 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class TTCN3Editor method isSemanticCheckingDelayed.

public static boolean isSemanticCheckingDelayed() {
    IPreferencesService prefs = Platform.getPreferencesService();
    boolean delayedSemanticChecking = prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DELAYSEMANTICCHECKINGTILLSAVE, false, null);
    return delayedSemanticChecking;
}
Also used : IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 70 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

// FIXME add semantic check guard on project level.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    if (editor == null) {
        return new ICompletionProposal[] {};
    }
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
        return new ICompletionProposal[] {};
    }
    IDocument doc = viewer.getDocument();
    TTCN3ReferenceParser refParser = new TTCN3ReferenceParser(true);
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    String moduleName = null;
    if (tempModule != null) {
        moduleName = tempModule.getName();
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    TemplateContextType contextType = new TemplateContextType(TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, TTCN3CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_TTCN, TTCN3CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    propCollector.setProjectParser(projectSourceParser);
    if (moduleName == null) {
        // rootless behavior
        if (ref.getModuleIdentifier() == null) {
            Set<String> moduleNames = projectSourceParser.getKnownModuleNames();
            Module module;
            for (String name : moduleNames) {
                module = projectSourceParser.getModuleByName(name);
                if (module != null) {
                    propCollector.addProposal(name, name, ImageCache.getImage("ttcn.gif"), TTCN3Module.MODULE);
                    module.getAssignments().addProposal(propCollector);
                }
            }
        } else {
            Module module = projectSourceParser.getModuleByName(ref.getModuleIdentifier().getName());
            if (module != null) {
                module.getAssignments().addProposal(propCollector);
            }
        }
    } else {
        /*
			 * search for the best scope in the module's scope
			 * hierarchy and call proposal adding function on the
			 * found scope instead of what can be found here
			 */
        if (scope != null) {
            scope.addProposal(propCollector);
        }
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getSubreferences().size() != 1) {
        if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
            propCollector.sortAll();
        }
        return propCollector.getCompletitions();
    }
    Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
    for (String knownModuleName : knownModuleNames) {
        Identifier tempIdentifier = new Identifier(Identifier_type.ID_NAME, knownModuleName);
        Module tempModule2 = projectSourceParser.getModuleByName(knownModuleName);
        propCollector.addProposal(tempIdentifier, ImageCache.getImage(tempModule2.getOutlineIcon()), "module");
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    if (ref.getModuleIdentifier() == null) {
        if (scope == null) {
            TTCN3CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        } else {
            scope.addSkeletonProposal(propCollector);
        }
        propCollector.addTemplateProposal("refers", new Template("refers( function/altstep/testcase name )", "", propCollector.getContextIdentifier(), "refers( ${fatName} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.addTemplateProposal("derefers", new Template("derefers( function/altstep/testcase name )(parameters)", "", propCollector.getContextIdentifier(), "derefers( ${fatName} ) ( ${parameters} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
        propCollector.sortTillMarked();
        propCollector.markPosition();
        TTCN3CodeSkeletons.addPredefinedSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
        if (scope == null) {
            TTCN3Keywords.addKeywordProposals(propCollector);
        } else {
            scope.addKeywordProposal(propCollector);
        }
        propCollector.sortTillMarked();
        propCollector.markPosition();
    } else {
        if (scope == null || !(scope instanceof StatementBlock)) {
            if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
                propCollector.sortAll();
            }
            return propCollector.getCompletitions();
        }
        String fakeModule = ref.getModuleIdentifier().getName();
        if ("any component".equals(fakeModule) || "all component".equals(fakeModule)) {
            Component_Type.addAnyorAllProposal(propCollector, 0);
        } else if ("any port".equals(fakeModule) || "all port".equals(fakeModule)) {
            PortTypeBody.addAnyorAllProposal(propCollector, 0);
        } else if ("any timer".equals(fakeModule) || "all timer".equals(fakeModule)) {
            Timer.addAnyorAllProposal(propCollector, 0);
        }
    }
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : IFile(org.eclipse.core.resources.IFile) Reference(org.eclipse.titan.designer.AST.Reference) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) Template(org.eclipse.jface.text.templates.Template) ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

Aggregations

IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)96 IFile (org.eclipse.core.resources.IFile)26 ArrayList (java.util.ArrayList)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)13 Module (org.eclipse.titan.designer.AST.Module)11 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 List (java.util.List)10 File (java.io.File)8 TextSelection (org.eclipse.jface.text.TextSelection)8 Path (org.eclipse.core.runtime.Path)6 IContainer (org.eclipse.core.resources.IContainer)5 IMarker (org.eclipse.core.resources.IMarker)5 IPath (org.eclipse.core.runtime.IPath)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 IOException (java.io.IOException)4 IStatus (org.eclipse.core.runtime.IStatus)4