Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 326538
Collapse All | Expand All

(-)description/dialogs.html (+30 lines)
Added Link Here
1
<html>
2
<head>
3
<link rel="stylesheet" type="text/css" href="default.css" media="screen" />
4
</head>
5
<body>
6
7
  <h2>Dialogs</h2>
8
9
  <h3>Selection dialogs</h3>
10
  <p>
11
    RAP provides the user with a series of dialogs that should help selecting things.
12
    Dialogs are easy to use and adapt to every object. All the user has to do is provide
13
    those objects and the necessary content and label providers. 
14
  </p>
15
 
16
  <h3>Message Dialogs</h3>
17
  <p>
18
    Message dialogs provide a simple way of displaying information to the user as well as getting simple
19
    <code>true</code> or <code>false</code> user input. The class <code>MessageDialog</code> provides easy
20
    to use static API for the following use cases:
21
    <UL>
22
      <LI><code>MessageDialog.WARNING</code>
23
      <LI><code>MessageDialog.ERROR</code>
24
      <LI><code>MessageDialog.INFORMATION</code>
25
      <LI><code>MessageDialog.QUESTION</code>
26
      <LI><code>MessageDialog.CONFIRM</code>
27
    </UL>
28
  </p>
29
</body>
30
</html>
(-)plugin.xml (+10 lines)
Lines 86-91 Link Here
86
            description="description/theming.html"
86
            description="description/theming.html"
87
            name="Theming">
87
            name="Theming">
88
      </page>
88
      </page>
89
      <category
90
            id="dialogs"
91
            name="Dialogs">
92
      </category>
93
      <page
94
            category="dialogs"
95
            class="org.eclipse.rap.examples.pages.DialogExample"
96
            description="description/dialogs.html"
97
            name="Selection and Message Dialogs">
98
      </page>
89
   </extension>
99
   </extension>
90
   <extension
100
   <extension
91
         point="org.eclipse.equinox.http.registry.resources">
101
         point="org.eclipse.equinox.http.registry.resources">
