EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.sensorframework.visualisation.views]

COVERAGE SUMMARY FOR SOURCE FILE [TreeViewAdapters.java]

nameclass, %method, %block, %line, %
TreeViewAdapters.java0%   (0/4)0%   (0/20)0%   (0/285)0%   (0/84)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExperimentsAdapter0%   (0/1)0%   (0/13)0%   (0/160)0%   (0/48)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
ExperimentsAdapter (TreeViewer): void 0%   (0/1)0%   (0/20)0%   (0/6)
access$0 (ExperimentsAdapter): List 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (ExperimentsAdapter): TreeViewer 0%   (0/1)0%   (0/3)0%   (0/1)
access$2 (ExperimentsAdapter): IStructuredSelection 0%   (0/1)0%   (0/3)0%   (0/1)
addNavigationActions (IMenuManager): void 0%   (0/1)0%   (0/20)0%   (0/6)
addNavigationActions (IToolBarManager): void 0%   (0/1)0%   (0/1)0%   (0/1)
createActions (): void 0%   (0/1)0%   (0/13)0%   (0/3)
getCurrentSelection (): IStructuredSelection 0%   (0/1)0%   (0/12)0%   (0/3)
getSelectedExperimentAndDAOs (): List 0%   (0/1)0%   (0/36)0%   (0/11)
getSelectedExperiments (): List 0%   (0/1)0%   (0/37)0%   (0/11)
selectionChanged (SelectionChangedEvent): void 0%   (0/1)0%   (0/3)0%   (0/2)
updateNavigationButtons (): void 0%   (0/1)0%   (0/1)0%   (0/1)
     
class ExperimentsAdapter$DeleteAction0%   (0/1)0%   (0/2)0%   (0/45)0%   (0/14)
ExperimentsAdapter$DeleteAction (ExperimentsAdapter): void 0%   (0/1)0%   (0/15)0%   (0/6)
run (): void 0%   (0/1)0%   (0/30)0%   (0/8)
     
class ExperimentsAdapter$RenameAction0%   (0/1)0%   (0/2)0%   (0/63)0%   (0/18)
ExperimentsAdapter$RenameAction (ExperimentsAdapter): void 0%   (0/1)0%   (0/15)0%   (0/6)
run (): void 0%   (0/1)0%   (0/48)0%   (0/12)
     
