diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java new file mode 100644 index 0000000..fdbd8e0 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/views/RecipeView.java | |||
@@ -0,0 +1,165 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.views; | ||
12 | |||
13 | import org.eclipse.core.resources.IFile; | ||
14 | import org.eclipse.jface.action.Action; | ||
15 | import org.eclipse.jface.action.IMenuListener; | ||
16 | import org.eclipse.jface.action.IMenuManager; | ||
17 | import org.eclipse.jface.action.IToolBarManager; | ||
18 | import org.eclipse.jface.action.MenuManager; | ||
19 | import org.eclipse.jface.action.Separator; | ||
20 | import org.eclipse.jface.viewers.DoubleClickEvent; | ||
21 | import org.eclipse.jface.viewers.IDoubleClickListener; | ||
22 | import org.eclipse.jface.viewers.ISelection; | ||
23 | import org.eclipse.jface.viewers.IStructuredSelection; | ||
24 | import org.eclipse.jface.viewers.ITableLabelProvider; | ||
25 | import org.eclipse.jface.viewers.LabelProvider; | ||
26 | import org.eclipse.jface.viewers.TableViewer; | ||
27 | import org.eclipse.jface.viewers.ViewerSorter; | ||
28 | import org.eclipse.swt.SWT; | ||
29 | import org.eclipse.swt.graphics.Image; | ||
30 | import org.eclipse.swt.widgets.Composite; | ||
31 | import org.eclipse.swt.widgets.Menu; | ||
32 | import org.eclipse.ui.IActionBars; | ||
33 | import org.eclipse.ui.ISharedImages; | ||
34 | import org.eclipse.ui.IWorkbenchActionConstants; | ||
35 | import org.eclipse.ui.PartInitException; | ||
36 | import org.eclipse.ui.PlatformUI; | ||
37 | import org.eclipse.ui.part.FileEditorInput; | ||
38 | import org.eclipse.ui.part.ViewPart; | ||
39 | |||
40 | import org.yocto.bc.ui.editors.bitbake.BitBakeFileEditor; | ||
41 | |||
42 | public class RecipeView extends ViewPart { | ||
43 | class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { | ||
44 | public Image getColumnImage(Object obj, int index) { | ||
45 | return getImage(obj); | ||
46 | } | ||
47 | |||
48 | public String getColumnText(Object obj, int index) { | ||
49 | |||
50 | if (obj instanceof IFile) { | ||
51 | return ((IFile) obj).getName(); | ||
52 | } | ||
53 | |||
54 | return getText(obj); | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public Image getImage(Object obj) { | ||
59 | return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE); | ||
60 | } | ||
61 | } | ||
62 | public static final String ID_VIEW = "org.yocto.bc.ui.views.RecipeView"; | ||
63 | private TableViewer viewer; | ||
64 | |||
65 | /* private Action action1; | ||
66 | private Action action2; | ||
67 | */ private Action doubleClickAction; | ||
68 | |||
69 | private void contributeToActionBars() { | ||
70 | IActionBars bars = getViewSite().getActionBars(); | ||
71 | fillLocalPullDown(bars.getMenuManager()); | ||
72 | fillLocalToolBar(bars.getToolBarManager()); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public void createPartControl(Composite parent) { | ||
77 | viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); | ||
78 | viewer.setContentProvider(new RecipeContentProvider()); | ||
79 | viewer.setLabelProvider(new ViewLabelProvider()); | ||
80 | viewer.setSorter(new ViewerSorter()); | ||
81 | viewer.setInput(getViewSite()); | ||
82 | makeActions(); | ||
83 | hookContextMenu(); | ||
84 | hookDoubleClickAction(); | ||
85 | contributeToActionBars(); | ||
86 | } | ||
87 | |||
88 | private void fillContextMenu(IMenuManager manager) { | ||
89 | /* manager.add(action1); | ||
90 | manager.add(action2); | ||
91 | */ // Other plug-ins can contribute there actions here | ||
92 | manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); | ||
93 | } | ||
94 | |||
95 | private void fillLocalPullDown(IMenuManager manager) { | ||
96 | /* manager.add(action1); | ||
97 | manager.add(new Separator()); | ||
98 | manager.add(action2); | ||
99 | */ } | ||
100 | |||
101 | private void fillLocalToolBar(IToolBarManager manager) { | ||
102 | /* manager.add(action1); | ||
103 | manager.add(action2); | ||
104 | */ } | ||
105 | |||
106 | private void hookContextMenu() { | ||
107 | MenuManager menuMgr = new MenuManager("#PopupMenu"); | ||
108 | menuMgr.setRemoveAllWhenShown(true); | ||
109 | menuMgr.addMenuListener(new IMenuListener() { | ||
110 | public void menuAboutToShow(IMenuManager manager) { | ||
111 | RecipeView.this.fillContextMenu(manager); | ||
112 | } | ||
113 | }); | ||
114 | Menu menu = menuMgr.createContextMenu(viewer.getControl()); | ||
115 | viewer.getControl().setMenu(menu); | ||
116 | getSite().registerContextMenu(menuMgr, viewer); | ||
117 | } | ||
118 | |||
119 | private void hookDoubleClickAction() { | ||
120 | viewer.addDoubleClickListener(new IDoubleClickListener() { | ||
121 | public void doubleClick(DoubleClickEvent event) { | ||
122 | doubleClickAction.run(); | ||
123 | } | ||
124 | }); | ||
125 | } | ||
126 | |||
127 | private void makeActions() { | ||
128 | /* action1 = new Action() { | ||
129 | public void run() { | ||
130 | } | ||
131 | }; | ||
132 | action1.setText("Action 1"); | ||
133 | action1.setToolTipText("Action 1 tooltip"); | ||
134 | action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); | ||
135 | |||
136 | action2 = new Action() { | ||
137 | public void run() { | ||
138 | } | ||
139 | }; | ||
140 | action2.setText("Action 2"); | ||
141 | action2.setToolTipText("Action 2 tooltip"); | ||
142 | action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); | ||
143 | */ doubleClickAction = new Action() { | ||
144 | @Override | ||
145 | public void run() { | ||
146 | ISelection selection = viewer.getSelection(); | ||
147 | Object obj = ((IStructuredSelection) selection).getFirstElement(); | ||
148 | |||
149 | if (obj instanceof IFile) { | ||
150 | try { | ||
151 | RecipeView.this.getViewSite().getPage().openEditor(new FileEditorInput((IFile) obj), BitBakeFileEditor.EDITOR_ID); | ||
152 | } catch (PartInitException e) { | ||
153 | // TODO Auto-generated catch block | ||
154 | e.printStackTrace(); | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | }; | ||
159 | } | ||
160 | |||
161 | @Override | ||
162 | public void setFocus() { | ||
163 | viewer.getControl().setFocus(); | ||
164 | } | ||
165 | } \ No newline at end of file | ||