KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > TypeRestrictionDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.schema;
12
13 import java.util.Hashtable JavaDoc;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.pde.internal.core.ischema.ISchemaRestriction;
18 import org.eclipse.pde.internal.ui.IHelpContextIds;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Combo;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.part.PageBook;
32
33 public class TypeRestrictionDialog extends Dialog {
34     private static final String JavaDoc T_ENUMERATION = "enumeration"; //$NON-NLS-1$
35
private static final String JavaDoc T_NONE = "none"; //$NON-NLS-1$
36

37     private String JavaDoc [] typeChoices = { T_NONE, T_ENUMERATION };
38     private Combo typeCombo;
39     private Hashtable JavaDoc pages = new Hashtable JavaDoc();
40     private ISchemaRestriction restriction;
41     private PageBook pageBook;
42
43 public TypeRestrictionDialog(Shell shell, ISchemaRestriction restriction) {
44     super(shell);
45     if (restriction!=null && restriction.getChildren().length>0)
46         this.restriction = restriction;
47 }
48 protected void createButtonsForButtonBar(Composite parent) {
49     // create OK and Cancel buttons by default
50
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
51     createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
52 }
53 protected Control createDialogArea(Composite parent) {
54     Composite container = new Composite(parent, SWT.NULL);
55     GridLayout layout = new GridLayout();
56     layout.numColumns = 2;
57     container.setLayout(layout);
58     GridData gd = new GridData(GridData.FILL_BOTH);
59     container.setLayoutData(gd);
60
61     Label label = new Label(container, SWT.NULL);
62     label.setText(PDEUIMessages.RestrictionDialog_type);
63     gd = new GridData();
64     label.setLayoutData(gd);
65     typeCombo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
66     initializeTypeCombo();
67     typeCombo.addSelectionListener(new SelectionAdapter() {
68         public void widgetSelected(SelectionEvent e) {
69             handleTypeSelection();
70         }
71     });
72     gd = new GridData(GridData.FILL_HORIZONTAL);
73     typeCombo.setLayoutData(gd);
74
75     gd = new GridData(GridData.FILL_HORIZONTAL);
76     gd.horizontalSpan = 2;
77     label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_OUT);
78     label.setLayoutData(gd);
79     
80     gd = new GridData(GridData.FILL_BOTH);
81     gd.horizontalSpan = 2;
82
83     pageBook = new PageBook(container, SWT.NULL);
84     pageBook.setLayoutData(gd);
85     initializePages();
86     PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.SCHEMA_TYPE_RESTRICTION);
87     return container;
88 }
89 public Object JavaDoc getValue() {
90     return restriction;
91 }
92 private void handleTypeSelection() {
93     String JavaDoc selection = typeCombo.getItem(typeCombo.getSelectionIndex());
94     IRestrictionPage page = (IRestrictionPage)pages.get(selection);
95     pageBook.showPage(page.getControl());
96 }
97 protected void initializePages() {
98     IRestrictionPage page;
99     IRestrictionPage pageToShow = null;
100     String JavaDoc typeToShow = null;
101
102     page = new NoRestrictionPage();
103     page.createControl(pageBook);
104     pages.put(T_NONE, page);
105     if (restriction == null) {
106         pageToShow = page;
107         typeToShow = T_NONE;
108     }
109
110     page = new EnumerationRestrictionPage();
111     page.createControl(pageBook);
112     pages.put(T_ENUMERATION, page);
113     if (restriction != null
114         && page.getCompatibleRestrictionClass().isInstance(restriction)) {
115         pageToShow = page;
116         typeToShow = T_ENUMERATION;
117     }
118     pageToShow.initialize(restriction);
119     typeCombo.setText(typeToShow);
120     pageBook.showPage(pageToShow.getControl());
121 }
122 protected void initializeTypeCombo() {
123     typeCombo.setItems(typeChoices);
124 }
125 protected void okPressed() {
126     String JavaDoc selectedRestriction = typeChoices[typeCombo.getSelectionIndex()];
127     IRestrictionPage page = (IRestrictionPage)pages.get(selectedRestriction);
128     restriction = page.getRestriction();
129     super.okPressed();
130 }
131 }
132
Popular Tags