Through event-driven, create different parts

A very easy thing is to dispose the first re-create.

Written mainly to see if they have a better realization method

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
 *  The program purpose: event-driven, dynamically created components simple demo.  
 *  Select Yes when: choose from the drop-down box.  
 *  Select "no" when you are making a specific text configuration  
 * @author Administrator
 */
public class MyComposite {

        private  Button useOutSourceButton;
        private  Button newSourceButton;
        private  Composite dbSourceComposite;
        private  Shell shell;

        /**
         *  The main program  
         * @param args
         */
        public static void main(String[] args) {
                MyComposite myComposite = new MyComposite();

                myComposite.open();
        }

        /**
         * shell
         */
        private void open() {
                Display display = Display.getDefault();
                shell = new Shell(display);
                shell.setText(" Component replacement test  ");
                shell.setSize(400, 200);
                shell.setLayout(new GridLayout(3, false));

                final Label label = new Label(shell, SWT.NONE);
                label.setLayoutData(new GridData(100, SWT.DEFAULT));
                label.setText(" Use the database resources  ");

                useOutSourceButton = new Button(shell, SWT.RADIO);
                useOutSourceButton.setText(" Is  ");
                newSourceButton = new Button(shell, SWT.RADIO);
                newSourceButton.setText(" No  ");

                dbSourceComposite = new Composite(shell, SWT.NONE);
                dbSourceComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,true, false,3,1));
                dbSourceComposite.setLayout(new GridLayout(3,false));

                createInnerListeners();

                shell.open();
                while (!display.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                display.dispose();

        }

        /**
         *  Event listener  
         */
        protected void createInnerListeners() {
                useOutSourceButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                Button btn = (Button) e.getSource();
                                if (btn.getSelection()) {
                                        initSelectDBSourceUI(dbSourceComposite);
                                }
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                });
                newSourceButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                Button btn = (Button) e.getSource();
                                if (btn.getSelection()) {
                                        initConfigDBSourceUI(dbSourceComposite);
                                }
                        }

                        public void widgetDefaultSelected(SelectionEvent e) {
                        }
                });
        }

        /**
         *  Create part Group 1  
         * @param composite
         */
        private void initConfigDBSourceUI(final Composite composite) {
                this.disposedComposite(composite);
                Text configureText = new Text(composite, SWT.BORDER);
                configureText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
                                false));
                configureText.setEditable(false);
                Button configureButton = new Button(composite, SWT.NONE);
                configureButton.setText(" Configuration  ");
                Button resetButton = new Button(composite, SWT.NONE);
                resetButton.setText(" Reset  ");
                shell.layout(true, true);
        }

        /**
         *  Create part Group 2  
         * @param composite
         */
        private void initSelectDBSourceUI(final Composite composite) {
                this.disposedComposite(composite);
                Label dbTypeLabel = new Label(composite, SWT.NONE);
                dbTypeLabel.setText(" Database resource name  ");
                dbTypeLabel.setLayoutData(new GridData(100, SWT.DEFAULT));
                dbTypeLabel.setToolTipText(" Select an existing database resources  ");

                CCombo dbCombo = new CCombo(composite, SWT.BORDER);
                dbCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
                dbCombo.setEditable(false);

                Button resetButton = new Button(composite, SWT.NONE);
                resetButton.setText(" Reset  ");
                shell.layout(true, true);
        }
        
        /**
         *  Destroy the original parts  
         * @param composite
         */
        private void disposedComposite(Composite composite) {
                Control[] arrays = composite.getChildren();
                for (Control control : arrays) {
                        if (control != null)
                                control.dispose();
                }
        }
}


Effect Picture:

Through event-driven, create different parts

  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Through event-driven, create different parts

  • ajax paging display

    ajax paging display

  • javascript_radio

    Error code: Analysis: radio arrays are Solution:

  • js delete line, Select All checkbox

    js delete line, Select All checkbox

  • js to do the Move, Move

    function upList () (/ / up sequencing var span = document.getElementById ( "trIds"); / / get to sort tr's span, of course, can also be set up to sort tr's name. var form = document.forms [0]; alert ( "form-========="+ form ...

  • The Rails Way back

    Rails 1.x days recalled by the Rails core members of Jamis Buck And Michael Koziarski Created The Rails Way Are the most influential one Rails site, the site is aimed at the creation of the code submitted to the site to comment and reconstruction to ...

  • To talk about Ruby variables

    School at the time heard that dynamic languages, python La. , ruby, lua you are. Get a picture of the object can change the runtime state, such as to add property to increase the Ways La. . But dynamic languages has been in the end do not know how to ...

  • ROR troubled long Axis2 web service calls to be initially resolved

    Problem: ROR how Axis2 call the web service Currently experiencing this problem, Google and Baidu found at numerous times, both at home and abroad have seen virtually no valuable information, the only help is a call ROR about. Net Services article (http:

  • Rails and Merb merged into a single project, it is not Fool's Day News

    Just ready to sleep, and suddenly saw the news, just released, and it is true. Attributed to a word a thousand words: Merb2 is Rails3! JE is now estimated that people remember you now sleep, right? I beg your pardon, was the first niche. Paragraphs e ...

  • log4j easy application in java

    JAVA development, frequently used the log output, in a so-called most of the software company will have its own set of configuration style, re-read the configuration file to initialize property of the log, it will be good, but sometimes may not need to fu

  • First Hibernate Example

    Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries