View Javadoc
1   /**
2    * 
3    * Copyright (c) 2013-2014, Openflexo
4    * Copyright (c) 2011-2012, AgileBirds
5    * 
6    * This file is part of Flexo-ui, a component of the software infrastructure 
7    * developed at Openflexo.
8    * 
9    * 
10   * Openflexo is dual-licensed under the European Union Public License (EUPL, either 
11   * version 1.1 of the License, or any later version ), which is available at 
12   * https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
13   * and the GNU General Public License (GPL, either version 3 of the License, or any 
14   * later version), which is available at http://www.gnu.org/licenses/gpl.html .
15   * 
16   * You can redistribute it and/or modify under the terms of either of these licenses
17   * 
18   * If you choose to redistribute it and/or modify under the terms of the GNU GPL, you
19   * must include the following additional permission.
20   *
21   *          Additional permission under GNU GPL version 3 section 7
22   *
23   *          If you modify this Program, or any covered work, by linking or 
24   *          combining it with software containing parts covered by the terms 
25   *          of EPL 1.0, the licensors of this Program grant you additional permission
26   *          to convey the resulting work. * 
27   * 
28   * This software is distributed in the hope that it will be useful, but WITHOUT ANY 
29   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
30   * PARTICULAR PURPOSE. 
31   *
32   * See http://www.openflexo.org/license.html for details.
33   * 
34   * 
35   * Please contact Openflexo (openflexo-contacts@openflexo.org)
36   * or visit www.openflexo.org if you need additional information.
37   * 
38   */
39  
40  package org.openflexo.gina.swing.editor.validation;
41  
42  import java.util.logging.Logger;
43  
44  import org.openflexo.gina.model.FIBValidationModel;
45  import org.openflexo.gina.swing.editor.controller.FIBEditorController;
46  import org.openflexo.logging.FlexoLogger;
47  import org.openflexo.pamela.validation.FixProposal;
48  import org.openflexo.pamela.validation.ProblemIssue;
49  import org.openflexo.pamela.validation.Validable;
50  import org.openflexo.pamela.validation.ValidationRule;
51  import org.openflexo.pamela.validation.ValidationWarning;
52  import org.openflexo.toolbox.PropertyChangedSupportDefaultImplementation;
53  
54  public class IssueFixing<R extends ValidationRule<R, V>, V extends Validable> extends PropertyChangedSupportDefaultImplementation {
55  
56  	private static final Logger logger = FlexoLogger.getLogger(IssueFixing.class.getPackage().getName());
57  
58  	private ProblemIssue<R, V> issue;
59  	private FIBValidationModel validationModel;
60  	private FIBEditorController editorController;
61  
62  	public IssueFixing(ProblemIssue<R, V> issue, FIBEditorController editorController) {
63  		super();
64  		this.issue = issue;
65  		this.editorController = editorController;
66  		validationModel = editorController.getValidationModel();
67  	}
68  
69  	public ProblemIssue<?, ?> getIssue() {
70  		return issue;
71  	}
72  
73  	public FIBValidationModel getValidationModel() {
74  		return validationModel;
75  	}
76  
77  	public FIBEditorController getEditorController() {
78  		return editorController;
79  	}
80  
81  	public boolean isFixable() {
82  		return fixProposal != null;
83  	}
84  
85  	public boolean isIgnorable() {
86  		return issue instanceof ValidationWarning;
87  	}
88  
89  	public void fix() {
90  		System.out.println("Applying fix proposal " + fixProposal);
91  		fixProposal.apply(true);
92  	}
93  
94  	public void ignore() {
95  		System.out.println("Ignoring");
96  	}
97  
98  	FixProposal<R, V> fixProposal;
99  
100 	public FixProposal<R, V> getFixProposal() {
101 		return fixProposal;
102 	}
103 
104 	public void setFixProposal(FixProposal<R, V> fixProposal) {
105 		System.out.println("On set le fixProposal a " + fixProposal);
106 		if ((fixProposal == null && this.fixProposal != null) || (fixProposal != null && !fixProposal.equals(this.fixProposal))) {
107 			FixProposal<R, V> oldValue = this.fixProposal;
108 			this.fixProposal = fixProposal;
109 			getPropertyChangeSupport().firePropertyChange("fixProposal", oldValue, fixProposal);
110 			getPropertyChangeSupport().firePropertyChange("isFixable", !isFixable(), isFixable());
111 			getPropertyChangeSupport().firePropertyChange("isIgnorable", !isIgnorable(), isIgnorable());
112 		}
113 	}
114 }