OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 import org.eclipse.ui.part.ResourceTransfer; | 70 import org.eclipse.ui.part.ResourceTransfer; |
71 import org.eclipse.ui.part.ViewPart; | 71 import org.eclipse.ui.part.ViewPart; |
72 import org.eclipse.ui.views.navigator.LocalSelectionTransfer; | 72 import org.eclipse.ui.views.navigator.LocalSelectionTransfer; |
73 | 73 |
74 import java.util.ArrayList; | 74 import java.util.ArrayList; |
75 import java.util.Iterator; | 75 import java.util.Iterator; |
76 import java.util.List; | 76 import java.util.List; |
77 | 77 |
78 /** | 78 /** |
79 * File-oriented view for navigating Dart projects. | 79 * File-oriented view for navigating Dart projects. |
80 * <p> | |
81 * This view will replace the current "Libraries" view once a few tasks are comp
leted: | |
82 * <p> | |
83 * TODO Remove the deprecated CreateFileAction and CreateFolderActions with new
Dart Editor specific | |
84 * versions | |
85 * <p> | |
86 * TODO modify the builder to ensure that the correct libraries are built when t
he user makes | |
87 * changes to Dart code | |
88 * <p> | |
89 * TODO re-visit the DeltaProcessor and ensure that all user actions result in a
correct update of | |
90 * the model in the viewer | |
91 */ | 80 */ |
92 @SuppressWarnings("deprecation") | 81 @SuppressWarnings("deprecation") |
93 public class FilesView extends ViewPart implements ISetSelectionTarget { | 82 public class FilesView extends ViewPart implements ISetSelectionTarget { |
94 | 83 |
95 private class FontPropertyChangeListener implements IPropertyChangeListener { | 84 private class FontPropertyChangeListener implements IPropertyChangeListener { |
96 @Override | 85 @Override |
97 public void propertyChange(PropertyChangeEvent event) { | 86 public void propertyChange(PropertyChangeEvent event) { |
98 if (treeViewer != null) { | 87 if (treeViewer != null) { |
99 if (DartBasePreferencePage.BASE_FONT_KEY.equals(event.getProperty())) { | 88 if (DartBasePreferencePage.BASE_FONT_KEY.equals(event.getProperty())) { |
100 updateTreeFont(); | 89 updateTreeFont(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 private static final String TAG_PATH = "path"; //$NON-NLS-1$ | 140 private static final String TAG_PATH = "path"; //$NON-NLS-1$ |
152 private static final String TAG_SELECTION = "selection"; //$NON-NLS-1$ | 141 private static final String TAG_SELECTION = "selection"; //$NON-NLS-1$ |
153 | 142 |
154 public FilesView() { | 143 public FilesView() { |
155 } | 144 } |
156 | 145 |
157 @Override | 146 @Override |
158 public void createPartControl(Composite parent) { | 147 public void createPartControl(Composite parent) { |
159 treeViewer = new TreeViewer(parent); | 148 treeViewer = new TreeViewer(parent); |
160 treeViewer.setContentProvider(new ResourceContentProvider()); | 149 treeViewer.setContentProvider(new ResourceContentProvider()); |
161 //TODO (pquitslund): replace with WorkbenchLabelProvider.getDecoratingWorkbe
nchLabelProvider() | 150 // TODO(pquitslund): replace with WorkbenchLabelProvider.getDecoratingWorkbe
nchLabelProvider() |
162 // when we have the linked resource story straightened out | 151 //treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchL
abelProvider()); |
163 // treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchL
abelProvider()); | |
164 treeViewer.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelPr
ovider(), | 152 treeViewer.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelPr
ovider(), |
165 new ProblemsLabelDecorator())); | 153 new ProblemsLabelDecorator())); |
166 treeViewer.setComparator(new FilesViewerComparator()); | 154 treeViewer.setComparator(new FilesViewerComparator()); |
167 treeViewer.addDoubleClickListener(new IDoubleClickListener() { | 155 treeViewer.addDoubleClickListener(new IDoubleClickListener() { |
168 @Override | 156 @Override |
169 public void doubleClick(DoubleClickEvent event) { | 157 public void doubleClick(DoubleClickEvent event) { |
170 handleDoubleClick(event); | 158 handleDoubleClick(event); |
171 } | 159 } |
172 }); | 160 }); |
173 treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); | 161 treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 Object elements[] = ((IStructuredSelection) treeViewer.getSelection()).toArr
ay(); | 243 Object elements[] = ((IStructuredSelection) treeViewer.getSelection()).toArr
ay(); |
256 if (elements.length > 0) { | 244 if (elements.length > 0) { |
257 IMemento selectionMem = memento.createChild(TAG_SELECTION); | 245 IMemento selectionMem = memento.createChild(TAG_SELECTION); |
258 for (Object element : elements) { | 246 for (Object element : elements) { |
259 if (element instanceof IResource) { | 247 if (element instanceof IResource) { |
260 IMemento elementMem = selectionMem.createChild(TAG_ELEMENT); | 248 IMemento elementMem = selectionMem.createChild(TAG_ELEMENT); |
261 elementMem.putString(TAG_PATH, ((IResource) element).getFullPath().toS
tring()); | 249 elementMem.putString(TAG_PATH, ((IResource) element).getFullPath().toS
tring()); |
262 } | 250 } |
263 } | 251 } |
264 } | 252 } |
265 | |
266 } | 253 } |
267 | 254 |
268 @Override | 255 @Override |
269 public void selectReveal(ISelection selection) { | 256 public void selectReveal(ISelection selection) { |
270 treeViewer.setSelection(selection, true); | 257 treeViewer.setSelection(selection, true); |
271 } | 258 } |
272 | 259 |
273 @Override | 260 @Override |
274 public void setFocus() { | 261 public void setFocus() { |
275 treeViewer.getTree().setFocus(); | 262 treeViewer.getTree().setFocus(); |
276 } | 263 } |
277 | 264 |
278 protected void createContextMenu() { | 265 protected void createContextMenu() { |
279 MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ | 266 MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
280 menuMgr.setRemoveAllWhenShown(true); | 267 menuMgr.setRemoveAllWhenShown(true); |
281 menuMgr.addMenuListener(new IMenuListener() { | 268 menuMgr.addMenuListener(new IMenuListener() { |
282 @Override | 269 @Override |
283 public void menuAboutToShow(IMenuManager manager) { | 270 public void menuAboutToShow(IMenuManager manager) { |
284 fillContextMenu(manager); | 271 fillContextMenu(manager); |
285 } | 272 } |
286 }); | 273 }); |
287 Menu menu = menuMgr.createContextMenu(treeViewer.getTree()); | 274 Menu menu = menuMgr.createContextMenu(treeViewer.getTree()); |
288 treeViewer.getTree().setMenu(menu); | 275 treeViewer.getTree().setMenu(menu); |
289 getSite().registerContextMenu(menuMgr, treeViewer); | 276 getSite().registerContextMenu(menuMgr, treeViewer); |
290 } | 277 } |
291 | 278 |
292 protected void fillContextMenu(IMenuManager manager) { | 279 protected void fillContextMenu(IMenuManager manager) { |
| 280 IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelect
ion(); |
293 | 281 |
294 // New File/ New Folder | 282 // New File/ New Folder |
295 | 283 |
296 manager.add(createFileAction); | 284 if (allElementsAreResources(selection)) { |
297 manager.add(createFolderAction); | 285 manager.add(createFileAction); |
| 286 manager.add(createFolderAction); |
| 287 } |
298 | 288 |
299 // OPEN GROUP | 289 // OPEN GROUP |
300 | 290 |
301 manager.add(new Separator()); | 291 if (manager.getItems().length > 0) { |
| 292 manager.add(new Separator()); |
| 293 } |
| 294 |
302 manager.add(OpenFolderHandler.createCommandAction(getSite().getWorkbenchWind
ow())); | 295 manager.add(OpenFolderHandler.createCommandAction(getSite().getWorkbenchWind
ow())); |
303 | 296 |
304 IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelect
ion(); | |
305 | |
306 // REFACTOR GROUP | 297 // REFACTOR GROUP |
307 | 298 |
308 // Refactor iff all elements are IResources | 299 // Refactor iff all elements are IResources |
309 | 300 |
310 if (!selection.isEmpty() && allElementsAreResources(selection)) { | 301 if (!selection.isEmpty() && allElementsAreResources(selection)) { |
311 manager.add(new Separator()); | 302 manager.add(new Separator()); |
312 if (selection.size() == 1) { | 303 if (selection.size() == 1) { |
313 manager.add(renameAction); | 304 manager.add(renameAction); |
314 manager.add(moveAction); | 305 manager.add(moveAction); |
315 } | 306 } |
316 manager.add(deleteAction); | 307 manager.add(deleteAction); |
317 } | 308 } |
318 | 309 |
319 // Remove, iff non-empty selection, all elements are IResources | 310 // Remove, iff non-empty selection, all elements are IResources |
320 | 311 |
321 if (!selection.isEmpty() && allElementsAreResources(selection)) { | 312 if (!selection.isEmpty() && allElementsAreResources(selection)) { |
322 | 313 |
323 // Copy File Path iff single element and is an IResource | 314 // Copy File Path iff single element and is an IResource |
324 | 315 |
325 if (selection.size() == 1) { | 316 if (selection.size() == 1) { |
326 manager.add(new Separator()); | 317 manager.add(new Separator()); |
327 manager.add(copyFilePathAction); | 318 manager.add(copyFilePathAction); |
328 } | 319 } |
329 | 320 |
330 manager.add(new Separator()); | 321 manager.add(new Separator()); |
331 if (allElementsAreProjects(selection)) { | 322 if (allElementsAreProjects(selection)) { |
332 manager.add(hideContainerAction); | 323 manager.add(hideContainerAction); |
333 } | 324 } |
334 } | 325 } |
335 | |
336 } | 326 } |
337 | 327 |
338 protected void fillInToolbar(IToolBarManager toolbar) { | 328 protected void fillInToolbar(IToolBarManager toolbar) { |
339 | |
340 // Link with Editor | 329 // Link with Editor |
341 | 330 |
342 linkWithEditorAction = new LinkWithEditorAction(getViewSite().getPage(), tre
eViewer); | 331 linkWithEditorAction = new LinkWithEditorAction(getViewSite().getPage(), tre
eViewer); |
343 | 332 |
344 if (memento != null && memento.getBoolean(LINK_WITH_EDITOR_ID) != null) { | 333 if (memento != null && memento.getBoolean(LINK_WITH_EDITOR_ID) != null) { |
345 linkWithEditorAction.setLinkWithEditor(memento.getBoolean(LINK_WITH_EDITOR
_ID).booleanValue()); | 334 linkWithEditorAction.setLinkWithEditor(memento.getBoolean(LINK_WITH_EDITOR
_ID).booleanValue()); |
346 } else { | 335 } else { |
347 linkWithEditorAction.setLinkWithEditor(true); | 336 linkWithEditorAction.setLinkWithEditor(true); |
348 } | 337 } |
349 | 338 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 Transfer[] transfers = new Transfer[] { | 420 Transfer[] transfers = new Transfer[] { |
432 LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), | 421 LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(), |
433 FileTransfer.getInstance(), PluginTransfer.getInstance()}; | 422 FileTransfer.getInstance(), PluginTransfer.getInstance()}; |
434 treeViewer.addDragSupport(ops, transfers, new FilesViewDragAdapter(treeViewe
r)); | 423 treeViewer.addDragSupport(ops, transfers, new FilesViewDragAdapter(treeViewe
r)); |
435 FilesViewDropAdapter adapter = new FilesViewDropAdapter(treeViewer); | 424 FilesViewDropAdapter adapter = new FilesViewDropAdapter(treeViewer); |
436 adapter.setFeedbackEnabled(true); | 425 adapter.setFeedbackEnabled(true); |
437 treeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, adapter); | 426 treeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, adapter); |
438 } | 427 } |
439 | 428 |
440 } | 429 } |
OLD | NEW |