|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.s60tools.appdep.ui.actions; |
|
20 |
|
21 import java.util.Map; |
|
22 |
|
23 import org.eclipse.core.runtime.IStatus; |
|
24 import org.eclipse.core.runtime.jobs.IJobChangeEvent; |
|
25 import org.eclipse.core.runtime.jobs.IJobChangeListener; |
|
26 import org.eclipse.core.runtime.jobs.Job; |
|
27 import org.eclipse.swt.SWT; |
|
28 import org.eclipse.swt.widgets.Display; |
|
29 import org.eclipse.swt.widgets.Shell; |
|
30 |
|
31 import com.nokia.s60tools.appdep.common.ProductInfoRegistry; |
|
32 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
33 import com.nokia.s60tools.appdep.core.data.ComponentNode; |
|
34 import com.nokia.s60tools.appdep.core.data.ComponentParentNode; |
|
35 import com.nokia.s60tools.appdep.locatecomponent.LocateComponentJob; |
|
36 import com.nokia.s60tools.appdep.locatecomponent.SeekParentNodesService; |
|
37 import com.nokia.s60tools.appdep.resources.ImageKeys; |
|
38 import com.nokia.s60tools.appdep.resources.ImageResourceManager; |
|
39 import com.nokia.s60tools.appdep.resources.Messages; |
|
40 import com.nokia.s60tools.appdep.ui.dialogs.AppDepMessageBox; |
|
41 import com.nokia.s60tools.appdep.ui.dialogs.LocateComponentDialog; |
|
42 import com.nokia.s60tools.appdep.ui.views.main.MainView; |
|
43 import com.nokia.s60tools.appdep.ui.views.main.MainViewDataPopulator; |
|
44 import com.nokia.s60tools.appdep.ui.views.main.MainViewPopulateProgressListener; |
|
45 import com.nokia.s60tools.appdep.util.AppDepConsole; |
|
46 |
|
47 /** |
|
48 * Locates concrete component for the selected generic component from component tree. |
|
49 */ |
|
50 public class LocateComponentMainViewAction extends AbstractMainViewAction implements IJobChangeListener{ |
|
51 |
|
52 /** |
|
53 * Name of the generic component. |
|
54 */ |
|
55 private String componentName; |
|
56 /** |
|
57 * Selected node (=generic component) from component tree. |
|
58 */ |
|
59 private ComponentNode startNode; |
|
60 |
|
61 /** |
|
62 * Constructor. |
|
63 * @param view Reference to the view. |
|
64 */ |
|
65 public LocateComponentMainViewAction(MainView view){ |
|
66 super(view); |
|
67 |
|
68 setText(Messages.getString("LocateComponentMainViewAction.Locate_Action_Text")); //$NON-NLS-1$ |
|
69 setToolTipText(Messages.getString("LocateSourceMainViewAction.Locate_Action_Tooltip")); //$NON-NLS-1$ |
|
70 |
|
71 |
|
72 /******************************************************************************* |
|
73 * This piece of the graphic is taken/modified from a graphic that is made |
|
74 * available under the terms of the Eclipse Public License v1.0. |
|
75 * |
|
76 * See 'com.nokia.s60tools.appdep.resources.ImageResourceManager' |
|
77 * for detailed information about the original graphic. |
|
78 * |
|
79 *******************************************************************************/ |
|
80 //Adding image descriptor if an icon is created for this action |
|
81 setImageDescriptor(ImageResourceManager. |
|
82 getImageDescriptor(ImageKeys.BIN_OBJ_BIND)); |
|
83 |
|
84 } |
|
85 |
|
86 /* (non-Javadoc) |
|
87 * @see org.eclipse.jface.action.IAction#run() |
|
88 */ |
|
89 public void run() { |
|
90 Object obj = view.getComponentTreeSelectedElement(); |
|
91 |
|
92 if(obj == null){ |
|
93 // We might get null-selections when |
|
94 // tree is expanded/collapsed. |
|
95 return; |
|
96 } |
|
97 |
|
98 startNode = (ComponentNode) obj; |
|
99 componentName = startNode.getName(); |
|
100 AppDepSettings settings = AppDepSettings.getActiveSettings(); |
|
101 if(settings.getCurrentlyAnalyzedComponentName() != null){ |
|
102 AppDepConsole.getInstance().println(Messages.getString("LocateComponentMainViewAction.Query_Start_Console_Msg") //$NON-NLS-1$ |
|
103 + componentName + "'..."); //$NON-NLS-1$ |
|
104 |
|
105 String jobName = ProductInfoRegistry.getProductName() |
|
106 + " " + Messages.getString("LocateComponentMainViewAction.LocateJobName_Str") + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
107 + componentName; |
|
108 |
|
109 //searching components in job. |
|
110 LocateComponentJob job = new LocateComponentJob( |
|
111 jobName, |
|
112 componentName ); |
|
113 job.addJobChangeListener(this); |
|
114 job.setPriority(Job.DECORATE); |
|
115 job.schedule(); |
|
116 |
|
117 } |
|
118 // Remember to always call AbstractMainViewAction |
|
119 // base class implementation |
|
120 super.run(); |
|
121 } |
|
122 |
|
123 /* (non-Javadoc) |
|
124 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#aboutToRun(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
125 */ |
|
126 public void aboutToRun(IJobChangeEvent event) { |
|
127 //Not needed |
|
128 } |
|
129 |
|
130 /* (non-Javadoc) |
|
131 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#awake(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
132 */ |
|
133 public void awake(IJobChangeEvent event) { |
|
134 //Not needed |
|
135 } |
|
136 |
|
137 /* (non-Javadoc) |
|
138 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#done(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
139 */ |
|
140 public void done(IJobChangeEvent event) { |
|
141 |
|
142 IStatus status = event.getResult(); |
|
143 LocateComponentJob job = (LocateComponentJob) event.getJob(); |
|
144 final String [] components = job.getConcreteComponent(); |
|
145 |
|
146 //Showing dialog only if not cancelled |
|
147 if(status.getSeverity() == IStatus.OK){ |
|
148 |
|
149 // Runnable implementing the actual printing to console |
|
150 Runnable completedRunnable = new Runnable(){ |
|
151 public void run(){ |
|
152 openDialog(components); |
|
153 } |
|
154 }; |
|
155 |
|
156 Display.getDefault().asyncExec(completedRunnable); |
|
157 } |
|
158 } |
|
159 |
|
160 /** |
|
161 * Opens the dialog with search results |
|
162 * @param components Component alternatives to be shown in dialog. |
|
163 */ |
|
164 private void openDialog(String [] components){ |
|
165 Shell sh = view.getViewSite().getShell(); |
|
166 |
|
167 // Did we found any concrete component candidates for generic component name? |
|
168 if(components.length == 0){ |
|
169 String infoMsg = Messages.getString("LocateComponentMainViewAction.NoConcreteComponentsFound_InfoMsg_Part1") + componentName + Messages.getString("LocateComponentMainViewAction.NoConcreteComponentsFound_InfoMsg_Part2"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
170 new AppDepMessageBox(sh, infoMsg, SWT.ICON_INFORMATION).open(); |
|
171 return; |
|
172 } |
|
173 |
|
174 LocateComponentDialog dialog = new LocateComponentDialog(sh, components, componentName ); |
|
175 int ok = dialog.open(); |
|
176 |
|
177 if(ok == LocateComponentDialog.OK){ |
|
178 int selection = dialog.getSelectionIndex(); |
|
179 if(selection != -1){ |
|
180 String newComponentName = components[selection]; |
|
181 |
|
182 //Get all already found Parent nodes to prevent them to occur more than once. |
|
183 ComponentParentNode parent = startNode.getParent(); |
|
184 ComponentParentNode root = parent.getRootNode(); |
|
185 //Get components all ready added, to prevent duplicates |
|
186 Map<String, ComponentParentNode> parentNodes = SeekParentNodesService.findParentNodes(root); |
|
187 MainViewPopulateProgressListener listener = new MainViewPopulateProgressListener(view); |
|
188 //populate tree from parent node of selected component |
|
189 MainViewDataPopulator.populatePartOfView(parent, newComponentName, listener, parentNodes, startNode); |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 /* (non-Javadoc) |
|
195 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#running(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
196 */ |
|
197 public void running(IJobChangeEvent event) { |
|
198 // Not needed |
|
199 } |
|
200 |
|
201 /* (non-Javadoc) |
|
202 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#scheduled(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
203 */ |
|
204 public void scheduled(IJobChangeEvent event) { |
|
205 //Not needed |
|
206 } |
|
207 |
|
208 /* (non-Javadoc) |
|
209 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#sleeping(org.eclipse.core.runtime.jobs.IJobChangeEvent) |
|
210 */ |
|
211 public void sleeping(IJobChangeEvent event) { |
|
212 // Not needed |
|
213 } |
|
214 |
|
215 } |