View | Details | Raw Unified | Return to bug 168769 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/forms/examples/internal/rcp/SimpleFormEditor.java (+1 lines)
Lines 46-51 Link Here
46
	protected void addPages() {
46
	protected void addPages() {
47
		try {
47
		try {
48
		addPage(new NewStylePage(this));
48
		addPage(new NewStylePage(this));
49
		addPage(new ErrorMessagesPage(this));
49
		addPage(new FreeFormPage(this));
50
		addPage(new FreeFormPage(this));
50
		addPage(new SecondPage(this));
51
		addPage(new SecondPage(this));
51
		int index = addPage(new Composite(getContainer(), SWT.NULL));
52
		int index = addPage(new Composite(getContainer(), SWT.NULL));
(-)src/org/eclipse/ui/forms/examples/internal/rcp/ErrorMessagesWizardPage.java (+125 lines)
Added Link Here
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 Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.forms.examples.internal.rcp;
12
import org.eclipse.jface.dialogs.IMessageProvider;
13
import org.eclipse.jface.fieldassist.MessageManager;
14
import org.eclipse.jface.wizard.WizardPage;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26
/**
27
 * @author dejan
28
 * 
29
 * To change the template for this generated type comment go to Window -
30
 * Preferences - Java - Code Generation - Code and Comments
31
 */
32
public class ErrorMessagesWizardPage extends WizardPage {
33
	private MessageManager mmng;
34
	/**
35
	 * @param id
36
	 * @param title
37
	 */
38
	public ErrorMessagesWizardPage(String id) {
39
		super(id);
40
		setTitle("Example with message handling");
41
		setDescription("This page shows how MessageManager can be used in wizards");
42
	}
43
	public void createControl(Composite parent) {
44
		Composite container = new Composite(parent, SWT.NULL);
45
		setControl(container);
46
		mmng = new MessageManager(this);
47
		
48
		GridLayout glayout = new GridLayout();
49
		glayout.horizontalSpacing = 10;
50
		glayout.numColumns= 2;
51
		container.setLayout(glayout);
52
		createDecoratedTextField("Field1", container);
53
		createDecoratedTextField("Field2", container);
54
		createDecoratedTextField("Field3", container);
55
		GridData gd;
56
		final Button button1 = new Button(container, SWT.CHECK); 
57
		button1.setText("Add general error");
58
		gd = new GridData();
59
		gd.horizontalSpan= 2;
60
		button1.setLayoutData(gd);
61
		button1.addSelectionListener(new SelectionAdapter() {
62
			public void widgetSelected(SelectionEvent e) {
63
				if (button1.getSelection()) {
64
					mmng.addMessage("saveError", "Save Error", IMessageProvider.ERROR);
65
				}
66
				else {
67
					mmng.removeMessage("saveError");
68
				}
69
			}
70
		});
71
		final Button button2 = new Button(container, SWT.CHECK);
72
		button2.setText("Add static message");
73
		gd = new GridData();
74
		gd.horizontalSpan= 2;
75
		button2.setLayoutData(gd);		
76
		button2.addSelectionListener(new SelectionAdapter() {
77
			public void widgetSelected(SelectionEvent e) {
78
				if (button2.getSelection()) {
79
					mmng.addMessage("info", "Secondary info", IMessageProvider.NONE);
80
				}
81
				else {
82
					mmng.removeMessage("info");
83
				}
84
			}
85
		});
86
	}
87
	
88
	private void createDecoratedTextField(String label, Composite parent) {
89
		Label l = new Label(parent, SWT.NULL);
90
		l.setText(label);
91
		final Text text = new Text(parent, SWT.BORDER);
92
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
93
		gd.widthHint = 150;
94
		text.setLayoutData(gd);
95
		text.addModifyListener(new ModifyListener() {
96
			public void modifyText(ModifyEvent e) {
97
				String s = text.getText();
98
				// flag length
99
				if (s.length()>5 && s.length()<=10) {
100
					mmng.addMessage("textLength", "Text is longer than 5 characters", IMessageProvider.WARNING, text);
101
				}
102
				else if (s.length()>10) {
103
					mmng.addMessage("textLength", "Text is longer than 10 characters", IMessageProvider.ERROR, text);
104
				}
105
				else {
106
					mmng.removeMessage("textLength", text);
107
				}
108
				// flag type
109
				boolean badType=false;
110
				for (int i=0; i<s.length(); i++) {
111
					if (!Character.isLetter(s.charAt(i))) {
112
						badType=true;
113
						break;
114
					}
115
				}
116
				if (badType) {
117
					mmng.addMessage("textType", "Text must only contain letters", IMessageProvider.ERROR, text);
118
				}
119
				else {
120
					mmng.removeMessage("textType", text);
121
				}				
122
			}
123
		});
124
	}
125
}
(-)src/org/eclipse/ui/forms/examples/internal/rcp/ErrorMessagesPage.java (+160 lines)
Added Link Here
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 Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.forms.examples.internal.rcp;
12
import org.eclipse.jface.action.ToolBarManager;
13
import org.eclipse.jface.dialogs.IMessageProvider;
14
import org.eclipse.jface.fieldassist.MessageManager;
15
import org.eclipse.jface.wizard.Wizard;
16
import org.eclipse.jface.wizard.WizardDialog;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.ModifyEvent;
19
import org.eclipse.swt.events.ModifyListener;
20
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.graphics.Color;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Text;
28
import org.eclipse.ui.forms.FormColors;
29
import org.eclipse.ui.forms.HyperlinkSettings;
30
import org.eclipse.ui.forms.IManagedForm;
31
import org.eclipse.ui.forms.editor.FormEditor;
32
import org.eclipse.ui.forms.editor.FormPage;
33
import org.eclipse.ui.forms.widgets.FormToolkit;
34
import org.eclipse.ui.forms.widgets.ScrolledForm;
35
import org.eclipse.ui.forms.widgets.Section;
36
import org.eclipse.ui.forms.widgets.TableWrapLayout;
37
/**
38
 * @author dejan
39
 * 
40
 * To change the template for this generated type comment go to Window -
41
 * Preferences - Java - Code Generation - Code and Comments
42
 */
43
public class ErrorMessagesPage extends FormPage {
44
	/**
45
	 * @param id
46
	 * @param title
47
	 */
48
	public ErrorMessagesPage(FormEditor editor) {
49
		super(editor, "messageManager", "Message Manager");
50
	}
51
	protected void createFormContent(IManagedForm managedForm) {
52
		final ScrolledForm form = managedForm.getForm();
53
		FormToolkit toolkit = managedForm.getToolkit();
54
		toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);
55
		form.setText("Example with message handling");
56
		FormColors colors = toolkit.getColors();
57
		colors.initializeSectionToolBarColors();
58
		Color gbg = colors.getColor(FormColors.TB_GBG);
59
		Color bg = colors.getBackground();
60
		form.getForm().setTextBackground(new Color[]{bg, gbg}, new int [] {100}, true);
61
		form.getForm().setSeparatorColor(colors.getColor(FormColors.TB_BORDER));
62
		form.getForm().setSeparatorVisible(true);
63
		ToolBarManager tbm = (ToolBarManager)form.getForm().getToolBarManager();
64
		tbm.getControl().setBackground(colors.getColor(FormColors.TB_GBG));
65
		
66
		final MessageManager mmng = new MessageManager(form.getForm());
67
		
68
		TableWrapLayout layout =new TableWrapLayout();
69
		form.getBody().setLayout(layout);
70
		Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
71
		section.setText("Local field messages");
72
		Composite sbody = toolkit.createComposite(section);
73
		section.setClient(sbody);
74
		GridLayout glayout = new GridLayout();
75
		glayout.horizontalSpacing = 10;
76
		glayout.numColumns= 2;
77
		sbody.setLayout(glayout);
78
		createDecoratedTextField("Field1", toolkit, sbody, mmng);
79
		createDecoratedTextField("Field2", toolkit, sbody, mmng);
80
		createDecoratedTextField("Field3", toolkit, sbody, mmng);
81
		final Button button1 = toolkit.createButton(form.getBody(), "Add general error", SWT.CHECK);
82
		button1.addSelectionListener(new SelectionAdapter() {
83
			public void widgetSelected(SelectionEvent e) {
84
				if (button1.getSelection()) {
85
					mmng.addMessage("saveError", "Save Error", IMessageProvider.ERROR);
86
				}
87
				else {
88
					mmng.removeMessage("saveError");
89
				}
90
			}
91
		});
92
		final Button button2 = toolkit.createButton(form.getBody(), "Add static message", SWT.CHECK);
93
		button2.addSelectionListener(new SelectionAdapter() {
94
			public void widgetSelected(SelectionEvent e) {
95
				if (button2.getSelection()) {
96
					mmng.addMessage("info", "Secondary info", IMessageProvider.NONE);
97
				}
98
				else {
99
					mmng.removeMessage("info");
100
				}
101
			}
102
		});
103
		final Button button3 = toolkit.createButton(form.getBody(), "Open Wizard", SWT.PUSH);
104
		button3.addSelectionListener(new SelectionAdapter() {
105
			public void widgetSelected(SelectionEvent e) {
106
				Wizard w = new Wizard() {
107
					public boolean performFinish() {
108
						return true;
109
					}
110
					public void addPages() {
111
						addPage(new ErrorMessagesWizardPage("id"));
112
					}
113
				};
114
				WizardDialog dialog = new WizardDialog(form.getShell(), w);
115
				dialog.create();
116
				dialog.getShell().setSize(300, 400);
117
				dialog.getShell().setText("Field Error Messages");
118
				dialog.open();
119
			}
120
		});		
121
		
122
	}
123
	
124
	private void createDecoratedTextField(String label, FormToolkit toolkit, Composite parent, final MessageManager mmng) {
125
		toolkit.createLabel(parent, label);
126
		final Text text = toolkit.createText(parent, "");
127
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
128
		gd.widthHint = 150;
129
		text.setLayoutData(gd);
130
		text.addModifyListener(new ModifyListener() {
131
			public void modifyText(ModifyEvent e) {
132
				String s = text.getText();
133
				// flag length
134
				if (s.length()>5 && s.length()<=10) {
135
					mmng.addMessage("textLength", "Text is longer than 5 characters", IMessageProvider.WARNING, text);
136
				}
137
				else if (s.length()>10) {
138
					mmng.addMessage("textLength", "Text is longer than 10 characters", IMessageProvider.ERROR, text);
139
				}
140
				else {
141
					mmng.removeMessage("textLength", text);
142
				}
143
				// flag type
144
				boolean badType=false;
145
				for (int i=0; i<s.length(); i++) {
146
					if (!Character.isLetter(s.charAt(i))) {
147
						badType=true;
148
						break;
149
					}
150
				}
151
				if (badType) {
152
					mmng.addMessage("textType", "Text must only contain letters", IMessageProvider.ERROR, text);
153
				}
154
				else {
155
					mmng.removeMessage("textType", text);
156
				}				
157
			}
158
		});
159
	}
160
}

Return to bug 168769