View Javadoc
1   /**
2    * 
3    * Copyright (c) 2013-2015, Openflexo
4    * Copyright (c) 2011-2012, AgileBirds
5    * 
6    * This file is part of Gina-core, 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  package org.openflexo.gina.swing.editor.controller;
40  
41  import javax.swing.JComponent;
42  
43  import org.openflexo.gina.controller.FIBController;
44  import org.openflexo.gina.model.bindings.RuntimeContext;
45  import org.openflexo.gina.model.container.FIBPanel;
46  import org.openflexo.gina.model.container.FIBSplitPanel;
47  import org.openflexo.gina.model.container.FIBTab;
48  import org.openflexo.gina.model.container.FIBTabPanel;
49  import org.openflexo.gina.model.operator.FIBIteration;
50  import org.openflexo.gina.model.widget.FIBBrowser;
51  import org.openflexo.gina.model.widget.FIBButton;
52  import org.openflexo.gina.model.widget.FIBCheckBox;
53  import org.openflexo.gina.model.widget.FIBCheckboxList;
54  import org.openflexo.gina.model.widget.FIBColor;
55  import org.openflexo.gina.model.widget.FIBCustom;
56  import org.openflexo.gina.model.widget.FIBDate;
57  import org.openflexo.gina.model.widget.FIBDropDown;
58  import org.openflexo.gina.model.widget.FIBEditor;
59  import org.openflexo.gina.model.widget.FIBFile;
60  import org.openflexo.gina.model.widget.FIBFont;
61  import org.openflexo.gina.model.widget.FIBHtmlEditor;
62  import org.openflexo.gina.model.widget.FIBImage;
63  import org.openflexo.gina.model.widget.FIBLabel;
64  import org.openflexo.gina.model.widget.FIBList;
65  import org.openflexo.gina.model.widget.FIBNumber;
66  import org.openflexo.gina.model.widget.FIBRadioButtonList;
67  import org.openflexo.gina.model.widget.FIBReferencedComponent;
68  import org.openflexo.gina.model.widget.FIBTable;
69  import org.openflexo.gina.model.widget.FIBTextArea;
70  import org.openflexo.gina.model.widget.FIBTextField;
71  import org.openflexo.gina.swing.editor.view.container.JFIBEditableIterationView;
72  import org.openflexo.gina.swing.editor.view.container.JFIBEditablePanelView;
73  import org.openflexo.gina.swing.editor.view.container.JFIBEditableSplitPanelView;
74  import org.openflexo.gina.swing.editor.view.container.JFIBEditableTabPanelView;
75  import org.openflexo.gina.swing.editor.view.container.JFIBEditableTabView;
76  import org.openflexo.gina.swing.editor.view.widget.JFDFIBEditableTableWidget;
77  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableBrowserWidget;
78  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableButtonWidget;
79  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableCheckboxListWidget;
80  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableCheckboxWidget;
81  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableColorWidget;
82  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableCustomWidget;
83  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableDateWidget;
84  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableDropDownWidget;
85  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableEditorWidget;
86  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableFileWidget;
87  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableFontWidget;
88  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableHtmlEditorWidget;
89  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableImageWidget;
90  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableLabelWidget;
91  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableListWidget;
92  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableNumberWidget;
93  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableRadioButtonListWidget;
94  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableReferencedComponentWidget;
95  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableTableWidget;
96  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableTextAreaWidget;
97  import org.openflexo.gina.swing.editor.view.widget.JFIBEditableTextFieldWidget;
98  import org.openflexo.gina.swing.view.SwingViewFactory;
99  import org.openflexo.gina.view.container.FIBPanelView;
100 import org.openflexo.gina.view.container.FIBSplitPanelView;
101 import org.openflexo.gina.view.container.FIBTabPanelView;
102 import org.openflexo.gina.view.container.FIBTabView;
103 import org.openflexo.gina.view.operator.FIBIterationView;
104 import org.openflexo.gina.view.widget.FIBLabelWidget;
105 import org.openflexo.gina.view.widget.FIBTextFieldWidget;
106 import org.openflexo.gina.view.widget.impl.FIBBrowserWidgetImpl;
107 import org.openflexo.gina.view.widget.impl.FIBButtonWidgetImpl;
108 import org.openflexo.gina.view.widget.impl.FIBCheckBoxWidgetImpl;
109 import org.openflexo.gina.view.widget.impl.FIBCheckboxListWidgetImpl;
110 import org.openflexo.gina.view.widget.impl.FIBColorWidgetImpl;
111 import org.openflexo.gina.view.widget.impl.FIBCustomWidgetImpl;
112 import org.openflexo.gina.view.widget.impl.FIBDateWidgetImpl;
113 import org.openflexo.gina.view.widget.impl.FIBDropDownWidgetImpl;
114 import org.openflexo.gina.view.widget.impl.FIBEditorWidgetImpl;
115 import org.openflexo.gina.view.widget.impl.FIBFileWidgetImpl;
116 import org.openflexo.gina.view.widget.impl.FIBFontWidgetImpl;
117 import org.openflexo.gina.view.widget.impl.FIBHtmlEditorWidgetImpl;
118 import org.openflexo.gina.view.widget.impl.FIBImageWidgetImpl;
119 import org.openflexo.gina.view.widget.impl.FIBListWidgetImpl;
120 import org.openflexo.gina.view.widget.impl.FIBNumberWidgetImpl;
121 import org.openflexo.gina.view.widget.impl.FIBRadioButtonListWidgetImpl;
122 import org.openflexo.gina.view.widget.impl.FIBReferencedComponentWidgetImpl;
123 import org.openflexo.gina.view.widget.impl.FIBTableWidgetImpl;
124 import org.openflexo.gina.view.widget.impl.FIBTextAreaWidgetImpl;
125 
126 /**
127  * Extends {@link SwingViewFactory} by providing editable views in the context of Swing editor
128  * 
129  * @author sylvain
130  *
131  */
132 public class SwingEditorViewFactory extends SwingViewFactory {
133 	/**
134 	 * 
135 	 */
136 	private final FIBEditorController fibEditorController;
137 
138 	/**
139 	 * @param fibEditorController
140 	 */
141 	SwingEditorViewFactory(FIBEditorController fibEditorController) {
142 		this.fibEditorController = fibEditorController;
143 	}
144 
145 	@Override
146 	public FIBTabView<? extends JComponent, ? extends JComponent> makeTabView(FIBTab container, FIBController controller,
147 			RuntimeContext context) {
148 		return new JFIBEditableTabView(container, fibEditorController);
149 	}
150 
151 	@Override
152 	public FIBPanelView<? extends JComponent, ? extends JComponent> makePanelView(FIBPanel container, FIBController controller,
153 			RuntimeContext context) {
154 		return new JFIBEditablePanelView(container, fibEditorController);
155 	}
156 
157 	@Override
158 	public FIBIterationView<? extends JComponent, ? extends JComponent> makeIterationView(FIBIteration iteration, FIBController controller,
159 			RuntimeContext context) {
160 		return new JFIBEditableIterationView(iteration, fibEditorController, context);
161 	}
162 
163 	@Override
164 	public FIBTabPanelView<? extends JComponent, ? extends JComponent> makeTabPanelView(FIBTabPanel container, FIBController controller,
165 			RuntimeContext context) {
166 		return new JFIBEditableTabPanelView(container, fibEditorController);
167 	}
168 
169 	@Override
170 	public FIBSplitPanelView<? extends JComponent, ? extends JComponent> makeSplitPanelView(FIBSplitPanel container,
171 			FIBController controller, RuntimeContext context) {
172 		return new JFIBEditableSplitPanelView(container, fibEditorController);
173 	}
174 
175 	@Override
176 	public FIBLabelWidget<? extends JComponent> makeLabel(FIBLabel widget, FIBController controller, RuntimeContext context) {
177 		return new JFIBEditableLabelWidget(widget, fibEditorController);
178 	}
179 
180 	@Override
181 	public FIBTextFieldWidget<? extends JComponent> makeTextField(FIBTextField widget, FIBController controller, RuntimeContext context) {
182 		return new JFIBEditableTextFieldWidget(widget, fibEditorController);
183 	}
184 
185 	@Override
186 	public FIBTextAreaWidgetImpl<? extends JComponent> makeTextArea(FIBTextArea widget, FIBController controller, RuntimeContext context) {
187 		return new JFIBEditableTextAreaWidget(widget, fibEditorController);
188 	}
189 
190 	@Override
191 	public FIBImageWidgetImpl<? extends JComponent> makeImage(FIBImage widget, FIBController controller, RuntimeContext context) {
192 		return new JFIBEditableImageWidget(widget, fibEditorController);
193 	}
194 
195 	@Override
196 	public FIBNumberWidgetImpl<? extends JComponent, ?> makeNumber(FIBNumber widget, FIBController controller, RuntimeContext context) {
197 		return new JFIBEditableNumberWidget<>(widget, fibEditorController);
198 	}
199 
200 	@Override
201 	public FIBCheckBoxWidgetImpl<? extends JComponent> makeCheckbox(FIBCheckBox widget, FIBController controller, RuntimeContext context) {
202 		return new JFIBEditableCheckboxWidget(widget, fibEditorController);
203 	}
204 
205 	@Override
206 	public FIBCheckboxListWidgetImpl<? extends JComponent, ?> makeCheckboxList(FIBCheckboxList widget, FIBController controller,
207 			RuntimeContext context) {
208 		return new JFIBEditableCheckboxListWidget<>(widget, fibEditorController);
209 	}
210 
211 	@Override
212 	public FIBRadioButtonListWidgetImpl<? extends JComponent, ?> makeRadioButtonList(FIBRadioButtonList widget, FIBController controller,
213 			RuntimeContext context) {
214 		return new JFIBEditableRadioButtonListWidget<>(widget, fibEditorController);
215 	}
216 
217 	@Override
218 	public FIBDropDownWidgetImpl<? extends JComponent, ?> makeDropDown(FIBDropDown widget, FIBController controller,
219 			RuntimeContext context) {
220 		return new JFIBEditableDropDownWidget<>(widget, fibEditorController);
221 	}
222 
223 	@Override
224 	public FIBListWidgetImpl<? extends JComponent, ?> makeList(FIBList widget, FIBController controller, RuntimeContext context) {
225 		return new JFIBEditableListWidget<>(widget, fibEditorController);
226 	}
227 
228 	@Override
229 	public FIBEditorWidgetImpl<? extends JComponent> makeEditor(FIBEditor widget, FIBController controller, RuntimeContext context) {
230 		return new JFIBEditableEditorWidget(widget, fibEditorController);
231 	}
232 
233 	@Override
234 	public FIBHtmlEditorWidgetImpl<? extends JComponent> makeHtmlEditor(FIBHtmlEditor widget, FIBController controller,
235 			RuntimeContext context) {
236 		return new JFIBEditableHtmlEditorWidget(widget, fibEditorController);
237 	}
238 
239 	@Override
240 	public FIBTableWidgetImpl<? extends JComponent, ?> makeTable(FIBTable widget, FIBController controller, RuntimeContext context) {
241 		if (widget.getLookAndFeel() != null) {
242 			switch (widget.getLookAndFeel()) {
243 				case Classic:
244 					return new JFIBEditableTableWidget<>(widget, fibEditorController);
245 				case FlatDesign:
246 					return new JFDFIBEditableTableWidget<>(widget, fibEditorController);
247 			}
248 		}
249 		return new JFIBEditableTableWidget<>(widget, fibEditorController);
250 	}
251 
252 	@Override
253 	public FIBBrowserWidgetImpl<? extends JComponent, ?> makeBrowser(FIBBrowser widget, FIBController controller, RuntimeContext context) {
254 		return new JFIBEditableBrowserWidget<>(widget, fibEditorController);
255 	}
256 
257 	@Override
258 	public FIBColorWidgetImpl<? extends JComponent> makeColor(FIBColor widget, FIBController controller, RuntimeContext context) {
259 		return new JFIBEditableColorWidget(widget, fibEditorController);
260 	}
261 
262 	@Override
263 	public FIBFontWidgetImpl<? extends JComponent> makeFont(FIBFont widget, FIBController controller, RuntimeContext context) {
264 		return new JFIBEditableFontWidget(widget, fibEditorController);
265 	}
266 
267 	@Override
268 	public FIBDateWidgetImpl<? extends JComponent> makeDate(FIBDate widget, FIBController controller, RuntimeContext context) {
269 		return new JFIBEditableDateWidget(widget, fibEditorController);
270 	}
271 
272 	@Override
273 	public FIBFileWidgetImpl<? extends JComponent> makeFile(FIBFile widget, FIBController controller, RuntimeContext context) {
274 		return new JFIBEditableFileWidget(widget, fibEditorController);
275 	}
276 
277 	@Override
278 	public FIBButtonWidgetImpl<? extends JComponent> makeButton(FIBButton widget, FIBController controller, RuntimeContext context) {
279 		return new JFIBEditableButtonWidget(widget, fibEditorController);
280 	}
281 
282 	@Override
283 	public FIBCustomWidgetImpl<? extends JComponent, ?, ?> makeCustomWidget(FIBCustom widget, FIBController controller,
284 			RuntimeContext context) {
285 		return new JFIBEditableCustomWidget<>(widget, fibEditorController);
286 	}
287 
288 	@Override
289 	public FIBReferencedComponentWidgetImpl<? extends JComponent> makeReferencedComponentWidget(FIBReferencedComponent widget,
290 			FIBController controller, RuntimeContext context) {
291 		return new JFIBEditableReferencedComponentWidget(widget, fibEditorController);
292 	}
293 
294 }