01: package org.drools.eclipse.flow.ruleflow.editor.action;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.eclipse.DroolsEclipsePlugin;
20: import org.drools.eclipse.flow.ruleflow.editor.RuleFlowModelEditor;
21: import org.drools.ruleflow.core.RuleFlowProcessValidationError;
22: import org.drools.ruleflow.core.impl.RuleFlowProcessValidatorImpl;
23: import org.eclipse.core.runtime.IStatus;
24: import org.eclipse.core.runtime.Status;
25: import org.eclipse.jface.action.IAction;
26: import org.eclipse.jface.dialogs.ErrorDialog;
27: import org.eclipse.jface.dialogs.MessageDialog;
28: import org.eclipse.ui.IEditorActionDelegate;
29: import org.eclipse.ui.IEditorPart;
30: import org.eclipse.ui.actions.ActionDelegate;
31:
32: /**
33: * Action for checking a RuleFlow.
34: *
35: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
36: */
37: public class CheckRuleFlowAction extends ActionDelegate implements
38: IEditorActionDelegate {
39:
40: private IEditorPart editor;
41:
42: public void run(IAction action) {
43: execute();
44: }
45:
46: public void setActiveEditor(IAction action, IEditorPart targetEditor) {
47: editor = targetEditor;
48: }
49:
50: private void execute() {
51: RuleFlowProcessValidationError[] errors = RuleFlowProcessValidatorImpl
52: .getInstance().validateProcess(
53: ((RuleFlowModelEditor) editor)
54: .getRuleFlowModel()
55: .getRuleFlowProcess());
56: if (errors.length == 0) {
57: MessageDialog.openInformation(editor.getSite().getShell(),
58: "Check RuleFlow",
59: "The RuleFlow model was checked successfully.");
60: } else {
61: StringBuffer error = new StringBuffer(errors[0].toString());
62: error.append("\n");
63: for (int i = 1; i < errors.length; i++) {
64: error.append(" ");
65: error.append(errors[i]);
66: error.append("\n");
67: }
68: ErrorDialog.openError(editor.getSite().getShell(),
69: "Check RuleFlow",
70: "The RuleFlow model contains errors.", new Status(
71: IStatus.ERROR, DroolsEclipsePlugin
72: .getDefault().getBundle()
73: .getSymbolicName(), IStatus.ERROR,
74: error.toString(), null));
75: }
76:
77: }
78: }
|