Example usage for org.eclipse.jface.preference IPreferenceStore getBoolean

List of usage examples for org.eclipse.jface.preference IPreferenceStore getBoolean

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore getBoolean.

Prototype

boolean getBoolean(String name);

Source Link

Document

Returns the current value of the boolean-valued preference with the given name.

Usage

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

/**
 * Build basic block graph diagram./*w w  w  .ja  va2s. c  o  m*/
 * 
 * @param instruction
 *            list
 * @throws IOException
 * @throws ControlFlowGraphException
 */
public static ControlFlowGraphDiagram buildBasicblockGraphDiagram(List<AbstractInstruction> instructions)
        throws ControlFlowGraphException, IOException {
    /* get preferences */
    IPreferenceStore store = ControlFlowFactoryPlugin.getDefault().getPreferenceStore();
    boolean createStartNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_START_NODE);
    boolean createExitNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_EXIT_NODE);
    boolean createBackEdge = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_BACK_EDGE);

    /* generate control flow graph */
    IDirectedGraphExt basicBlockGraph = ControlFlowGraphGenerator.generateBasicBlockGraph(instructions, null,
            createStartNode, createExitNode, createBackEdge);
    return createBasicBlockDiagram(basicBlockGraph);
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

/**
 * Build basicblock graph diagram.//from   w ww. ja va  2 s  .  c om
 * 
 * @param classPath
 *            , the class path
 * @param packageName
 *            , the name of the package
 * @param className
 *            , the name of the class
 * @param methodName
 *            , the name of the method
 * @param methodSig
 *            , the method signature
 * @throws ControlFlowGraphException
 *             , IOException, InvalidByteCodeException
 */
public static ControlFlowGraphDiagram buildBasicblockGraphDiagram(String[] classPath, String packageName,
        String className, String methodName, String methodSig) throws ControlFlowGraphException, IOException {
    /* get preferences */
    IPreferenceStore store = ControlFlowFactoryPlugin.getDefault().getPreferenceStore();

    boolean createStartNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_START_NODE);
    boolean createExitNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_EXIT_NODE);
    boolean createBackEdge = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_BACK_EDGE);

    /* generate control flow graph */
    IDirectedGraphExt basicBlockGraph = ControlFlowGraphGenerator.generateBasicBlockGraph(classPath,
            packageName, className, methodName, methodSig, createStartNode, createExitNode, createBackEdge);
    Map<String, Object> attr = basicBlockGraph.getUserObject();
    attr.put(ByteCodeConstants.NAME, className + "." + methodName + methodSig);
    return createBasicBlockDiagram(basicBlockGraph);
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

/**
 * Build sourcecode graph diagram.// w ww  .  j  a v a  2 s . c om
 * 
 * @param instruction
 *            list
 */
public static ControlFlowGraphDiagram buildSourceControlFlowDiagram(List<AbstractInstruction> instructions,
        LineNumberTableEntry[] lineNumberTable) throws ControlFlowGraphException, IOException {
    /* get preferences */
    IPreferenceStore store = ControlFlowFactoryPlugin.getDefault().getPreferenceStore();
    boolean createStartNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_START_NODE);
    boolean createExitNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_EXIT_NODE);
    boolean createBackEdge = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_BACK_EDGE);

    /* generate control flow graph */
    IDirectedGraphExt graph = ControlFlowGraphGenerator.generateSourceCodeGraph(instructions, lineNumberTable,
            createStartNode, createExitNode, createBackEdge);
    return createSourceCodeGraphDiagram(graph);
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

/**
 * Build sourcecode graph diagram./*from   ww w .  j av a 2 s  . co m*/
 * 
 * @param classPath
 *            , the class path
 * @param packageName
 *            , the name of the package
 * @param className
 *            , the name of the class
 * @param methodName
 *            , the name of the method
 * @param methodSig
 *            , the method signature
 * @throws ControlFlowGraphException
 *             , IOException, InvalidByteCodeException
 */
public static ControlFlowGraphDiagram buildSourceControlFlowDiagram(String[] classPath, String packageName,
        String className, String methodName, String methodSig) throws ControlFlowGraphException, IOException {
    /* get preferences */
    IPreferenceStore store = ControlFlowFactoryPlugin.getDefault().getPreferenceStore();
    boolean createStartNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_START_NODE);
    boolean createExitNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_EXIT_NODE);
    boolean createBackEdge = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_BACK_EDGE);

    /* generate control flow graph */
    IDirectedGraphExt graph = ControlFlowGraphGenerator.generateSourceCodeGraph(classPath, packageName,
            className, methodName, methodSig, createStartNode, createExitNode, createBackEdge);
    Map<String, Object> attr = graph.getUserObject();
    attr.put(ByteCodeConstants.NAME, className + "." + methodName + methodSig);
    return createSourceCodeGraphDiagram(graph);
}

