View Javadoc
1   /**
2    * 
3    * Copyright (c) 2014, Openflexo
4    * 
5    * This file is part of Gina-swing, a component of the software infrastructure 
6    * developed at Openflexo.
7    * 
8    * 
9    * Openflexo is dual-licensed under the European Union Public License (EUPL, either 
10   * version 1.1 of the License, or any later version ), which is available at 
11   * https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
12   * and the GNU General Public License (GPL, either version 3 of the License, or any 
13   * later version), which is available at http://www.gnu.org/licenses/gpl.html .
14   * 
15   * You can redistribute it and/or modify under the terms of either of these licenses
16   * 
17   * If you choose to redistribute it and/or modify under the terms of the GNU GPL, you
18   * must include the following additional permission.
19   *
20   *          Additional permission under GNU GPL version 3 section 7
21   *
22   *          If you modify this Program, or any covered work, by linking or 
23   *          combining it with software containing parts covered by the terms 
24   *          of EPL 1.0, the licensors of this Program grant you additional permission
25   *          to convey the resulting work. * 
26   * 
27   * This software is distributed in the hope that it will be useful, but WITHOUT ANY 
28   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
29   * PARTICULAR PURPOSE. 
30   *
31   * See http://www.openflexo.org/license.html for details.
32   * 
33   * 
34   * Please contact Openflexo (openflexo-contacts@openflexo.org)
35   * or visit www.openflexo.org if you need additional information.
36   * 
37   */
38  
39  package org.openflexo.gina.swing.editor.validation;
40  
41  import org.openflexo.gina.FIBLibrary;
42  import org.openflexo.gina.model.FIBComponent;
43  import org.openflexo.gina.swing.utils.FIBJPanel;
44  import org.openflexo.gina.swing.view.SwingViewFactory;
45  import org.openflexo.localization.LocalizedDelegate;
46  import org.openflexo.pamela.validation.Validable;
47  import org.openflexo.pamela.validation.ValidationIssue;
48  import org.openflexo.pamela.validation.ValidationModel;
49  import org.openflexo.pamela.validation.ValidationReport;
50  import org.openflexo.rm.Resource;
51  import org.openflexo.rm.ResourceLocator;
52  
53  @SuppressWarnings("serial")
54  public abstract class ValidationDialogPanel extends FIBJPanel<ValidationReport> {
55  
56  	public static Resource VALIDATION_PANEL_FIB = ResourceLocator.locateResource("Fib/ValidationDialog.fib");
57  
58  	public ValidationDialogPanel(ValidationReport validationReport, FIBLibrary fibLibrary, LocalizedDelegate parentLocalizer) {
59  		super(fibLibrary.retrieveFIBComponent(VALIDATION_PANEL_FIB, true), validationReport, parentLocalizer);
60  	}
61  
62  	@Override
63  	protected ValidationFIBController makeFIBController(FIBComponent fibComponent, LocalizedDelegate parentLocalizer) {
64  		return new ValidationFIBController(fibComponent, SwingViewFactory.INSTANCE) {
65  			@Override
66  			protected void performSelect(ValidationIssue<?, ?> validationIssue) {
67  				ValidationDialogPanel.this.performSelect(validationIssue);
68  			}
69  		};
70  	}
71  
72  	@Override
73  	public ValidationFIBController getController() {
74  		return (ValidationFIBController) super.getController();
75  	}
76  
77  	protected abstract void performSelect(ValidationIssue<?, ?> validationIssue);
78  
79  	protected void performValidation(ValidationModel validationModel, Validable objectToValidate) throws InterruptedException {
80  		// startValidation(validationModel);
81  		ValidationReport report = validationModel.validate(objectToValidate);
82  		// stopValidation(validationModel);
83  		getController().setDataObject(report);
84  	}
85  
86  	public void validate(ValidationModel validationModel, Validable objectToValidate) throws InterruptedException {
87  		performValidation(validationModel, objectToValidate);
88  	}
89  
90  	@Override
91  	public Class<ValidationReport> getRepresentedType() {
92  		return ValidationReport.class;
93  	}
94  
95  	@Override
96  	public void delete() {
97  		// TODO
98  	}
99  
100 	/*public void startValidation(ValidationModel validationModel) {
101 	}
102 	
103 	public void stopValidation(ValidationModel validationModel) {
104 	}*/
105 }