Search in sources :

Example 66 with ControlListener

use of org.eclipse.swt.events.ControlListener in project balzac by balzac-lang.

the class TrustedNodesPreferences method createNetworkContents.

private void createNetworkContents(Composite parent, boolean testnet) {
    Group group = new Group(parent, SWT.NONE);
    group.setText(testnet ? " Testnet node " : " Mainnet node ");
    GridLayout gl_grpTestnet = new GridLayout(2, false);
    gl_grpTestnet.marginTop = 5;
    gl_grpTestnet.marginRight = 5;
    gl_grpTestnet.marginLeft = 5;
    gl_grpTestnet.marginBottom = 5;
    group.setLayout(gl_grpTestnet);
    Label hostLabel = new Label(group, SWT.NONE);
    hostLabel.setText("Host");
    Text hostText = new Text(group, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label lblPort = new Label(group, SWT.NONE);
    lblPort.setText("Port");
    Spinner portSpinner = new Spinner(group, SWT.BORDER);
    portSpinner.setMaximum(65535);
    portSpinner.setMinimum(1);
    GridData gd_portSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_portSpinner.heightHint = 19;
    gd_portSpinner.widthHint = 163;
    portSpinner.setLayoutData(gd_portSpinner);
    Label lblHttpsButton = new Label(group, SWT.NONE);
    lblHttpsButton.setText("Https");
    Button httpsCheckbox = new Button(group, SWT.CHECK);
    httpsCheckbox.setToolTipText("Recommended if the server accepts SSL connections");
    Label usernameLabel = new Label(group, SWT.NONE);
    usernameLabel.setText("Username");
    Text usernameText = new Text(group, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    Label urlLabel = new Label(group, SWT.NONE);
    urlLabel.setText("URL");
    Text urlText = new Text(group, SWT.BORDER);
    urlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    urlText.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            String text = urlText.getText();
            if (!text.startsWith("/"))
                urlText.setText("/" + text);
        }

        @Override
        public void focusGained(FocusEvent e) {
        }
    });
    Label testnetPasswordLabel = new Label(group, SWT.NONE);
    testnetPasswordLabel.setText("Password");
    Text passwordText = new Text(group, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label timeoutLabel = new Label(group, SWT.NONE);
    timeoutLabel.setText("Timeout");
    Spinner timeoutSpinner = new Spinner(group, SWT.BORDER);
    timeoutSpinner.setMaximum(Integer.MAX_VALUE);
    timeoutSpinner.setMinimum(-1);
    timeoutSpinner.setToolTipText("Set -1 for undefined waiting time (not recommended)");
    GridData gd_timeoutSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_timeoutSpinner.heightHint = 19;
    gd_timeoutSpinner.widthHint = 163;
    timeoutSpinner.setLayoutData(gd_timeoutSpinner);
    // test button with feedbacks
    Composite compositeBtnTest = new Composite(group, SWT.NONE);
    compositeBtnTest.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    GridLayout gl_composite = new GridLayout(2, false);
    gl_composite.horizontalSpacing = 10;
    gl_composite.marginWidth = 0;
    compositeBtnTest.setLayout(gl_composite);
    Button btnTestConnection = new Button(compositeBtnTest, SWT.NONE);
    btnTestConnection.setText("Test");
    Composite compositeFeedbacks = new Composite(compositeBtnTest, SWT.NONE);
    Canvas networkFeedbackOK = new Canvas(compositeFeedbacks, SWT.NONE);
    networkFeedbackOK.setBounds(0, 0, 16, 16);
    networkFeedbackOK.setBackgroundImage(imageSuccess);
    networkFeedbackOK.setVisible(false);
    Canvas networkFeedbackERR = new Canvas(compositeFeedbacks, SWT.NONE);
    networkFeedbackERR.setBounds(0, 0, 16, 16);
    networkFeedbackERR.setBackgroundImage(imageError);
    networkFeedbackERR.setVisible(false);
    // error details
    Composite errorDetailsComposite = new Composite(group, SWT.BORDER);
    StyledText errorDetailsTextArea = new StyledText(errorDetailsComposite, SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
    GridData gd_errorDetailsTextArea = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    gd_errorDetailsTextArea.grabExcessVerticalSpace = true;
    errorDetailsComposite.setLayoutData(gd_errorDetailsTextArea);
    errorDetailsComposite.setBackground(errorDetailsTextArea.getBackground());
    errorDetailsTextArea.setAlwaysShowScrollBars(false);
    errorDetailsComposite.addControlListener(new ControlListener() {

        private int TOP_MARGIN = 4;

        private int LEFT_MARGIN = 8;

        @Override
        public void controlResized(ControlEvent e) {
            Composite parent = errorDetailsTextArea.getParent();
            errorDetailsTextArea.setBounds(LEFT_MARGIN, TOP_MARGIN, parent.getSize().x - 2 * parent.getBorderWidth() - LEFT_MARGIN, parent.getSize().y - 2 * parent.getBorderWidth() - TOP_MARGIN);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        }
    });
    btnTestConnection.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            errorDetailsTextArea.setText("");
            networkFeedbackOK.setVisible(false);
            networkFeedbackERR.setVisible(false);
        }

        @Override
        public void mouseUp(MouseEvent e) {
            String address = hostText.getText();
            Integer port = portSpinner.getSelection();
            String protocol = httpsCheckbox.getSelection() ? "https" : "http";
            String url = urlText.getText();
            String user = usernameText.getText();
            String password = passwordText.getText();
            Integer timeout = timeoutSpinner.getSelection();
            if (password.isEmpty()) {
                try {
                    if (testnet)
                        password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__TESTNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__TESTNET_PASSWORD, "");
                    else
                        password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__MAINNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__MAINNET_PASSWORD, "");
                } catch (StorageException e1) {
                    e1.printStackTrace();
                    errorDetailsTextArea.append("Error fetching the password from the secure store.\n\n");
                    errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
                    networkFeedbackERR.setVisible(true);
                    return;
                }
            }
            RPCBitcoinClient bitcoinClient = new RPCBitcoinClient(address, port, protocol, url, user, password, timeout, TimeUnit.MILLISECONDS);
            try {
                BitcoindApi api = bitcoinClient.getApi();
                boolean isTestnet = api.getblockchaininfo().getChain().equals("test");
                if (isTestnet != testnet) {
                    String expected = testnet ? "testnet" : "mainnet";
                    String actual = isTestnet ? "testnet" : "mainnet";
                    errorDetailsTextArea.append("Wrong network type: expected " + expected + ", found " + actual + ".");
                    networkFeedbackERR.setVisible(true);
                    return;
                }
            } catch (Exception e1) {
                e1.printStackTrace();
                errorDetailsTextArea.append("Cannot connect to the node.\n\n");
                errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
                networkFeedbackERR.setVisible(true);
                return;
            }
            errorDetailsTextArea.append("ok");
            networkFeedbackOK.setVisible(true);
        }
    });
    if (testnet)
        testnetHostText = hostText;
    else
        mainnetHostText = hostText;
    if (testnet)
        testnetPortSpinner = portSpinner;
    else
        mainnetPortSpinner = portSpinner;
    if (testnet)
        testnetHttpsCheckbox = httpsCheckbox;
    else
        mainnetHttpsCheckbox = httpsCheckbox;
    if (testnet)
        testnetUrlText = urlText;
    else
        mainnetUrlText = urlText;
    if (testnet)
        testnetUsernameText = usernameText;
    else
        mainnetUsernameText = usernameText;
    if (testnet)
        testnetPasswordText = passwordText;
    else
        mainnetPasswordText = passwordText;
    if (testnet)
        testnetTimeoutSpinner = timeoutSpinner;
    else
        mainnetTimeoutSpinner = timeoutSpinner;
}
Also used : Group(org.eclipse.swt.widgets.Group) StyledText(org.eclipse.swt.custom.StyledText) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) RPCBitcoinClient(it.unica.tcs.lib.client.impl.RPCBitcoinClient) FocusEvent(org.eclipse.swt.events.FocusEvent) StorageException(org.eclipse.equinox.security.storage.StorageException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FocusListener(org.eclipse.swt.events.FocusListener) StorageException(org.eclipse.equinox.security.storage.StorageException) BitcoindApi(com.sulacosoft.bitcoindconnector4j.BitcoindApi)

Example 67 with ControlListener

use of org.eclipse.swt.events.ControlListener in project selenium_java by sergueik.

the class PreferencesDialog method createCategory.

private Composite createCategory(final TabFolder folder, String category, List<Preference<?>> preferences) {
    final Composite c = new Composite(folder, SWT.NONE);
    c.setLayout(new GridLayout(4, false));
    final List<Label> labels = new ArrayList<Label>();
    org.eclipse.swt.widgets.Group current = null;
    for (final Preference<?> e : preferences) {
        if (e instanceof Group) {
            current = new org.eclipse.swt.widgets.Group(c, SWT.SHADOW_ETCHED_IN);
            current.setText(e.getLabel());
            current.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(4, 1).create());
            current.setLayout(new GridLayout(4, false));
        } else {
            final Label l = new Label(current != null ? current : c, SWT.NONE);
            // $NON-NLS-1$
            l.setText(e.getLabel() + ":");
            labels.add(l);
            editors.put(e, e.getEditor());
            editors.get(e).createControl(current != null ? current : c);
            editors.get(e).setValue(e.getValue());
        }
    }
    // Set equal width on labels
    ControlListener listener = new ControlAdapter() {

        int count = 0;

        int maxWidth = 0;

        @Override
        public void controlResized(ControlEvent arg0) {
            maxWidth = Math.max(((Label) arg0.widget).getSize().x, maxWidth);
            if (++count == labels.size()) {
                GridData gridData = new GridData();
                gridData.widthHint = maxWidth;
                for (Label label : labels) {
                    label.setLayoutData(gridData);
                }
                c.layout(true, true);
            }
        }
    };
    // Attach listener
    for (Label label : labels) {
        label.addControlListener(listener);
    }
    // Return base
    return c;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 68 with ControlListener

use of org.eclipse.swt.events.ControlListener in project tmdm-studio-se by Talend.

the class XObjectBrowser method createToolbar.

protected void createToolbar(final Composite parent) {
    toolBar = new TdEditorToolBar(parent);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    toolBar.getToolbarControl().setLayoutData(data);
    toolBar.addResizeListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            parent.getParent().layout(true);
            parent.layout(true);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 69 with ControlListener

use of org.eclipse.swt.events.ControlListener in project jbosstools-openshift by jbosstools.

the class DialogChildVisibilityAdapter method onShellResized.

private ControlListener onShellResized(final Shell shell) {
    final ControlListener listener = new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (!resizing) {
                DialogChildVisibilityAdapter.this.invisibleChildShellHeight = shell.getSize().y;
            }
        }
    };
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            shell.removeControlListener(listener);
        }
    });
    return listener;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 70 with ControlListener