From source file:com.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java

License:Apache License

/**
 * Starts process.//w  w  w .  j  a v  a 2 s  .co m
 * 
 * @param monitor
 * @param folder
 * @param elementName
 * @param in
 * @param graphType
 * @param exportDecorations 
 * @param exportGeometry 
 * @param exportComments 
 * @return result: OK, YES_TO_ALL, NO_TO_ALL, ERROR
 * @throws IOException
 * @throws ControlFlowGraphException
 */
private static Result generateControlFlowGraphs(IProgressMonitor monitor, final IFolder folder,
        final String elementName, final InputStream in, IGraphSpecification spec)
        throws IOException, ControlFlowGraphException {

    boolean yes_To_All = false;
    if (spec.isOverwriteAll()) {
        yes_To_All = true;
    }

    AllCodeVisitor codeVisitor = ControlFlowGraphGenerator.getClassFileVisitor(in);
    for (Map<String, Object> attr : codeVisitor.getInstructionLists()) {

        if (monitor != null && monitor.isCanceled()) {
            return Result.CANCELED;
        }

        String name = (String) attr.get(ByteCodeConstants.NAME);
        String signature = (String) attr.get(ByteCodeConstants.DESCRIPTOR);

        if (monitor != null)
            monitor.subTask(name);

        List<AbstractInstruction> instructions = (List<AbstractInstruction>) attr.get(ByteCodeConstants.CODE);

        /* get preferences */
        IPreferenceStore store = ControlFlowFactoryPlugin.getDefault().getPreferenceStore();
        boolean createStartNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_START_NODE);
        boolean createExitNode = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_EXIT_NODE);
        boolean createBackEdge = store.getBoolean(ControlFlowFactoryPreferenceConstants.GENERATE_BACK_EDGE);

        IDirectedGraphExt cfg = null;
        ControlFlowGraphDiagram diagram = null;
        LineNumberTableEntry[] lineNumberTable = null;
        Object o;
        switch (spec.getGraphType()) {
        case GraphConstants.GRAPH_TYPE_BYTECODE_GRAPH:

            o = attr.get(ByteCodeConstants.LINE_NUMBER_TABLE);

            if (o != null) {
                lineNumberTable = (LineNumberTableEntry[]) o;
            }

            cfg = ControlFlowGraphGenerator.generateControlFlowGraph(instructions, lineNumberTable,
                    createStartNode, createExitNode, createBackEdge);

            if (cfg == null) {
                // Messages.error(ControlFlowFactoryMessages.DiagramIsNullMessage);
                // return Result.ERROR;
                throw new ControlFlowGraphException(ControlFlowFactoryMessages.DiagramIsNullMessage);
            }

            diagram = createControlFlowDiagram(cfg);
            break;
        case GraphConstants.GRAPH_TYPE_BASICBLOCK_GRAPH:
            o = attr.get(ByteCodeConstants.LINE_NUMBER_TABLE);

            if (o != null) {
                lineNumberTable = (LineNumberTableEntry[]) o;
            }

            cfg = ControlFlowGraphGenerator.generateBasicBlockGraph(instructions, lineNumberTable,
                    createStartNode, createExitNode, createBackEdge);

            if (cfg == null) {
                // Messages.error(ControlFlowFactoryMessages.DiagramIsNullMessage);
                // return Result.ERROR;
                throw new ControlFlowGraphException(ControlFlowFactoryMessages.DiagramIsNullMessage);
            }

            diagram = createBasicBlockDiagram(cfg);
            break;
        case GraphConstants.GRAPH_TYPE_SOURCE_GRAPH:

            o = attr.get(ByteCodeConstants.LINE_NUMBER_TABLE);

            if (o == null) {
                // Messages.error(ControlFlowFactoryMessages.ERROR_LineNumberTable_is_Missing
                // + name + signature);
                // return Result.ERROR;
                throw new ControlFlowGraphException(
                        ControlFlowFactoryMessages.ERROR_LineNumberTable_is_Missing + name + signature);
            }

            lineNumberTable = (LineNumberTableEntry[]) o;
            cfg = ControlFlowGraphGenerator.generateSourceCodeGraph(instructions, lineNumberTable,
                    createStartNode, createExitNode, createBackEdge);

            if (cfg == null) {
                // Messages.error(ControlFlowFactoryMessages.DiagramIsNullMessage);
                // return Result.ERROR;
                throw new ControlFlowGraphException(ControlFlowFactoryMessages.DiagramIsNullMessage);
            }

            diagram = createSourceCodeGraphDiagram(cfg);
            break;
        default:
            throw new IllegalStateException("Unexpected graph type '" + spec.getGraphType() + "'");
        }

        if (diagram == null) {
            // Messages.error(ControlFlowFactoryMessages.DiagramIsNullMessage);
            // return Result.ERROR;
            throw new ControlFlowGraphException(ControlFlowFactoryMessages.DiagramIsNullMessage);
        }

        if (name.equals(ByteCodeConstants.INIT)) {
            name = "init"; //$NON-NLS-1$
        }

        if (name.equals(ByteCodeConstants.CLINIT)) {
            name = "clinit"; //$NON-NLS-1$
        }

        /* set name property */
        diagram.setPropertyValue(ByteCodeConstants.NAME, elementName + "." + name + signature);

        String fileName = elementName + "." + name + signature.replace('/', '.') + "."
                + GraphConstants.graphTypeSuffixes[spec.getGraphType()];
        IPath pathToFile = folder.getFullPath().append(fileName).addFileExtension(FileExtensions.GRAPH);

        try {
            Result r;

            switch (spec.getExportFormat()) {
            case GraphConstants.EXPORT_FORMAT_DRGARBAGE_GRAPH:
                final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(pathToFile);
                r = saveDiagram(file, diagram, monitor, yes_To_All);
                break;
            default:

                AbstractExport2 exporter = null;

                switch (spec.getExportFormat()) {
                case GraphConstants.EXPORT_FORMAT_DOT:
                    exporter = new GraphDOTExport();
                    pathToFile = pathToFile.addFileExtension(FileExtensions.DOT);
                    break;
                case GraphConstants.EXPORT_FORMAT_GRAPHXML:
                    exporter = new GraphXMLExport();
                    pathToFile = pathToFile.addFileExtension(FileExtensions.XML);
                    break;
                case GraphConstants.EXPORT_FORMAT_GRAPHML:
                    exporter = new GraphMlExport();
                    pathToFile = pathToFile.addFileExtension(FileExtensions.GRAPHML);
                    break;
                default:
                    throw new IllegalStateException("Unexpected export format.");
                }

                exporter.setGraphSpecification(spec);
                StringWriter sb = new StringWriter();
                try {
                    exporter.write(diagram, sb);
                } catch (ExportException e) {
                    /*
                     * This will never happen as StringWriter.append(*)
                     * does not throw IOException
                     */
                    throw new RuntimeException(e);
                }

                final IFile file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(pathToFile);
                r = saveContentToFile(file2, sb.toString(), monitor, yes_To_All);
            }

            if (r == Result.NO) {
                continue;
            } else if (r == Result.NO_TO_ALL) {
                return Result.NO_TO_ALL;
            } else if (r == Result.YES_TO_ALL) {
                yes_To_All = true;
            } else if (r == Result.CANCELED) {
                return Result.CANCELED;
            }

        } catch (CoreException e) {
            ControlFlowFactoryPlugin.getDefault().getLog()
                    .log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, e.getMessage(), e));
            // Messages.error(e.getMessage() +
            // CoreMessages.ExceptionAdditionalMessage);
            return Result.ERROR;
        }

    }

    if (yes_To_All) {
        return Result.YES_TO_ALL;
    }

    return Result.OK;
}

From source file:com.dubture.pdt.formatter.IndentGuidePainter.java

License:Open Source License

/**
 * Creates a new painter for the given text viewer.
 * // w ww  .  ja va  2  s  .co m
 * @param textViewer
 *            the text viewer the painter should be attached to
 */
public IndentGuidePainter(ITextViewer textViewer) {
    super();
    fTextViewer = textViewer;
    fTextWidget = textViewer.getTextWidget();
    GC gc = new GC(fTextWidget);
    gc.setAdvanced(true);
    fIsAdvancedGraphicsPresent = gc.getAdvanced();
    gc.dispose();

    IPreferenceStore store = FormatterPlugin.getDefault().getPreferenceStore();
    lineAlpha = store.getInt(PreferenceConstants.LINE_ALPHA);
    lineStyle = store.getInt(PreferenceConstants.LINE_STYLE);
    lineWidth = store.getInt(PreferenceConstants.LINE_WIDTH);
    lineShift = store.getInt(PreferenceConstants.LINE_SHIFT);
    drawLeftEnd = store.getBoolean(PreferenceConstants.DRAW_LEFT_END);
    drawBlankLine = store.getBoolean(PreferenceConstants.DRAW_BLANK_LINE);
    skipCommentBlock = store.getBoolean(PreferenceConstants.SKIP_COMMENT_BLOCK);
}

