View Javadoc

1   /*
2    *  
3    *  Fosstrak LLRP Commander (www.fosstrak.org)
4    * 
5    *  Copyright (C) 2008 ETH Zurich
6    *
7    *  This program is free software: you can redistribute it and/or modify
8    *  it under the terms of the GNU General Public License as published by
9    *  the Free Software Foundation, either version 3 of the License, or
10   *  (at your option) any later version.
11   *
12   *  This program is distributed in the hope that it will be useful,
13   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   *  GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License
18   *  along with this program.  If not, see <http://www.gnu.org/licenses/> 
19   *
20   */
21  
22  package org.fosstrak.llrp.commander.editors.graphical;
23  
24  import java.util.Observable;
25  import java.util.Observer;
26  
27  import org.eclipse.ui.forms.IManagedForm;
28  import org.eclipse.ui.forms.editor.FormPage;
29  import org.eclipse.ui.forms.widgets.ScrolledForm;
30  import org.fosstrak.llrp.commander.editors.LLRPEditor;
31  import org.fosstrak.llrp.commander.util.LLRPTreeMaintainer;
32  import org.llrp.ltk.types.LLRPMessage;
33  
34  /**
35   * The GraphicalEditorPage is the root class of the graphical editor. It has a 
36   * LLRPMasterDetailsBlock.
37   *
38   * @author Ulrich Etter, ETHZ
39   *
40   */
41  public class GraphicalEditorPage extends FormPage implements Observer {
42  		
43  	private final static String GRAPHICAL_EDITOR_TITLE = "Graphical Editor";
44  	private LLRPEditor editor;
45  	private LLRPMasterDetailsBlock masterDetailsBlock;
46  	private LLRPTreeMaintainer treeMaintainer;
47  	private boolean masterDetailsBlockCreated;
48  	private boolean dirty;
49  	
50  	/**
51  	 * Creates a new GraphicalEditorPage.
52  	 * 
53  	 * @param editor the editor this editor page belongs to
54  	 */
55  	public GraphicalEditorPage(LLRPEditor editor) {
56  		super(editor, "graphicalEditor", GRAPHICAL_EDITOR_TITLE);
57  		this.editor = editor;
58  		treeMaintainer = new LLRPTreeMaintainer(null);		
59  		treeMaintainer.addObserver(this);
60  		masterDetailsBlock = new LLRPMasterDetailsBlock(this, this.treeMaintainer);
61  	}
62  	
63  	/* (non-Javadoc)
64  	 * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
65  	 */
66  	protected void createFormContent(final IManagedForm managedForm) {
67  		final ScrolledForm form = managedForm.getForm();
68  		form.setText(GRAPHICAL_EDITOR_TITLE);
69  		masterDetailsBlock.createContent(managedForm);
70  		masterDetailsBlockCreated = true;
71  	}
72  	
73  	/**
74  	 * Returns the LLRP message that is currently displayed in the graphical editor.
75  	 * 
76  	 * @return the LLRP message that is currently displayed in the graphical editor
77  	 */
78  	public LLRPMessage getLLRPMessage(){
79  		return treeMaintainer.getRoot();
80  	}
81  
82  	/**
83  	 * Changes the message currently displayed in the graphical editor to the given message.
84  	 * 
85  	 * @param lLRPMessage the message that should be displayed in the graphical editor
86  	 */
87  	public void setLLRPMessage(LLRPMessage lLRPMessage){
88  		this.treeMaintainer.setRoot(lLRPMessage);
89  		dirty = false;
90  		if (masterDetailsBlockCreated){
91  			masterDetailsBlock.refresh(treeMaintainer.getRoot());
92  		}
93  	}
94  
95  	/**
96  	 * @return <code>true</code> if the graphical editor is dirty, and <code>false</code> otherwise.
97  	 */
98  	public boolean isGraphicalEditorDirty() {
99  		return dirty;
100 	}
101 
102 	/**
103 	 * Sets the dirty flag to the given value.
104 	 */
105 	public void setDirty(boolean dirty) {
106 		this.dirty = dirty;
107 	}
108 
109 	public void update(Observable arg0, Object arg1) {
110 		if ((arg0 == treeMaintainer) && (!dirty)){
111 			dirty = true;
112 			editor.markXMLEditorAsDirty();
113 		}
114 	}
115 }