KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > EditorValidationStack


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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;
12
13 import java.util.Stack JavaDoc;
14
15 import org.eclipse.ui.forms.IManagedForm;
16 import org.eclipse.ui.forms.editor.IFormPage;
17 import org.eclipse.ui.forms.widgets.Form;
18
19 public class EditorValidationStack implements IEditorValidationStack {
20
21     private PDEFormEditor fEditor;
22     private Stack JavaDoc fStack = new Stack JavaDoc();
23     
24     public EditorValidationStack(PDEFormEditor editor) {
25         fEditor = editor;
26     }
27     
28     public void push(IEditorValidator validator) {
29         Form form = getForm(validator);
30         if (form != null && validator.markedInvalid()) {
31             if (!fStack.contains(validator))
32                 fStack.push(validator);
33             form.setMessage(validator.getMessage(), validator.getSeverity());
34         }
35     }
36
37     public void top() {
38         IEditorValidator top = getTopValidator();
39         Form form = getForm(top);
40         if (form == null)
41             return;
42         if (top == null)
43             form.setMessage(null);
44         else
45             form.setMessage(top.getMessage(), top.getSeverity());
46     }
47
48     private IEditorValidator getTopValidator() {
49         if (fStack.isEmpty()) return null;
50         IEditorValidator currTop = (IEditorValidator)fStack.peek();
51         while (!currTop.markedInvalid()) {
52             fStack.pop();
53             if (fStack.isEmpty())
54                 return null;
55             currTop = (IEditorValidator)fStack.peek();
56         }
57         return currTop;
58     }
59     
60     private Form getForm(IEditorValidator validator) {
61         IFormPage page = fEditor.getActivePageInstance();
62         if (validator != null && page == null)
63             page = validator.getSection().getPage();
64         if (page == null)
65             return null;
66         IManagedForm mform = page.getManagedForm();
67         return mform == null ? null : mform.getForm().getForm();
68     }
69     
70     public boolean isEmpty() {
71         return fStack.isEmpty();
72     }
73 }
74
Popular Tags