use of org.eclipse.swt.events.ControlListener in project tdq-studio-se by Talend.

the class CommonFormEditor method createToolbar.

/**
 * DOC bzhou Comment method "createToolbar".
 *
 * @param parent
 */
protected void createToolbar(final Composite parent) {
    editorBarWrap = new TdEditorBarWrapper(this);
    toolBar = new TdEditorToolBar(parent, editorBarWrap);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    toolBar.getToolbarControl().setLayoutData(data);
    toolBar.addResizeListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        // do nothing until now
        }

        public void controlResized(ControlEvent e) {
            parent.getParent().layout(true);
            parent.layout(true);
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

ControlListener (org.eclipse.swt.events.ControlListener)87 ControlEvent (org.eclipse.swt.events.ControlEvent)82 GridData (org.eclipse.swt.layout.GridData)31 FocusEvent (org.eclipse.swt.events.FocusEvent)19 Composite (org.eclipse.swt.widgets.Composite)19 Test (org.junit.Test)19 MouseEvent (org.eclipse.swt.events.MouseEvent)18 Point (org.eclipse.swt.graphics.Point)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 KeyEvent (org.eclipse.swt.events.KeyEvent)16 ArrayList (java.util.ArrayList)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 DisposeEvent (org.eclipse.swt.events.DisposeEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)11 DisposeListener (org.eclipse.swt.events.DisposeListener)11 FocusListener (org.eclipse.swt.events.FocusListener)11 Listener (org.eclipse.swt.widgets.Listener)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9