|
Lines 1-21
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004 IBM Corporation and others. |
2 |
* Copyright (c) 2004, 2006 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* yyyymmdd bug Email and other contact information |
| 11 |
* -------- -------- ----------------------------------------------------------- |
| 12 |
* 20060418 136335 joan@ca.ibm.com - Joan Haggarty |
| 10 |
*******************************************************************************/ |
13 |
*******************************************************************************/ |
| 11 |
package org.eclipse.wst.command.internal.env.ui.widgets; |
14 |
package org.eclipse.wst.command.internal.env.ui.widgets; |
| 12 |
|
15 |
|
|
|
16 |
import org.eclipse.core.runtime.IStatus; |
| 13 |
import org.eclipse.jface.dialogs.Dialog; |
17 |
import org.eclipse.jface.dialogs.Dialog; |
|
|
18 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.layout.GridData; |
| 21 |
import org.eclipse.swt.widgets.Button; |
| 14 |
import org.eclipse.swt.widgets.Composite; |
22 |
import org.eclipse.swt.widgets.Composite; |
| 15 |
import org.eclipse.swt.widgets.Control; |
23 |
import org.eclipse.swt.widgets.Control; |
| 16 |
import org.eclipse.swt.widgets.Event; |
24 |
import org.eclipse.swt.widgets.Event; |
| 17 |
import org.eclipse.swt.widgets.Listener; |
25 |
import org.eclipse.swt.widgets.Listener; |
| 18 |
import org.eclipse.swt.widgets.Shell; |
26 |
import org.eclipse.swt.widgets.Shell; |
|
|
27 |
import org.eclipse.swt.widgets.Text; |
| 19 |
|
28 |
|
| 20 |
public abstract class SimpleDialog extends Dialog implements DialogDataEvents |
29 |
public abstract class SimpleDialog extends Dialog implements DialogDataEvents |
| 21 |
{ |
30 |
{ |
|
Lines 23-28
Link Here
|
| 23 |
private WidgetDataEvents dataEvents_; |
32 |
private WidgetDataEvents dataEvents_; |
| 24 |
private Listener statusListener_; |
33 |
private Listener statusListener_; |
| 25 |
protected WizardPageManager pageManager_; |
34 |
protected WizardPageManager pageManager_; |
|
|
35 |
private Text messageText_; |
| 36 |
private boolean ok_; |
| 26 |
|
37 |
|
| 27 |
public SimpleDialog( Shell shell, PageInfo pageInfo) |
38 |
public SimpleDialog( Shell shell, PageInfo pageInfo) |
| 28 |
{ |
39 |
{ |
|
Lines 35-45
Link Here
|
| 35 |
{ |
46 |
{ |
| 36 |
Composite control = (Composite) super.createDialogArea(parent); |
47 |
Composite control = (Composite) super.createDialogArea(parent); |
| 37 |
dataEvents_ = widget_.addControls( control, statusListener_ ); |
48 |
dataEvents_ = widget_.addControls( control, statusListener_ ); |
| 38 |
callSetters(); |
49 |
|
|
|
50 |
//Text area to display validation messages |
| 51 |
messageText_ = new Text(parent, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY); |
| 52 |
GridData griddata = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); |
| 53 |
griddata.horizontalIndent = 10; |
| 54 |
messageText_.setLayoutData( griddata ); |
| 55 |
|
| 56 |
//Remove focus from the message text area so cursor doesn't appear there |
| 57 |
control.setFocus(); |
| 58 |
|
| 59 |
//Call extenders override of the callSetters method to intialize any data in widget |
| 60 |
callSetters(); |
| 39 |
org.eclipse.jface.dialogs.Dialog.applyDialogFont(control); |
61 |
org.eclipse.jface.dialogs.Dialog.applyDialogFont(control); |
| 40 |
return control; |
62 |
return control; |
| 41 |
} |
63 |
} |
|
|
64 |
|
| 65 |
//Override of Dialog.createContents so we can affect button enablement |
| 66 |
protected Control createContents(Composite parent) { |
| 67 |
Control c = super.createContents(parent); |
| 68 |
//enable controls for initial entry to dialog |
| 69 |
validatePageToStatus(); |
| 70 |
return c; |
| 71 |
} |
| 42 |
|
72 |
|
|
|
73 |
// Enable or disable ok button based on state |
| 74 |
private void enableOk(boolean state) |
| 75 |
{ |
| 76 |
Button okButton = getButton(IDialogConstants.OK_ID); |
| 77 |
if (okButton != null) |
| 78 |
okButton.setEnabled(state); |
| 79 |
} |
| 80 |
|
| 43 |
//Implement this method to call all setters on the dialog widget after the controls are created |
81 |
//Implement this method to call all setters on the dialog widget after the controls are created |
| 44 |
protected abstract void callSetters(); |
82 |
protected abstract void callSetters(); |
| 45 |
|
83 |
|
|
Lines 52-108
Link Here
|
| 52 |
{ |
90 |
{ |
| 53 |
return widget_; |
91 |
return widget_; |
| 54 |
} |
92 |
} |
|
|
93 |
|
| 94 |
// sets message in message area above OK and Cancel buttons |
| 95 |
private void setMessage(String message) |
| 96 |
{ |
| 97 |
if (message == null) |
| 98 |
messageText_.setText(""); |
| 99 |
else |
| 100 |
messageText_.setText(message); |
| 101 |
} |
| 55 |
|
102 |
|
| 56 |
public void validatePageToStatus() |
103 |
public void validatePageToStatus() |
| 57 |
{ |
104 |
{ |
| 58 |
/*IStatus status = widget_.getStatus(); |
105 |
IStatus status = widget_.getStatus(); |
| 59 |
|
106 |
|
| 60 |
if( status != null ) |
107 |
if( status != null ) |
| 61 |
{ |
108 |
{ |
| 62 |
if( status.getSeverity() == IStatus.ERROR ) |
109 |
String message = status.getMessage(); |
| 63 |
{ |
110 |
int severity = status.getSeverity(); |
| 64 |
String message = status.getMessage(); |
111 |
|
| 65 |
|
112 |
// for error condition, disable ok and print message |
|
|
113 |
if( severity == IStatus.ERROR ) |
| 114 |
{ |
| 66 |
if( message.length() == 0 ) |
115 |
if( message.length() == 0 ) |
| 67 |
{ |
116 |
{ |
| 68 |
setErrorMessage( null ); |
117 |
setMessage( null); |
| 69 |
setMessage( getDescription() ); |
|
|
| 70 |
} |
118 |
} |
| 71 |
else |
119 |
else |
| 72 |
{ |
120 |
{ |
| 73 |
setErrorMessage( message ); |
121 |
setMessage(message); |
| 74 |
} |
122 |
} |
| 75 |
|
123 |
ok_ = false; |
| 76 |
// jvh - dialog equivalent ....disable OK? setPageComplete( false ); |
|
|
| 77 |
} |
124 |
} |
| 78 |
else if (status.getSeverity() == IStatus.WARNING ) |
125 |
// display warning and info messages but still enable OK |
|
|
126 |
else if (severity == IStatus.WARNING | severity == IStatus.INFO) |
| 79 |
{ |
127 |
{ |
| 80 |
setErrorMessage( null ); |
128 |
setMessage(message); |
| 81 |
setMessage(status.getMessage(), IStatus.WARNING ); |
129 |
ok_ = true; |
| 82 |
// jvh - dialog equivalent ....enable OK?setPageComplete( true ); |
130 |
} |
| 83 |
} |
131 |
// no message to display |
| 84 |
else if( status.getSeverity() == IStatus.INFO ) |
132 |
else |
| 85 |
{ |
|
|
| 86 |
setErrorMessage( null ); |
| 87 |
setMessage( status.getMessage(), IStatus.INFO ); |
| 88 |
// jvh - dialog equivalent ....enable OK?setPageComplete( true ); |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
133 |
{ |
| 92 |
setErrorMessage( null ); |
134 |
setMessage( null); |
| 93 |
setMessage( getDescription() ); |
135 |
ok_ = true; |
| 94 |
// jvh - dialog equivalent ....enable OK?setPageComplete( true ); |
|
|
| 95 |
} |
136 |
} |
| 96 |
} |
137 |
} |
|
|
138 |
// null status case |
| 97 |
else |
139 |
else |
| 98 |
{ |
140 |
{ |
| 99 |
setErrorMessage( null ); |
141 |
setMessage(null); |
| 100 |
setMessage( getDescription() ); |
142 |
ok_ = true; |
| 101 |
// jvh - dialog equivalent ....enable OK?setPageComplete( true ); |
|
|
| 102 |
} |
143 |
} |
| 103 |
|
144 |
|
| 104 |
// jvh - dialog equivalent - update dialog buttons? getContainer().updateButtons(); |
145 |
enableOk(ok_); |
| 105 |
*/ } |
146 |
} |
| 106 |
|
147 |
|
| 107 |
private class StatusListener implements Listener |
148 |
private class StatusListener implements Listener |
| 108 |
{ |
149 |
{ |