class ExperimentsAdapter$RenameAction$NameValidator0%   (0/1)0%   (0/3)0%   (0/17)0%   (0/4)
ExperimentsAdapter$RenameAction$NameValidator (ExperimentsAdapter$RenameActio... 0%   (0/1)0%   (0/6)0%   (0/1)
ExperimentsAdapter$RenameAction$NameValidator (ExperimentsAdapter$RenameActio... 0%   (0/1)0%   (0/4)0%   (0/1)
isValid (String): String 0%   (0/1)0%   (0/7)0%   (0/3)

1package de.uka.ipd.sdq.sensorframework.visualisation.views;
2 
3import java.util.Iterator;
4import java.util.LinkedList;
5import java.util.List;
6 
7import org.eclipse.jface.action.Action;
8import org.eclipse.jface.action.IMenuManager;
9import org.eclipse.jface.action.IToolBarManager;
10import org.eclipse.jface.dialogs.IInputValidator;
11import org.eclipse.jface.dialogs.InputDialog;
12import org.eclipse.jface.viewers.ISelectionChangedListener;
13import org.eclipse.jface.viewers.IStructuredSelection;
14import org.eclipse.jface.viewers.SelectionChangedEvent;
15import org.eclipse.jface.viewers.TreeViewer;
16import org.eclipse.jface.window.Window;
17import org.eclipse.swt.widgets.Display;
18 
19import de.uka.ipd.sdq.sensorframework.entities.Experiment;
20import de.uka.ipd.sdq.sensorframework.entities.dao.IExperimentDAO;
21 
22/**
23 * Adapter class that supplies functionality applicable to Experiments
24 */
25class ExperimentsAdapter implements ISelectionChangedListener {
26 
27        private TreeViewer myChildTree;
28 
29        private Action myDeleteAction;
30        private Action myRenameAction;
31 
32        public ExperimentsAdapter(TreeViewer childTree) {
33                assert (childTree != null );
34                myChildTree = childTree;
35                createActions();
36                myChildTree.addSelectionChangedListener(this);
37        }
38 
39        /**
40         * Adds actions to the menu if the selection is a single experiment.
41         * This method is called every time the user right clicks to open
42         * a popup menu.
43         * @param manager the menu manager to add the actions to
44         */
45        public void addNavigationActions(IMenuManager manager) {
46                if (getSelectedExperiments().size() < 1){
47                        return;
48                }
49                
50                //actions which only apply to selections containing experiments
51                
52                if (getCurrentSelection().size() == 1) {
53                        //action which only apply to a single distinctly selected experiment
54                        manager.add(myRenameAction);
55                }
56                
57                
58                manager.add(myDeleteAction);        
59        }
60 
61        /**
62         * Adds actions to the toolbar which should then be enabled
63         * and disabled when the selection changes.
64         * @param toolbar the toolbar to add actions to
65         */
66        public void addNavigationActions(IToolBarManager toolbar) {
67                // don't add anything to the toolbar
68        }
69 
70        public void selectionChanged(SelectionChangedEvent event) {
71                updateNavigationButtons();                
72        }
73 
74        private void createActions() {
75                myRenameAction = new RenameAction();
76                myDeleteAction = new DeleteAction();
77        }
78 
79        /**
80         * enables or disables navigation buttons depending on the selection
81         * @param selection the current selection
82         */
83        private void updateNavigationButtons() {
84                // no toolbar items or context menu items that need to be updated
85        }
86 
87        /** 
88         * returns the current selection as a structured selection
89         * @return the current selection or null if no elements are contained
90         */
91        private IStructuredSelection getCurrentSelection() {
92                //check if selection has objects
93                if ( ! (myChildTree.getSelection() instanceof IStructuredSelection)) {
94                        return null;
95                }
96 
97                return (IStructuredSelection)myChildTree.getSelection();
98        }
99 
100        /**
101         * retrieves all currently selected Experiments
102         * @return a list of all currently selected experiments
103         */
104        private List<Experiment> getSelectedExperiments() {
105                List<Experiment> experiments = new LinkedList<Experiment>();
106 
107                //check if selection has objects
108                if ( ! (myChildTree.getSelection() instanceof IStructuredSelection)) {
109                        return experiments;
110                }
111 
112                IStructuredSelection selection = 
113                        (IStructuredSelection)myChildTree.getSelection();                        
114 
115                Iterator<?> it = selection.iterator();
116                while (it.hasNext()) {
117                        //add experiment to list, if we find one
118                        Object selectedObject = it.next();
119                        if (selectedObject instanceof ExperimentAndDAO) {
120                                experiments.add(((ExperimentAndDAO) selectedObject).getExperiment());
121                        }
122                }
123 
124                return experiments;
125        }
126        
127        private List<ExperimentAndDAO> getSelectedExperimentAndDAOs() {
128                List<ExperimentAndDAO> exAndDAOs = new LinkedList<ExperimentAndDAO>();
129 
130                //check if selection has objects
131                if ( ! (myChildTree.getSelection() instanceof IStructuredSelection)) {
132                        return exAndDAOs;
133                }
134 
135                IStructuredSelection selection = 
136                        (IStructuredSelection)myChildTree.getSelection();                        
137 
138                Iterator<?> it = selection.iterator();
139                while (it.hasNext()) {
140                        //add experiment to list, if we find one
141                        Object selectedObject = it.next();
142                        if (selectedObject instanceof ExperimentAndDAO) {
143                                exAndDAOs.add((ExperimentAndDAO) selectedObject);
144                        }
145                }
146 
147                return exAndDAOs;
148        }
149        
150        /**
151         * Action that deletes all selected Experiments and their contents.
152         * Note: Currently Experiments are stored as part of ExperimentAndDAO, so
153         * these will be deleted instead of just the experiment.
154         */
155        private class DeleteAction extends Action {
156                public DeleteAction() {
157                        super();
158                        setText("Delete");
159                        setToolTipText("Delete Experiment");
160                        setEnabled(true);
161                }
162                
163                @Override
164                public void run() {
165                        List<ExperimentAndDAO> exAndDAOs = getSelectedExperimentAndDAOs();
166                        
167                        //delete all selected exAndDAOs
168                        Iterator<ExperimentAndDAO> it = exAndDAOs.iterator();
169                        while (it.hasNext()) {
170                                ExperimentAndDAO toDel = it.next();
171                                IExperimentDAO dao = toDel.getDatasource().createExperimentDAO();
172                                dao.removeExperiment(toDel.getExperiment(), true);
173                                myChildTree.remove(toDel);
174                        }
175                }
176        }
177 
178        /**
179         * Action that pops up a dialog to rename an experiment.
180         * Only runs, if exacly one experiment and nothing else is selected. 
181         */
182        private class RenameAction extends Action {
183                public RenameAction() {
184                        super();
185                        setText("Rename");
186                        setToolTipText("Rename Experiment");
187                        setEnabled(true);
188                }
189 
190                @Override
191                public void run() {
192                        //check if only a single element has been selected
193                        if (getCurrentSelection().size() != 1) {
194                                return;
195                        }
196                        
197                        List<ExperimentAndDAO> expAndDAOs = getSelectedExperimentAndDAOs();
198                        if (expAndDAOs.isEmpty()) {
199                                return;
200                        }
201                        
202                        //get the first (and only) selected experiment
203                        Experiment experiment = expAndDAOs.get(0).getExperiment();
204                        
205                        //ask the user for a new name
206                        InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(),
207                            "Rename experiment", "Enter the new experiment name!", experiment.getExperimentName(), new NameValidator());
208                    if (dlg.open() == Window.OK) {
209                        experiment.setExperimentName(dlg.getValue());
210                        
211                        myChildTree.refresh();
212                    }
213                }
214                
215                private class NameValidator implements IInputValidator {
216                        
217                        public String isValid(String newText) {
218                                if ( newText == "" ) {
219                                        return "Please enter a name!";
220                                }
221                                
222                                return null;
223                        }
224                        
225                }
226        }
227}

[all classes][de.uka.ipd.sdq.sensorframework.visualisation.views]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov