KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > composite > OKCancelComposite


1 /*
2  * Created on Mar 12, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.rcp.composite;
7
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.events.SelectionListener;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
15
16 /**
17  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
18  *
19  */

20 public abstract class OKCancelComposite extends TightWrapperComposite {
21
22     private Button okButton;
23     private Button cancelButton;
24     private Label label;
25     
26     /**
27      * @param parent
28      * @param style
29      * @param setLayoutData
30      */

31     public OKCancelComposite(Composite parent, int style, String JavaDoc text, String JavaDoc okTxt, String JavaDoc cancelTxt) {
32         super(parent, style, true);
33         if ((text != null) && (!"".equals(text))) {
34             label = new Label(this, SWT.WRAP);
35             label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
36             label.setText(text);
37         }
38         TightWrapperComposite buttonWrapper = new TightWrapperComposite(this, SWT.NONE, true);
39         buttonWrapper.getGridLayout().numColumns = 2;
40         okButton = new Button(buttonWrapper, SWT.PUSH);
41         GridData okGD = new GridData();
42         okGD.grabExcessHorizontalSpace = false;
43         okGD.horizontalAlignment = GridData.END;
44         okButton.setLayoutData(okGD);
45         okButton.setText(okTxt);
46         okButton.addSelectionListener(new SelectionListener() {
47             public void widgetSelected(SelectionEvent e) {
48                 okPressed();
49             }
50             public void widgetDefaultSelected(SelectionEvent e) {
51                 okPressed();
52             }
53         });
54         
55         cancelButton = new Button(buttonWrapper, SWT.PUSH);
56         cancelButton.setLayoutData(new GridData());
57         cancelButton.setText(cancelTxt);
58         cancelButton.addSelectionListener(new SelectionListener() {
59             public void widgetSelected(SelectionEvent e) {
60                 cancelPressed();
61             }
62             public void widgetDefaultSelected(SelectionEvent e) {
63                 cancelPressed();
64             }
65         });
66     }
67     
68     protected abstract void okPressed();
69     
70     protected abstract void cancelPressed();
71     
72     
73
74 }
75
Popular Tags