From source file:com.dubture.twig.ui.editor.autoEdit.CloseTagAutoEditStrategyTwig.java

License:Open Source License

/**
 * Automatically create a twig statement tag and insert the cursor in the
 * middle./*from w ww  .  ja v a 2s .  co  m*/
 * 
 * <pre>
 * 
 *   {% | %}
 * </pre>
 * 
 */
private boolean autoCreateStatementTag(IDOMNode node) {

    IPreferenceStore store = TwigUICorePlugin.getDefault().getPreferenceStore();
    boolean autocreate = store.getBoolean(PreferenceConstants.AUTOCREATE_STATEMENT_TAGS);

    if (autocreate == false || node == null)
        return true;

    command.text = "{%  %}"; //$NON-NLS-1$
    command.shiftsCaret = false;
    command.caretOffset = command.offset + 3;
    command.doit = false;

    return true;

}

From source file:com.dubture.twig.ui.editor.autoEdit.CloseTagAutoEditStrategyTwig.java

License:Open Source License

/**
 * Automatically close an open twig statement tag and insert the cursor in
 * the middle./*from   ww  w.j  av  a  2s . co  m*/
 * 
 * <pre>
 * 
 *     {|   <-- type "%" and get
 * 
 *   {% | %}
 * 
 * </pre>
 * 
 */
private boolean autoCloseStatementTag(IDOMNode node) {

    IPreferenceStore store = TwigUICorePlugin.getDefault().getPreferenceStore();
    boolean autoclose = store.getBoolean(PreferenceConstants.AUTOCLOSE_STATEMENT_TAGS);

    if (autoclose == false || node == null)
        return true;

    // command.text += "%"; //$NON-NLS-1$
    // command.shiftsCaret = false;
    // command.caretOffset = command.offset + 1;
    // command.doit = false;

    command.text += "  %"; //$NON-NLS-1$
    command.shiftsCaret = false;
    command.caretOffset = command.offset + 2;
    command.doit = false;

    return true;

}

From source file:com.dubture.twig.ui.editor.autoEdit.CloseTagAutoEditStrategyTwig.java

License:Open Source License

/**
 * Automatically close an open twig print tag and insert the cursor in the
 * middle./*from   w  w  w  .j a v  a  2 s  .  co m*/
 * 
 * <pre>
 * 
 *     {|   <-- type "{" and get
 * 
 *   {{ | }}
 * 
 * </pre>
 * 
 */
private void autoClosePrintTag(IDOMNode node) {

    IPreferenceStore store = TwigUICorePlugin.getDefault().getPreferenceStore();
    boolean autoclose = store.getBoolean(PreferenceConstants.AUTOCLOSE_PRINT_TAGS);

    if (autoclose == false)
        return;

    String append = "}"; //$NON-NLS-1$
    int caretOffset = 1;

    if (node != null) {

        if (prefixedWith(document, command.offset, "{")) {
            append = "  }";
            caretOffset = 2;
        }

        command.text += append;
        command.shiftsCaret = false;
        command.caretOffset = command.offset + caretOffset;
        command.doit = false;

        // empty document
    } else {
        command.text += append;
        command.shiftsCaret = false;
        command.caretOffset = command.offset + caretOffset;
        command.doit = false;

    }
}

From source file:com.dubture.twig.ui.editor.folding.StructuredTextFoldingProviderTwig.java

License:Open Source License

private void initializePreferences() {
    IPreferenceStore store = PHPUiPlugin.getDefault().getPreferenceStore();
    // fCollapseImportContainer=
    // store.getBoolean(PreferenceConstants.EDITOR_FOLDING_IMPORTS);
    fCollapseTypes = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_CLASSES);
    fCollapsePhpdoc = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_PHPDOC);
    fCollapseMembers = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_FUNCTIONS);
    fCollapseHeaderComments = store.getBoolean(PreferenceConstants.EDITOR_FOLDING_HEADER_COMMENTS);
}