Example usage for org.eclipse.jface.layout GridLayoutFactory margins

List of usage examples for org.eclipse.jface.layout GridLayoutFactory margins

Introduction

In this page you can find the example usage for org.eclipse.jface.layout GridLayoutFactory margins.

Prototype

public GridLayoutFactory margins(int width, int height) 

Source Link

Document

Sets the margins for layouts created with this factory.

Usage

From source file:com.twinsoft.convertigo.eclipse.editors.connector.htmlconnector.XpathEvaluatorComposite.java

License:Open Source License

protected void initialize() {
    GridLayoutFactory gdf = GridLayoutFactory.swtDefaults();
    gdf.margins(1, 1).spacing(1, 1).equalWidth(false);

    setLayout(gdf.numColumns(2).create());
    //TODO:setBackground(new Color(Display.getDefault(),255,0,121));

    Composite buttons = new Composite(this, SWT.NONE);
    buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_END));

    String[] buttonsDefNames = new String[] { "name", "tooltip", "disable_msg", "image_url", "other" };
    String[][][] buttonsDefinition = getButtonsDefinition();
    int numButtonsDefinition = buttonsDefinition.length;
    String[][][] buttonsDef = new String[numButtonsDefinition + 1][][];
    for (int i = 0; i < numButtonsDefinition; i++)
        buttonsDef[i] = buttonsDefinition[i];
    buttonsDef[numButtonsDefinition] = new String[][] {
            //name         , tooltip               , disable_msg         , image_url                                                   , other
            { "calcxpath", "Evaluate Xpath", "modify the Xpath",
                    "/com/twinsoft/convertigo/eclipse/editors/images/calc_xpath.png", null },
            { "backward", "Backward Xpath history", null,
                    "/com/twinsoft/convertigo/eclipse/editors/images/backward_history.png", null },
            { "forward", "Forward Xpath history", null,
                    "/com/twinsoft/convertigo/eclipse/editors/images/forward_history.png", null },
            { "anchor", "Set anchor", "evaluate the Xpath",
                    "/com/twinsoft/convertigo/eclipse/editors/images/anchor.png", null } };

    SelectionListener listener = new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        }//from   www  .ja v  a  2s . c  om

        public void widgetSelected(SelectionEvent e) {
            boolean enable = ((Boolean) e.widget.getData("enable")).booleanValue();
            if (enable) {
                String name = (String) e.widget.getData("name");
                if (name.equals("calcxpath")) {
                    performCalcXpath();
                } else if (name.equals("backward")) {
                    moveHistory(true);
                } else if (name.equals("forward")) {
                    moveHistory(false);
                } else if (name.equals("anchor")) {
                    setAnchor(isAnchorDisabled);
                } else {
                    buttonSelected(name);
                }
            }
        }
    };

    buttons.setLayout(gdf.numColumns(buttonsDef.length).create());

    buttonsMap = new HashMap<String, Button>();
    for (int i = 0; i < buttonsDef.length; i++) {
        String[][] columnDef = buttonsDef[i];
        Composite column = new Composite(buttons, SWT.NONE);
        column.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
        column.setLayout(new FillLayout(SWT.VERTICAL));

        for (int j = 0; j < columnDef.length; j++) {
            String[] buttonDef = columnDef[j];
            Button button = new Button(column, SWT.FLAT);
            buttonsMap.put(buttonDef[0], button);
            for (int k = 0; k < buttonsDefNames.length; k++) {
                button.setData(buttonsDefNames[k], buttonDef[k]);
            }
            button.addSelectionListener(listener);
            enableButton(button, false);
        }
    }

    Composite evaluator = new Composite(this, SWT.NONE);
    evaluator.setLayoutData(new GridData(GridData.FILL_BOTH));

    evaluator.setLayout(gdf.numColumns(1).create());

    Composite evaluator_up = new Composite(evaluator, SWT.NONE);
    evaluator_up.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    evaluator_up.setLayout(gdf.numColumns(2).create());

    lab = new Label(evaluator_up, SWT.NONE);
    lab.setText("xPath");
    lab.setToolTipText(
            "ctrl+up : backward history\nctrl+down : forward history\nYou can drag the xPath edit zone to the project tree on :\n - \"Inherited screen classes\" folder to create ScreenClasses\n - \"Criterias\" folder to create Criterias\n - \"Extraction Rules\" folder to create ExtractionRules");

    xpath = new StyledText(evaluator_up, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    xpath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    xpath.setWordWrap(true);
    xpath.addVerifyKeyListener(new VerifyKeyListener() {
        public void verifyKey(VerifyEvent event) {
            if (event.stateMask == SWT.CTRL) {
                if (event.keyCode == SWT.ARROW_DOWN) {
                    moveHistory(false);
                    return;
                } else if (event.keyCode == SWT.ARROW_UP) {
                    moveHistory(true);
                    return;
                }
            }

            if (event.character == '\r') {
                event.doit = false;
                performCalcXpath();
            } else if (currentAnchor != null) {
                int anchorStart = xpath.getText().indexOf(currentAnchor);
                if (anchorStart >= 0) {
                    int caret = xpath.getCaretOffset();
                    if (caret > anchorStart && caret < anchorStart + currentAnchor.length()) {
                        event.doit = Arrays.binarySearch(allowKeyInAnchor, event.keyCode) >= 0;
                    }
                }
            }
        }
    });

    xpath.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            lastEval = null;
            refreshButtonsEnable();
        }
    });

    SashForm evaluator_down = new SashForm(evaluator, SWT.HORIZONTAL);
    evaluator_down.setLayoutData(new GridData(GridData.FILL_BOTH));

    nodesResult = new TwsDomTree(evaluator_down, SWT.MULTI);
    new TreeColumn(nodesResult.getTree(), SWT.LEFT).setText("Document");
    new TreeColumn(nodesResult.getTree(), SWT.RIGHT).setText("Value");
    nodesResult.setHeaderVisible(true);

    nodesResult.getColumn(0).setWidth(400);

    nodeData = new Text(evaluator_down, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
    nodeData.setEditable(false);

    evaluator_down.setWeights(new int[] { 70, 30 });
}