(-)src/org/eclipse/rap/examples/pages/DialogExample.java (+318 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 EclipseSource and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the
4
 * terms of the Eclipse Public License v1.0 which accompanies this distribution, 
5
 * and is available at http://www.eclipse.org/legal/epl-v10.html
6
 *
7
 * Contributors:
8
 *   EclipseSource - initial API and implementation
9
 ******************************************************************************/
10
package org.eclipse.rap.examples.pages;
11
12
import java.util.ArrayList;
13
14
import org.eclipse.jface.dialogs.*;
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.viewers.*;
17
import org.eclipse.rap.examples.IExamplePage;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.layout.*;
22
import org.eclipse.swt.widgets.*;
23
import org.eclipse.ui.dialogs.*;
24
25
public class DialogExample implements IExamplePage {
26
  
27
  private final ArrayContentProvider arrayContentProvider;
28
  private final ITreeContentProvider treeContentProvider;
29
  private final LabelProvider labelProvider;
30
  private final String[] input;
31
32
  public DialogExample() {
33
    this.arrayContentProvider = ArrayContentProvider.getInstance();
34
    this.treeContentProvider = new TreeContenProvider();
35
    this.labelProvider = new LabelProvider();
36
    this.input = new String[]{
37
      "op1", "op2", "op3", "op4", "op5", "op6"
38
    };
39
  }
40
  
41
  public void createControl( final Composite parent ) {
42
    parent.setLayout( new GridLayout() );
43
    Composite selectionGroup = createGroup( parent, "Selection Dialogs:" );
44
    createListSelection( selectionGroup );
45
    createListDialog( selectionGroup );
46
    createTreeSelection( selectionGroup );
47
    createCheckedTreeSelection( selectionGroup );
48
    createTwoPaneElementSelector( selectionGroup );
49
    createTypeFilteringDialog( selectionGroup );
50
    Composite messageDialogGroup = createGroup( parent, "Dialogs:" );
51
    createTitleAreaDialog( messageDialogGroup );
52
    createMessageDialogs( messageDialogGroup );
53
  }
54
55
  private void createMessageDialogs( final Composite parent ) {
56
    createMessageDialg( parent,
57
                        MessageDialog.CONFIRM,
58
                        "Confirm Dialog",
59
                        "Confirm Dialog Title",
60
                        "Confirm message" );
61
    createMessageDialg( parent,
62
                        MessageDialog.ERROR,
63
                        "Error Dialog",
64
                        "Error Dialog Title",
65
                        "Error message" );
66
    createMessageDialg( parent,
67
                        MessageDialog.INFORMATION,
68
                        "Information Dialog",
69
                        "Information Dialog Title",
70
                        "Information message" );
71
    createMessageDialg( parent,
72
                        MessageDialog.QUESTION,
73
                        "Question Dialog",
74
                        "Question Dialog Title",
75
                        "Question message" );
76
    createMessageDialg( parent,
77
                        MessageDialog.QUESTION_WITH_CANCEL,
78
                        "Question/Cancel Dialog",
79
                        "Question Dialog Title",
80
                        "Question message" );
81
    createMessageDialg( parent,
82
                        MessageDialog.WARNING,
83
                        "Warning Dialog",
84
                        "Warning Dialog Title",
85
                        "Warning message" );
86
  }
87
88
  private void createMessageDialg( final Composite parent,
89
                                   final int type,
90
                                   final String buttonLabel,
91
                                   final String title,
92
                                   final String message )
93
  {
94
    Button button = createButton( parent, buttonLabel );
95
    final Text text = createText( parent );
96
    button.addSelectionListener( new SelectionAdapter() {
97
98
      public void widgetSelected( final SelectionEvent e ) {
99
        boolean result = MessageDialog.open( type,
100
                                             parent.getShell(),
101
                                             title,
102
                                             message,
103
                                             SWT.NONE );
104
        text.setText( result ? "Ok clicked" : "Cancel clicked" );
105
      }
106
    } );
107
  }
108
  
109
  private void createTitleAreaDialog( final Composite parent ) {
110
    Button titleAreaDialog = createButton( parent, "Title area dialog" );
111
    final Text text = createText( parent );
112
    titleAreaDialog.addSelectionListener( new SelectionAdapter() {
113
114
      public void widgetSelected( final SelectionEvent e ) {
115
        TitleAreaDialog dialog = new TitleAreaDialog( parent.getShell() );
116
        dialog.create();
117
        dialog.setTitle( "Title area dialog - Title" );
118
        dialog.setMessage( "Choose from the list - Message" );
119
        Display display = parent.getDisplay();
120
        dialog.setTitleImage( display.getSystemImage( SWT.ICON_QUESTION ) );
121
        if( dialog.open() == Dialog.OK ) {
122
          text.setText( "Ok clicked" );
123
        }
124
      }
125
    } );
126
  }
127
128
  private void createTypeFilteringDialog( final Composite parent ) {
129
    TypeFilteringDialog dialog = new TypeFilteringDialog( parent.getShell(), new ArrayList() );
130
    dialog.setTitle( "Type filtering dialog" );
131
    dialog.setMessage( "Choose from the list" );
132
    createSelectionDialog( parent, dialog, "Type Filtering Dialog" );
133
  }
134
135
  private void createTwoPaneElementSelector( final Composite parent ) {
136
    TwoPaneElementSelector dialog = new TwoPaneElementSelector( parent.getShell(),
137
                                                                labelProvider,
138
                                                                labelProvider );
139
    dialog.setElements( input );
140
    dialog.setTitle( "Two Pane Element Selector" );
141
    dialog.setMessage( "Choose from the list" );
142
    createSelectionDialog( parent, dialog, "Two Pane Selector Dialog" );
143
  }
144
145
  private void createListDialog( final Composite parent ) {
146
    ListDialog dialog = new ListDialog( parent.getShell() );
147
    dialog.setInput( input );
148
    dialog.setContentProvider( arrayContentProvider );
149
    dialog.setLabelProvider( labelProvider );
150
    dialog.setTitle( "List Dialog" );
151
    dialog.setMessage( "Choose from the list" );
152
    createSelectionDialog( parent, dialog, "List Dialog" );
153
  }
154
155
  private void createSelectionDialog( final Composite parent,
156
                                      final SelectionDialog dialog,
157
                                      final String buttonLabel )
158
  {
159
    Button button = createButton( parent, buttonLabel );
160
    final Text text = createText( parent );
161
    button.addSelectionListener( new SelectionAdapter() {
162
163
      public void widgetSelected( SelectionEvent e ) {
164
        if( dialog.open() == Dialog.OK ) {
165
          text.setText( getResultString( dialog.getResult() ) );
166
        } else {
167
          text.setText( "Cancel clicked" );
168
        }
169
      }
170
    } );
171
  }
172
  
173
  private void createTreeSelection( final Composite parent ) {
174
    ElementTreeSelectionDialog dialog 
175
    = new ElementTreeSelectionDialog( parent.getShell(), 
176
                                      labelProvider,
177
                                      treeContentProvider );
178
    dialog.setInput( getTreeInput() );
179
    dialog.setTitle( "Tree Selection Dialog" );
180
    dialog.setMessage( "Choose from the tree" );
181
    createSelectionDialog( parent, dialog, "Tree Selection Dialog" );
182
  }
183
184
  private void createCheckedTreeSelection( final Composite parent ) {
185
    CheckedTreeSelectionDialog dialog 
186
     = new CheckedTreeSelectionDialog( parent.getShell(),
187
                                      labelProvider,
188
                                      treeContentProvider );
189
    dialog.setInput( getTreeInput() );
190
    dialog.setTitle( "Checked Tree Selection Dialog" );
191
    dialog.setMessage( "Choose from the tree" );
192
    createSelectionDialog( parent, dialog, "Checked Tree Selection Dialog" );
193
  }
194
  
195
  private Object getTreeInput() {
196
    TreeObject parent = new TreeObject( "Parent" );
197
    TreeObject parent2 = new TreeObject( "Parent 2" );
198
    TreeObject parent3 = new TreeObject( "Parent 3" );
199
    parent.putChild( parent2 );
200
    parent.putChild( parent3 );
201
    for( int i = 0; i < 4; i++ ) {
202
      TreeObject childParent2 = new TreeObject( "Child" + i );
203
      parent2.putChild( childParent2 );
204
      TreeObject childParent3 = new TreeObject( "Child" + i );
205
      parent3.putChild( childParent3 );
206
    }
207
    return parent;
208
  }
209
  
210
  private void createListSelection( final Composite parent ) {
211
    String message = "Select something:";
212
    ListSelectionDialog dialog = new ListSelectionDialog( parent.getShell(),
213
                                                          input,
214
                                                          arrayContentProvider,
215
                                                          labelProvider,
216
                                                          message );
217
    dialog.setTitle( "List selection dialog" );
218
    createSelectionDialog( parent, dialog, "List Selection Dialog" );
219
  }
220
221
  private Button createButton( final Composite parent, final String label ) {
222
    Button button = new Button( parent, SWT.PUSH );
223
    button.setText( label );
224
    GridData gridData = new GridData( SWT.FILL, SWT.FILL, false, false );
225
    gridData.widthHint = 200;
226
    button.setLayoutData( gridData );
227
    return button;
228
  }
229
  
230
  private Text createText( final Composite parent ) {
231
    Text text = new Text( parent, SWT.BORDER );
232
    text.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false ) );
233
    text.setEditable( false );
234
    return text;
235
  }
