View Javadoc
1   /**
2    * 
3    * Copyright (c) 2014, Openflexo
4    * 
5    * This file is part of Gina-swing-editor, 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.widget;
40  
41  import java.util.logging.Logger;
42  
43  import org.openflexo.connie.annotations.NotificationUnsafe;
44  import org.openflexo.gina.ApplicationFIBLibrary;
45  import org.openflexo.gina.FIBLibrary;
46  import org.openflexo.gina.model.FIBComponent;
47  import org.openflexo.gina.model.FIBMouseEvent;
48  import org.openflexo.gina.swing.editor.SwingEditorFIBController;
49  import org.openflexo.rm.Resource;
50  
51  public class LibraryBrowserFIBController extends SwingEditorFIBController<FIBLibrary> {
52  
53  	private static final Logger logger = Logger.getLogger(LibraryBrowserFIBController.class.getPackage().getName());
54  
55  	private FIBLibraryBrowser fibLibraryBrowser;
56  
57  	public LibraryBrowserFIBController(FIBComponent rootComponent) {
58  		super(rootComponent);
59  	}
60  
61  	public Resource getSelectedComponentResource() {
62  		if (fibLibraryBrowser != null) {
63  			return fibLibraryBrowser.getSelectedComponentResource();
64  		}
65  		return null;
66  	}
67  
68  	public void setSelectedComponentResource(Resource selectedComponentResource) {
69  		if (fibLibraryBrowser != null) {
70  			fibLibraryBrowser.setSelectedComponentResource(selectedComponentResource);
71  			getPropertyChangeSupport().firePropertyChange("selectedComponentResource", null, selectedComponentResource);
72  		}
73  	}
74  
75  	public void doubleClickOnComponentResource(Resource selectedComponentResource) {
76  		if (fibLibraryBrowser != null) {
77  			fibLibraryBrowser.doubleClickOnComponentResource(selectedComponentResource);
78  		}
79  	}
80  
81  	@NotificationUnsafe
82  	public String textFor(Object object) {
83  		if (object == null) {
84  			return null;
85  		}
86  		if (object instanceof Resource) {
87  			String relativePath = ((Resource) object).getRelativePath();
88  			if (relativePath.lastIndexOf("/") > -1) {
89  				return relativePath.substring(relativePath.lastIndexOf("/") + 1);
90  			}
91  			return relativePath;
92  		}
93  		else if (object instanceof ApplicationFIBLibrary) {
94  			return "ApplicationFIBLibrary";
95  		}
96  		else if (object instanceof FIBLibrary) {
97  			return "FIBLibrary";
98  		}
99  		return object.toString();
100 
101 	}
102 
103 	public void rightClick(Resource resource, FIBMouseEvent event) {
104 		System.out.println("rightClick with " + resource + " event=" + event);
105 		// editorController.getContextualMenu().displayPopupMenu(component,
106 		// /*((JFIBView<?, ?>) getRootView()).getJComponent()*/(Component) event.getSource(), event.getPoint());
107 	}
108 
109 	public FIBLibraryBrowser getFIBLibraryBrowser() {
110 		return fibLibraryBrowser;
111 	}
112 
113 	public void setFIBLibraryBrowser(FIBLibraryBrowser fibLibraryBrowser) {
114 		if ((fibLibraryBrowser == null && this.fibLibraryBrowser != null)
115 				|| (fibLibraryBrowser != null && !fibLibraryBrowser.equals(this.fibLibraryBrowser))) {
116 			FIBLibraryBrowser oldValue = this.fibLibraryBrowser;
117 			this.fibLibraryBrowser = fibLibraryBrowser;
118 			getPropertyChangeSupport().firePropertyChange("fibLibraryBrowser", oldValue, fibLibraryBrowser);
119 		}
120 	}
121 
122 }