View Javadoc
1   /**
2    * 
3    * Copyright (c) 2013-2014, Openflexo
4    * Copyright (c) 2011-2012, AgileBirds
5    * 
6    * This file is part of Gina-swing-editor, 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.view.widget;
41  
42  import java.util.logging.Logger;
43  
44  import javax.swing.JComponent;
45  
46  import org.openflexo.gina.controller.FIBController;
47  import org.openflexo.gina.model.FIBComponent;
48  import org.openflexo.gina.model.widget.FIBReferencedComponent;
49  import org.openflexo.gina.swing.editor.controller.FIBEditorController;
50  import org.openflexo.gina.swing.editor.view.FIBSwingEditableView;
51  import org.openflexo.gina.swing.editor.view.FIBSwingEditableViewDelegate;
52  import org.openflexo.gina.swing.view.SwingViewFactory;
53  import org.openflexo.gina.swing.view.widget.JFIBReferencedComponentWidget;
54  import org.openflexo.gina.swing.view.widget.JFIBReferencedComponentWidget.JReferenceComponentPanel;
55  import org.openflexo.logging.FlexoLogger;
56  
57  public class JFIBEditableReferencedComponentWidget extends JFIBReferencedComponentWidget
58  		implements FIBSwingEditableView<FIBReferencedComponent, JReferenceComponentPanel> {
59  
60  	@SuppressWarnings("unused")
61  	private static final Logger logger = FlexoLogger.getLogger(JFIBEditableReferencedComponentWidget.class.getPackage().getName());
62  
63  	private final FIBSwingEditableViewDelegate<FIBReferencedComponent, JReferenceComponentPanel> delegate;
64  
65  	private final FIBEditorController editorController;
66  
67  	@Override
68  	public JComponent getDraggableComponent() {
69  		return getTechnologyComponent();
70  	}
71  
72  	@Override
73  	public FIBEditorController getEditorController() {
74  		return editorController;
75  	}
76  
77  	public JFIBEditableReferencedComponentWidget(FIBReferencedComponent model, FIBEditorController editorController) {
78  		super(model, editorController.getController());
79  		this.editorController = editorController;
80  
81  		delegate = new FIBSwingEditableViewDelegate<>(this);
82  	}
83  
84  	@Override
85  	public synchronized void delete() {
86  		delegate.delete();
87  		super.delete();
88  	}
89  
90  	@Override
91  	public FIBSwingEditableViewDelegate<FIBReferencedComponent, JReferenceComponentPanel> getDelegate() {
92  		return delegate;
93  	}
94  
95  	@Override
96  	protected FIBController makeEmbeddedFIBController(FIBComponent component) {
97  		// We dont want here to use the EditableViewFactory, otherwise, FIBController will be the one used by embedding component
98  		// TODO: if we want the referenced component to be editable, instanciate a new SwingEditorViewFactory
99  		return FIBController.instanciateController(component, /*getController().getViewFactory()*/SwingViewFactory.INSTANCE,
100 				getController().getLocalizer());
101 	}
102 
103 	private boolean operatorContentsStart = false;
104 
105 	// TODO: avoid code duplication in FIBSwingEditableView
106 	@Override
107 	public boolean isOperatorContentsStart() {
108 		return operatorContentsStart;
109 	}
110 
111 	// TODO: avoid code duplication in FIBSwingEditableView
112 	@Override
113 	public void setOperatorContentsStart(boolean operatorContentsStart) {
114 		if (operatorContentsStart != this.operatorContentsStart) {
115 			this.operatorContentsStart = operatorContentsStart;
116 			FIBSwingEditableView.updateOperatorContentsStart(this, operatorContentsStart);
117 			getPropertyChangeSupport().firePropertyChange("operatorContentsStart", !operatorContentsStart, operatorContentsStart);
118 		}
119 	}
120 
121 }