|
1 /* |
|
2 * Copyright (c) 2009 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 the License "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 package com.nokia.carbide.cpp.pi.util; |
|
19 |
|
20 import org.eclipse.cdt.core.dom.ast.IASTFileLocation; |
|
21 import org.eclipse.core.resources.IFile; |
|
22 import org.eclipse.core.resources.ResourcesPlugin; |
|
23 import org.eclipse.core.runtime.IPath; |
|
24 import org.eclipse.core.runtime.Path; |
|
25 import org.eclipse.jface.dialogs.TitleAreaDialog; |
|
26 import org.eclipse.swt.SWT; |
|
27 import org.eclipse.swt.events.MouseEvent; |
|
28 import org.eclipse.swt.events.MouseListener; |
|
29 import org.eclipse.swt.events.SelectionEvent; |
|
30 import org.eclipse.swt.events.SelectionListener; |
|
31 import org.eclipse.swt.layout.GridData; |
|
32 import org.eclipse.swt.layout.GridLayout; |
|
33 import org.eclipse.swt.widgets.Composite; |
|
34 import org.eclipse.swt.widgets.Control; |
|
35 import org.eclipse.swt.widgets.Shell; |
|
36 import org.eclipse.swt.widgets.Table; |
|
37 import org.eclipse.swt.widgets.TableItem; |
|
38 import org.eclipse.ui.ISharedImages; |
|
39 import org.eclipse.ui.PlatformUI; |
|
40 |
|
41 import com.nokia.carbide.cpp.ui.CarbideUIPlugin; |
|
42 import com.nokia.carbide.cpp.ui.ICarbideSharedImages; |
|
43 |
|
44 public class SourceLookupFileChooserDialog extends TitleAreaDialog { |
|
45 |
|
46 IASTFileLocation[] locations = null; |
|
47 IASTFileLocation selectedLocation = null; |
|
48 |
|
49 // control |
|
50 private Composite composite = null; |
|
51 private Table table = null; |
|
52 |
|
53 protected SourceLookupFileChooserDialog(Shell arg0, IASTFileLocation[] locs) { |
|
54 super(arg0); |
|
55 locations = locs; |
|
56 } |
|
57 |
|
58 public Control createDialogArea(Composite parent) { |
|
59 // use image from support plugin |
|
60 setDefaultImage(CarbideUIPlugin.getSharedImages().getImageDescriptor(ICarbideSharedImages.IMG_CARBIDE_C_ICON_16_16).createImage()); |
|
61 getShell().setText(Messages.getString("SourceLookupFileChooserDialog.text")); //$NON-NLS-1$ |
|
62 setTitle(Messages.getString("SourceLookupFileChooserDialog.title")); //$NON-NLS-1$ |
|
63 setMessage(Messages.getString("SourceLookupFileChooserDialog.message")); //$NON-NLS-1$ |
|
64 |
|
65 GridLayout gridLayout = new GridLayout(); |
|
66 gridLayout.numColumns = 1; |
|
67 composite = new Composite(parent, SWT.NONE); |
|
68 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
69 composite.setLayout(gridLayout); |
|
70 |
|
71 table = new Table(composite, SWT.SINGLE); |
|
72 table.addSelectionListener(new SelectionListener() { |
|
73 |
|
74 public void widgetDefaultSelected(SelectionEvent arg0) { |
|
75 } |
|
76 |
|
77 public void widgetSelected(SelectionEvent arg0) { |
|
78 selectedLocation = (IASTFileLocation)table.getSelection()[0].getData(); |
|
79 } |
|
80 |
|
81 }); |
|
82 table.addMouseListener(new MouseListener(){ |
|
83 // allow double click instead of OK |
|
84 public void mouseDoubleClick(MouseEvent arg0) { |
|
85 selectedLocation = (IASTFileLocation)table.getSelection()[0].getData(); |
|
86 okPressed(); |
|
87 } |
|
88 |
|
89 public void mouseDown(MouseEvent arg0) { |
|
90 } |
|
91 |
|
92 public void mouseUp(MouseEvent arg0) { |
|
93 } |
|
94 |
|
95 }); |
|
96 |
|
97 for(IASTFileLocation location : locations) { |
|
98 |
|
99 IPath path = new Path(location.getFileName()); |
|
100 IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); |
|
101 |
|
102 String fileName = null; |
|
103 String containerName = null; |
|
104 |
|
105 if (file != null) { |
|
106 fileName = file.getName(); |
|
107 containerName = "project " + file.getProject().getName(); //$NON-NLS-1$ |
|
108 } else { |
|
109 fileName = path.segment(path.segmentCount() - 1); |
|
110 containerName = path.uptoSegment(path.segmentCount() - 2).toString(); //$NON-NLS-1$ |
|
111 } |
|
112 |
|
113 TableItem item = new TableItem(table, SWT.NONE); |
|
114 item.setText(fileName + " - " + containerName); //$NON-NLS-1$ |
|
115 item.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE)); |
|
116 item.setData(location); |
|
117 } |
|
118 |
|
119 return composite; |
|
120 } |
|
121 |
|
122 protected void okPressed() { |
|
123 if (selectedLocation != null) { |
|
124 super.okPressed(); |
|
125 } |
|
126 } |
|
127 |
|
128 protected void cancelPressed() { |
|
129 selectedLocation = null; |
|
130 super.cancelPressed(); |
|
131 } |
|
132 |
|
133 public IASTFileLocation getLocation() { |
|
134 return selectedLocation; |
|
135 } |
|
136 } |