236
  
237
  private Composite createGroup( final Composite parent, 
238
                                 final String groupName )
239
  {
240
    Group group = new Group( parent, SWT.NONE );
241
    group.setText( groupName );
242
    GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, false );
243
    group.setLayoutData( gridData );
244
    group.setLayout( new GridLayout( 2, false ) );
245
    return group;
246
  }
247
  
248
  private String getResultString( final Object[] object ) {
249
    String result = "";
250
    if( object != null ) {
251
      for( int i = 0; i < object.length; i++ ) {
252
        result += object[ i ].toString() + " ";
253
      }
254
    }
255
    return result;
256
  }
257
  
258
  private class TreeObject {
259
260
    private final String name;
261
    private java.util.List children;
262
    private TreeObject parent;
263
264
    public TreeObject( final String name ) {
265
      this.name = name;
266
      this.children = new ArrayList();
267
    }
268
269
    public String toString() {
270
      return name;
271
    }
272
273
    public void putChild( final TreeObject treeObject ) {
274
      children.add( treeObject );
275
      treeObject.setParent( this );
276
    }
277
278
    public Object[] getChildren() {
279
      return children.toArray();
280
    }
281
282
    public void setParent( final TreeObject parent ) {
283
      this.parent = parent;
284
    }
285
286
    public TreeObject getParent() {
287
      return this.parent;
288
    }
289
  }
290
  
291
  private class TreeContenProvider implements ITreeContentProvider {
292
293
    public void dispose() {
294
    }
295
296
    public void inputChanged( final Viewer viewer,
297
                              final Object oldInput,
298
                              final Object newInput )
299
    {
300
    }
301
302
    public Object[] getElements( final Object inputElement ) {
303
      return ( ( TreeObject )inputElement ).getChildren();
304
    }
305
306
    public Object[] getChildren( final Object parentElement ) {
307
      return ( ( TreeObject )parentElement ).getChildren();
308
    }
309
310
    public Object getParent( final Object element ) {
311
      return ( ( TreeObject )element ).getParent();
312
    }
313
314
    public boolean hasChildren( final Object element ) {
315
      return ( ( TreeObject )element ).getChildren().length > 0;
316
    }
317
  }
318
}

Return to bug 326538