KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.jface.dialogs.IMessageProvider;
14 import org.eclipse.pde.internal.ui.PDEUIMessages;
15
16 public abstract class AbstractFormValidator implements IEditorValidator {
17
18     private boolean fEnabled;
19     private boolean fInputValidates = true;
20     private String JavaDoc fMessage = PDEUIMessages.AbstractFormValidator_noMessageSet;
21     private int fSeverity = IMessageProvider.WARNING;
22     private PDESection fSection;
23     
24     public AbstractFormValidator(PDESection section) {
25         fSection = section;
26         fEnabled = fSection.isEditable();
27     }
28     
29     public boolean isEnabled() {
30         return fEnabled;
31     }
32
33     public void setEnabled(boolean enable) {
34         if (fSection.isEditable()) {
35             fEnabled = enable;
36             validate(enable);
37         }
38     }
39     
40     public void setMessage(String JavaDoc message) {
41         fMessage = message != null ? message : PDEUIMessages.AbstractFormValidator_noMessageSet;
42     }
43     
44     public String JavaDoc getMessage() {
45         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
46         if (!fSection.getPage().isActive()) {
47             buff.append('[');
48             buff.append(fSection.getPage().getTitle());
49             buff.append(']');
50         }
51         buff.append('[');
52         buff.append(fSection.getSection().getText());
53         buff.append(']');
54         buff.append(' ');
55         buff.append(fMessage);
56         return buff.toString();
57     }
58     
59     public void setSeverity(int severity) {
60         if (severity >= 0)
61             fSeverity = severity;
62     }
63     
64     public int getSeverity() {
65         return fSeverity;
66     }
67     
68     public PDESection getSection() {
69         return fSection;
70     }
71     
72     public boolean markedInvalid() {
73         return isEnabled() && !fInputValidates;
74     }
75     
76     public final boolean validate(boolean revalidate) {
77         IEditorValidationStack stack = fSection.getPage().getPDEEditor().getValidationStack();
78         if (!isEnabled()) {
79             stack.top();
80             return true;
81         }
82         if (revalidate) {
83             fInputValidates = inputValidates();
84             if (fInputValidates)
85                 stack.top();
86             else
87                 stack.push(this);
88         }
89         return fInputValidates;
90     }
91 }
92
Popular Tags