Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2007 Dakshinamurthy Karra and others. |
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 |
* Dakshinamurthy Karra (Jalian Systems) - Templates View - https://bugs.eclipse.org/bugs/show_bug.cgi?id=69581 |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.ui.texteditor.templates; |
13 |
|
14 |
import java.io.IOException; |
15 |
import java.util.ArrayList; |
16 |
import java.util.Arrays; |
17 |
import java.util.Iterator; |
18 |
import java.util.List; |
19 |
|
20 |
import org.eclipse.jface.action.Action; |
21 |
import org.eclipse.jface.action.IAction; |
22 |
import org.eclipse.jface.action.IMenuListener; |
23 |
import org.eclipse.jface.action.IMenuManager; |
24 |
import org.eclipse.jface.action.IToolBarManager; |
25 |
import org.eclipse.jface.action.MenuManager; |
26 |
import org.eclipse.jface.action.Separator; |
27 |
import org.eclipse.jface.dialogs.MessageDialog; |
28 |
import org.eclipse.jface.layout.TreeColumnLayout; |
29 |
import org.eclipse.jface.preference.IPreferenceStore; |
30 |
import org.eclipse.jface.text.BadLocationException; |
31 |
import org.eclipse.jface.text.Document; |
32 |
import org.eclipse.jface.text.IDocument; |
33 |
import org.eclipse.jface.text.IRegion; |
34 |
import org.eclipse.jface.text.ITextViewerExtension5; |
35 |
import org.eclipse.jface.text.source.ISourceViewer; |
36 |
import org.eclipse.jface.text.source.SourceViewer; |
37 |
import org.eclipse.jface.text.source.SourceViewerConfiguration; |
38 |
import org.eclipse.jface.text.templates.ContextTypeRegistry; |
39 |
import org.eclipse.jface.text.templates.Template; |
40 |
import org.eclipse.jface.text.templates.TemplateContextType; |
41 |
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData; |
42 |
import org.eclipse.jface.text.templates.persistence.TemplateStore; |
43 |
import org.eclipse.jface.util.IPropertyChangeListener; |
44 |
import org.eclipse.jface.util.PropertyChangeEvent; |
45 |
import org.eclipse.jface.viewers.AbstractTreeViewer; |
46 |
import org.eclipse.jface.viewers.ColumnPixelData; |
47 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
48 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
49 |
import org.eclipse.jface.viewers.IPostSelectionProvider; |
50 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
51 |
import org.eclipse.jface.viewers.ISelectionProvider; |
52 |
import org.eclipse.jface.viewers.IStructuredSelection; |
53 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
54 |
import org.eclipse.jface.viewers.ITreeContentProvider; |
55 |
import org.eclipse.jface.viewers.LabelProvider; |
56 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
57 |
import org.eclipse.jface.viewers.StructuredSelection; |
58 |
import org.eclipse.jface.viewers.TreeViewer; |
59 |
import org.eclipse.jface.viewers.Viewer; |
60 |
import org.eclipse.jface.viewers.ViewerComparator; |
61 |
import org.eclipse.jface.window.Window; |
62 |
import org.eclipse.swt.SWT; |
63 |
import org.eclipse.swt.custom.CLabel; |
64 |
import org.eclipse.swt.custom.SashForm; |
65 |
import org.eclipse.swt.custom.StyledText; |
66 |
import org.eclipse.swt.custom.ViewForm; |
67 |
import org.eclipse.swt.dnd.Clipboard; |
68 |
import org.eclipse.swt.dnd.DND; |
69 |
import org.eclipse.swt.dnd.DragSourceAdapter; |
70 |
import org.eclipse.swt.dnd.DragSourceEvent; |
71 |
import org.eclipse.swt.dnd.DropTargetAdapter; |
72 |
import org.eclipse.swt.dnd.DropTargetEvent; |
73 |
import org.eclipse.swt.dnd.TextTransfer; |
74 |
import org.eclipse.swt.dnd.Transfer; |
75 |
import org.eclipse.swt.events.ControlEvent; |
76 |
import org.eclipse.swt.events.ControlListener; |
77 |
import org.eclipse.swt.graphics.Image; |
78 |
import org.eclipse.swt.graphics.Point; |
79 |
import org.eclipse.swt.layout.GridData; |
80 |
import org.eclipse.swt.widgets.Composite; |
81 |
import org.eclipse.swt.widgets.Control; |
82 |
import org.eclipse.swt.widgets.Event; |
83 |
import org.eclipse.swt.widgets.Menu; |
84 |
import org.eclipse.swt.widgets.Shell; |
85 |
import org.eclipse.swt.widgets.Tree; |
86 |
import org.eclipse.swt.widgets.TreeColumn; |
87 |
import org.eclipse.swt.widgets.TreeItem; |
88 |
import org.eclipse.ui.IActionBars; |
89 |
import org.eclipse.ui.IWorkbenchActionConstants; |
90 |
import org.eclipse.ui.actions.ActionFactory; |
91 |
import org.eclipse.ui.dialogs.PreferencesUtil; |
92 |
import org.eclipse.ui.dnd.IDragAndDropService; |
93 |
import org.eclipse.ui.internal.texteditor.NLSUtility; |
94 |
import org.eclipse.ui.internal.texteditor.PixelConverter; |
95 |
import org.eclipse.ui.internal.texteditor.TextEditorPlugin; |
96 |
import org.eclipse.ui.internal.texteditor.templates.TemplateTransfer; |
97 |
import org.eclipse.ui.internal.texteditor.templates.TemplatesPageImages; |
98 |
import org.eclipse.ui.part.Page; |
99 |
import org.eclipse.ui.texteditor.AbstractTextEditor; |
100 |
import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
101 |
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; |
102 |
import org.eclipse.ui.texteditor.templates.TemplatePreferencePage.EditTemplateDialog; |
103 |
|
104 |
import com.ibm.icu.text.Collator; |
105 |
|
106 |
/** |
107 |
* An abstract base class for template pages. |
108 |
* <p> |
109 |
* Clients who are defining an editor may elect to provide a corresponding |
110 |
* templates page. This templates page will be presented to the user via the |
111 |
* Templates View (the user decides whether their workbench window contains this |
112 |
* view) whenever that editor is active. This class should be subclassed by |
113 |
* clients. |
114 |
* </p> |
115 |
* <p> |
116 |
* Internally, a TemplatesPage uses the template store to display different |
117 |
* categories. A link to editor mode on the templates page allows to filtering |
118 |
* of the categories to only that are supported in this context. |
119 |
* </p> |
120 |
* |
121 |
* @since 3.4 |
122 |
*/ |
123 |
public abstract class TemplatesPage extends Page implements ITemplatesPage { |
124 |
|
125 |
/** |
126 |
* Sashform size |
127 |
*/ |
128 |
private static final String SASH_SIZE_PREF_ID = TextEditorPlugin.PLUGIN_ID |
129 |
+ ".templates.templatesPage.sashSize"; //$NON-NLS-1$ |
130 |
/** |
131 |
* Tree columns widths |
132 |
*/ |
133 |
private static final String COLUMN_NAME_WIDTH_PREF_ID = TextEditorPlugin.PLUGIN_ID |
134 |
+ ".templates.templatesPage.nameWidth"; //$NON-NLS-1$ |
135 |
private static final String COLUMN_DESCRIPTION_WIDTH_PREF_ID = TextEditorPlugin.PLUGIN_ID |
136 |
+ ".templates.templatesPage.descriptionWidth"; //$NON-NLS-1$ |
137 |
/** |
138 |
* Link to editor action setting |
139 |
*/ |
140 |
private static final String LINK_ACTION_PREF_ID = TextEditorPlugin.PLUGIN_ID |
141 |
+ ".templates.templatesPage.linkAction"; //$NON-NLS-1$ |
142 |
|
143 |
/** |
144 |
* Context expand/collapse setting prefix |
145 |
*/ |
146 |
private static final String CONTEXT_COLLAPSE_PREF_ID = TextEditorPlugin.PLUGIN_ID |
147 |
+ "templates.templatesPage.context.expand."; //$NON-NLS-1$ |
148 |
|
149 |
/** |
150 |
* The ID for the popup menu for this templates page |
151 |
*/ |
152 |
private static final String POPUP_MENU_ID = "org.eclipse.ui.texteditor.templates.PopupMenu"; //$NON-NLS-1$ |
153 |
|
154 |
/** |
155 |
* Default image for a template |
156 |
*/ |
157 |
private static final Image DEFAULT_TEMPLATE_IMAGE = TemplatesPageImages |
158 |
.getImage(TemplatesPageImages.IMG_OBJ_TEMPLATE); |
159 |
/** |
160 |
* Image for the context |
161 |
*/ |
162 |
private static final Image CONTEXT_IMAGE = TemplatesPageImages |
163 |
.getImage(TemplatesPageImages.IMG_OBJ_CONTEXT); |
164 |
|
165 |
/** |
166 |
* A post selection changed listener for the editor. Depending on the caret |
167 |
* position updates the templates |
168 |
*/ |
169 |
private final class SelectionChangedListener implements ISelectionChangedListener { |
170 |
/* |
171 |
* (non-Javadoc) |
172 |
* |
173 |
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
174 |
*/ |
175 |
public void selectionChanged(SelectionChangedEvent event) { |
176 |
String[] contextTypes = getContextTypes(); |
177 |
if (needUpdate(contextTypes)) { |
178 |
fCurrentContextTypes = contextTypes; |
179 |
updateContextTypes(fCurrentContextTypes); |
180 |
return; |
181 |
} |
182 |
} |
183 |
|
184 |
/** |
185 |
* Check whether an update of the TemplatesPage is needed |
186 |
* |
187 |
* @param contextTypes |
188 |
* @return true if update is needed |
189 |
*/ |
190 |
private boolean needUpdate(String[] contextTypes) { |
191 |
return fCurrentContextTypes == null |
192 |
|| fCurrentContextTypes.length != contextTypes.length |
193 |
|| contextTypeChanged(contextTypes); |
194 |
} |
195 |
|
196 |
/** |
197 |
* Check whether there is any change in the context types needed |
198 |
* |
199 |
* @param contextTypes |
200 |
* @return true if any of the context types changed |
201 |
*/ |
202 |
private boolean contextTypeChanged(String[] contextTypes) { |
203 |
for (int i = 0; i < contextTypes.length; i++) { |
204 |
if (!contextTypes[i].equals(fCurrentContextTypes[i])) |
205 |
return false; |
206 |
} |
207 |
return true; |
208 |
} |
209 |
} |
210 |
|
211 |
/** |
212 |
* Drop support for the editor linked to this page. When a user drops a |
213 |
* template into the active editor, the template is applied at the drop |
214 |
* position. |
215 |
*/ |
216 |
private final class EditorDropTarget extends DropTargetAdapter { |
217 |
/* |
218 |
* (non-Javadoc) |
219 |
* |
220 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent) |
221 |
*/ |
222 |
public void dragEnter(DropTargetEvent event) { |
223 |
event.detail = DND.DROP_COPY; |
224 |
} |
225 |
|
226 |
/* |
227 |
* (non-Javadoc) |
228 |
* |
229 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent) |
230 |
*/ |
231 |
public void dragOperationChanged(DropTargetEvent event) { |
232 |
event.detail = DND.DROP_COPY; |
233 |
} |
234 |
|
235 |
/* |
236 |
* (non-Javadoc) |
237 |
* |
238 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent) |
239 |
*/ |
240 |
public void dragOver(DropTargetEvent event) { |
241 |
event.feedback |= DND.FEEDBACK_SCROLL; |
242 |
event.detail = DND.DROP_NONE; |
243 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
244 |
if (fEditor.isEditorInputModifiable() |
245 |
&& selectedTemplates.length == 1 |
246 |
&& isValidTemplateForPosition(selectedTemplates[0].getTemplate(), new Point( |
247 |
event.x, event.y))) |
248 |
event.detail = DND.DROP_COPY; |
249 |
} |
250 |
|
251 |
/* |
252 |
* (non-Javadoc) |
253 |
* |
254 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd.DropTargetEvent) |
255 |
*/ |
256 |
public void drop(DropTargetEvent event) { |
257 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
258 |
insertTemplate(selectedTemplates[0].getTemplate(), new Point(event.x, event.y)); |
259 |
// The highlight of the item is removed once the drop happens - |
260 |
// restore it |
261 |
fTreeViewer.setSelection(new StructuredSelection(selectedTemplates), true); |
262 |
} |
263 |
} |
264 |
|
265 |
/** |
266 |
* Comparator for the viewer. Sorts the templates by name and then |
267 |
* description and context types by names. |
268 |
*/ |
269 |
private static final class TemplateViewerComparator extends ViewerComparator { |
270 |
/* |
271 |
* (non-Javadoc) |
272 |
* |
273 |
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, |
274 |
* java.lang.Object, java.lang.Object) |
275 |
*/ |
276 |
public int compare(Viewer viewer, Object object1, Object object2) { |
277 |
if ((object1 instanceof TemplatePersistenceData) |
278 |
&& (object2 instanceof TemplatePersistenceData)) { |
279 |
Template left = ((TemplatePersistenceData) object1).getTemplate(); |
280 |
Template right = ((TemplatePersistenceData) object2).getTemplate(); |
281 |
int result = Collator.getInstance().compare(left.getName(), right.getName()); |
282 |
if (result != 0) |
283 |
return result; |
284 |
return Collator.getInstance() |
285 |
.compare(left.getDescription(), right.getDescription()); |
286 |
} |
287 |
if ((object1 instanceof TemplateContextType) |
288 |
&& (object2 instanceof TemplateContextType)) { |
289 |
return Collator.getInstance().compare(((TemplateContextType) object1).getName(), |
290 |
((TemplateContextType) object1).getName()); |
291 |
} |
292 |
return super.compare(viewer, object1, object2); |
293 |
} |
294 |
|
295 |
/* |
296 |
* (non-Javadoc) |
297 |
* |
298 |
* @see org.eclipse.jface.viewers.ViewerComparator#isSorterProperty(java.lang.Object, |
299 |
* java.lang.String) |
300 |
*/ |
301 |
public boolean isSorterProperty(Object element, String property) { |
302 |
return false; |
303 |
} |
304 |
} |
305 |
|
306 |
/** |
307 |
* Label provider for templates. |
308 |
*/ |
309 |
private final class TemplateLabelProvider extends LabelProvider implements ITableLabelProvider { |
310 |
/* |
311 |
* (non-Javadoc) |
312 |
* |
313 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, |
314 |
* int) |
315 |
*/ |
316 |
public Image getColumnImage(Object element, int columnIndex) { |
317 |
if (columnIndex != 0) |
318 |
return null; |
319 |
if (element instanceof TemplateContextType) |
320 |
return CONTEXT_IMAGE; |
321 |
return getImageForTemplate(((TemplatePersistenceData) element).getTemplate()); |
322 |
} |
323 |
|
324 |
/* |
325 |
* (non-Javadoc) |
326 |
* |
327 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, |
328 |
* int) |
329 |
*/ |
330 |
public String getColumnText(Object element, int columnIndex) { |
331 |
if (element instanceof TemplatePersistenceData) |
332 |
return getTemplateColumnText((TemplatePersistenceData) element, columnIndex); |
333 |
return getContextColumnText((TemplateContextType) element, columnIndex); |
334 |
} |
335 |
|
336 |
private String getTemplateColumnText(TemplatePersistenceData data, int columnIndex) { |
337 |
switch (columnIndex) { |
338 |
case 0: |
339 |
return data.getTemplate().getName(); |
340 |
case 1: |
341 |
return data.getTemplate().getDescription(); |
342 |
default: |
343 |
return ""; //$NON-NLS-1$ |
344 |
} |
345 |
} |
346 |
|
347 |
private String getContextColumnText(TemplateContextType contextType, int columnIndex) { |
348 |
switch (columnIndex) { |
349 |
case 0: |
350 |
return contextType.getName(); |
351 |
default: |
352 |
return ""; //$NON-NLS-1$ |
353 |
} |
354 |
} |
355 |
} |
356 |
|
357 |
/** |
358 |
* Content provider for templates. Provides all the enabled templates |
359 |
* defined for this editor. |
360 |
*/ |
361 |
private final class TemplatesContentProvider implements ITreeContentProvider { |
362 |
/* |
363 |
* (non-Javadoc) |
364 |
* |
365 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) |
366 |
*/ |
367 |
public Object[] getChildren(Object parentElement) { |
368 |
if (parentElement instanceof TemplatePersistenceData) |
369 |
return new Object[0]; |
370 |
else if (parentElement instanceof TemplateContextType) { |
371 |
TemplateContextType contextType = (TemplateContextType) parentElement; |
372 |
return getTemplates(contextType.getId()); |
373 |
} |
374 |
return null; |
375 |
} |
376 |
|
377 |
private TemplatePersistenceData[] getTemplates(String contextId) { |
378 |
List templateList = new ArrayList(); |
379 |
TemplatePersistenceData[] datas = getTemplateStore().getTemplateData(false); |
380 |
for (int i = 0; i < datas.length; i++) { |
381 |
if (datas[i].isEnabled() |
382 |
&& datas[i].getTemplate().getContextTypeId().equals(contextId)) |
383 |
templateList.add(datas[i]); |
384 |
} |
385 |
return (TemplatePersistenceData[]) templateList |
386 |
.toArray(new TemplatePersistenceData[templateList.size()]); |
387 |
} |
388 |
|
389 |
/* |
390 |
* (non-Javadoc) |
391 |
* |
392 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) |
393 |
*/ |
394 |
public Object getParent(Object element) { |
395 |
if (element instanceof TemplatePersistenceData) { |
396 |
TemplatePersistenceData templateData = (TemplatePersistenceData) element; |
397 |
return getContextTypeRegistry().getContextType( |
398 |
templateData.getTemplate().getContextTypeId()); |
399 |
} |
400 |
return null; |
401 |
} |
402 |
|
403 |
/* |
404 |
* (non-Javadoc) |
405 |
* |
406 |
* @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) |
407 |
*/ |
408 |
public boolean hasChildren(Object element) { |
409 |
if (element instanceof TemplateContextType) |
410 |
return true; |
411 |
return false; |
412 |
} |
413 |
|
414 |
/* |
415 |
* (non-Javadoc) |
416 |
* |
417 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
418 |
*/ |
419 |
public Object[] getElements(Object inputElement) { |
420 |
List contextTypes = new ArrayList(); |
421 |
|
422 |
for (Iterator iterator = getContextTypeRegistry().contextTypes(); iterator.hasNext();) { |
423 |
TemplateContextType contextType = (TemplateContextType) iterator.next(); |
424 |
if (!fLinkWithEditorAction.isChecked() || isActiveContext(contextType)) |
425 |
contextTypes.add(contextType); |
426 |
} |
427 |
return contextTypes.toArray(new TemplateContextType[contextTypes.size()]); |
428 |
} |
429 |
|
430 |
private boolean isActiveContext(TemplateContextType contextType) { |
431 |
return fActiveTypes == null || fActiveTypes.contains(contextType.getId()); |
432 |
} |
433 |
|
434 |
/* |
435 |
* (non-Javadoc) |
436 |
* |
437 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
438 |
*/ |
439 |
public void dispose() { |
440 |
} |
441 |
|
442 |
/* |
443 |
* (non-Javadoc) |
444 |
* |
445 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, |
446 |
* java.lang.Object, java.lang.Object) |
447 |
*/ |
448 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
449 |
} |
450 |
} |
451 |
|
452 |
/* The editor */ |
453 |
private final AbstractTextEditor fEditor; |
454 |
/* The SourceViewer attached to this editor */ |
455 |
private final ISourceViewer fViewer; |
456 |
|
457 |
/* Listener to monitor changes to template store */ |
458 |
private IPropertyChangeListener fTemplateChangeListener; |
459 |
|
460 |
/* Control for this pagebook view */ |
461 |
private SashForm fControl; |
462 |
|
463 |
/* Actions */ |
464 |
private Action fInsertAction; |
465 |
private Action fAddAction; |
466 |
private Action fEditAction; |
467 |
private Action fRemoveAction; |
468 |
private Action fLinkWithEditorAction; |
469 |
private Action fCollapseAllAction; |
470 |
private Action fPreferencePageAction; |
471 |
|
472 |
/* Clipboard actions */ |
473 |
private Action fPasteAction; |
474 |
private Action fCopyAction; |
475 |
|
476 |
/* Current active context types for the editor */ |
477 |
private List fActiveTypes; |
478 |
|
479 |
/* Preference stores */ |
480 |
private IPreferenceStore fPreferenceStore; |
481 |
|
482 |
/* Controls */ |
483 |
private Tree fTemplatesTree; |
484 |
private TreeViewer fTreeViewer; |
485 |
private Menu fContextMenu; |
486 |
|
487 |
/* Current selection */ |
488 |
private TemplatePersistenceData[] fSelectedTemplates = new TemplatePersistenceData[0]; |
489 |
|
490 |
/* The pattern viewer to be used with this view */ |
491 |
private SourceViewer fPatternViewer; |
492 |
|
493 |
/* Cached results for avoiding processing while drag-over the editor */ |
494 |
private int fCachedOffset; |
495 |
private boolean fCachedResult; |
496 |
private Point fCachedPosition; |
497 |
|
498 |
/* The current context types */ |
499 |
protected String[] fCurrentContextTypes; |
500 |
|
501 |
/* The selection changed listener to monitor the editor selections */ |
502 |
private SelectionChangedListener fSelectionChangedListener; |
503 |
|
504 |
/* Paste action support for the editor */ |
505 |
private IAction fEditorOldPasteAction; |
506 |
private IAction fEditorPasteAction; |
507 |
|
508 |
/** |
509 |
* Creates a new template view page. |
510 |
* |
511 |
* @param editor |
512 |
* @param viewer |
513 |
*/ |
514 |
protected TemplatesPage(AbstractTextEditor editor, ISourceViewer viewer) { |
515 |
super(); |
516 |
fEditor = editor; |
517 |
fViewer = viewer; |
518 |
setupPreferenceStore(); |
519 |
setupEditorDropTarget(); |
520 |
setupSelectionProvider(); |
521 |
setupPasteOperation(); |
522 |
} |
523 |
|
524 |
/* |
525 |
* (non-Javadoc) |
526 |
* |
527 |
* @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite) |
528 |
*/ |
529 |
public void createControl(Composite ancestor) { |
530 |
setupActions(); |
531 |
|
532 |
fControl = new SashForm(ancestor, SWT.VERTICAL); |
533 |
|
534 |
createTemplateTree(fControl); |
535 |
createPatternForm(fControl); |
536 |
|
537 |
hookContextMenu(); |
538 |
initializeDND(); |
539 |
updateButtons(); |
540 |
|
541 |
int sashSize = fPreferenceStore.getInt(SASH_SIZE_PREF_ID); |
542 |
fControl.setWeights(new int[] { sashSize, 100 - sashSize }); |
543 |
fTemplateChangeListener = new IPropertyChangeListener() { |
544 |
public void propertyChange(PropertyChangeEvent event) { |
545 |
getShell().getDisplay().asyncExec(new Runnable() { |
546 |
public void run() { |
547 |
refresh(); |
548 |
} |
549 |
}); |
550 |
} |
551 |
}; |
552 |
getTemplatePreferenceStore().addPropertyChangeListener(fTemplateChangeListener); |
553 |
} |
554 |
|
555 |
/* |
556 |
* (non-Javadoc) |
557 |
* |
558 |
* @see org.eclipse.ui.part.Page#setFocus() |
559 |
*/ |
560 |
public void setFocus() { |
561 |
} |
562 |
|
563 |
/* |
564 |
* (non-Javadoc) |
565 |
* |
566 |
* @see org.eclipse.ui.part.Page#getControl() |
567 |
*/ |
568 |
public Control getControl() { |
569 |
return fControl; |
570 |
} |
571 |
|
572 |
/* |
573 |
* (non-Javadoc) |
574 |
* |
575 |
* @see org.eclipse.ui.part.Page#dispose() |
576 |
*/ |
577 |
public void dispose() { |
578 |
ISelectionProvider selectionProvider = fViewer.getSelectionProvider(); |
579 |
if (selectionProvider instanceof IPostSelectionProvider) |
580 |
((IPostSelectionProvider) selectionProvider) |
581 |
.removePostSelectionChangedListener(fSelectionChangedListener); |
582 |
else |
583 |
selectionProvider.removeSelectionChangedListener(fSelectionChangedListener); |
584 |
fEditor.setAction(ITextEditorActionConstants.PASTE, fEditorOldPasteAction); |
585 |
if (fContextMenu != null && !fContextMenu.isDisposed()) |
586 |
fContextMenu.dispose(); |
587 |
if (fTemplateChangeListener != null) |
588 |
getTemplatePreferenceStore().removePropertyChangeListener(fTemplateChangeListener); |
589 |
super.dispose(); |
590 |
} |
591 |
|
592 |
/** |
593 |
* Get the shell |
594 |
* |
595 |
* @return the shell for this view site |
596 |
*/ |
597 |
protected Shell getShell() { |
598 |
return getSite().getShell(); |
599 |
} |
600 |
|
601 |
/** |
602 |
* Get the image to be used for the given template. Clients can override to |
603 |
* provide a different image. |
604 |
* |
605 |
* @param template |
606 |
* @return handle to the image |
607 |
*/ |
608 |
protected Image getImageForTemplate(Template template) { |
609 |
return DEFAULT_TEMPLATE_IMAGE; |
610 |
} |
611 |
|
612 |
/** |
613 |
* Creates the edit dialog. Subclasses may override this method to provide a |
614 |
* custom dialog. |
615 |
* |
616 |
* @param template |
617 |
* the template being edited |
618 |
* @param edit |
619 |
* whether the dialog should be editable |
620 |
* @param isNameModifiable |
621 |
* whether the template name may be modified |
622 |
* @return the created or modified template, or <code>null</code> if the |
623 |
* editing failed |
624 |
*/ |
625 |
protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) { |
626 |
EditTemplateDialog dialog = new EditTemplateDialog(getShell(), template, edit, |
627 |
isNameModifiable, getContextTypeRegistry()); |
628 |
if (dialog.open() == Window.OK) { |
629 |
return dialog.getTemplate(); |
630 |
} |
631 |
return null; |
632 |
} |
633 |
|
634 |
/** |
635 |
* Update the pattern viewer to show the current template. |
636 |
* |
637 |
* @param template |
638 |
*/ |
639 |
protected void updatePatternViewer(Template template) { |
640 |
if (template != null) |
641 |
fPatternViewer.getDocument().set(template.getPattern()); |
642 |
else |
643 |
fPatternViewer.getDocument().set(""); //$NON-NLS-1$ |
644 |
} |
645 |
|
646 |
/** |
647 |
* Creates, configures and returns a source viewer to present the template |
648 |
* pattern on the templates page. Clients may override to provide a custom |
649 |
* source viewer featuring e.g. syntax coloring. |
650 |
* |
651 |
* @param parent |
652 |
* the parent control |
653 |
* @return a configured source viewer |
654 |
*/ |
655 |
protected SourceViewer createPatternViewer(Composite parent) { |
656 |
SourceViewer viewer = new SourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL |
657 |
| SWT.H_SCROLL); |
658 |
SourceViewerConfiguration configuration = new SourceViewerConfiguration(); |
659 |
viewer.configure(configuration); |
660 |
IDocument document = new Document(); |
661 |
viewer.setDocument(document); |
662 |
viewer.setEditable(false); |
663 |
return viewer; |
664 |
} |
665 |
|
666 |
/** |
667 |
* Get the pattern viewer created by createPatternViewer() |
668 |
* |
669 |
* @return the pattern viewer |
670 |
*/ |
671 |
protected final SourceViewer getPatternViewer() { |
672 |
return fPatternViewer; |
673 |
} |
674 |
|
675 |
/** |
676 |
* Get the editor associated with this view |
677 |
* |
678 |
* @return the editor |
679 |
*/ |
680 |
protected final AbstractTextEditor getEditor() { |
681 |
return fEditor; |
682 |
} |
683 |
|
684 |
/** |
685 |
* The caret position in the editor has moved into a new context type. It is |
686 |
* the subclasses responsibility to see that this is called only when needed |
687 |
* by keeping track of editor contents (eg. partitions). |
688 |
* |
689 |
* @param ids |
690 |
*/ |
691 |
protected final void updateContextTypes(String[] ids) { |
692 |
fActiveTypes = Arrays.asList(ids); |
693 |
if (fLinkWithEditorAction != null && fLinkWithEditorAction.isChecked()) |
694 |
refresh(); |
695 |
} |
696 |
|
697 |
/** |
698 |
* Subclasses should override and facilitate inserting the template code |
699 |
* into the active editor. |
700 |
* |
701 |
* @param template |
702 |
* @param position |
703 |
*/ |
704 |
abstract protected void insertTemplate(Template template, Point position); |
705 |
|
706 |
/** |
707 |
* Get the context type registry for the associated editor. |
708 |
* |
709 |
* @return the contextTypeRegistry |
710 |
*/ |
711 |
abstract protected ContextTypeRegistry getContextTypeRegistry(); |
712 |
|
713 |
/** |
714 |
* Get the template store for the associated editor |
715 |
* |
716 |
* @return the template store |
717 |
*/ |
718 |
abstract protected TemplateStore getTemplateStore(); |
719 |
|
720 |
/** |
721 |
* Get the preference store used to create the template store returned by |
722 |
* {@link TemplatesPage#getTemplateStore()}. |
723 |
* |
724 |
* @return the preference store |
725 |
*/ |
726 |
abstract protected IPreferenceStore getTemplatePreferenceStore(); |
727 |
|
728 |
/** |
729 |
* Get the preference page ID for the templates for the given editor. |
730 |
* |
731 |
* @return id of the preference page, null if none exists |
732 |
*/ |
733 |
abstract protected String getPreferencePageId(); |
734 |
|
735 |
/** |
736 |
* Get the context types supported at the current caret position of the |
737 |
* editor |
738 |
* |
739 |
* @return the ids of the context types |
740 |
*/ |
741 |
protected abstract String[] getContextTypes(); |
742 |
|
743 |
/** |
744 |
* Check whether the given template is valid for the document at the given |
745 |
* position |
746 |
* |
747 |
* @param document |
748 |
* @param template |
749 |
* @param offset |
750 |
* @param length |
751 |
* @return true if the template is valid |
752 |
*/ |
753 |
protected abstract boolean isValidTemplate(IDocument document, Template template, int offset, |
754 |
int length); |
755 |
|
756 |
/** |
757 |
* Setup the preference store |
758 |
*/ |
759 |
private void setupPreferenceStore() { |
760 |
fPreferenceStore = TextEditorPlugin.getDefault().getPreferenceStore(); |
761 |
fPreferenceStore.setDefault(LINK_ACTION_PREF_ID, true); |
762 |
fPreferenceStore.setDefault(SASH_SIZE_PREF_ID, 80); |
763 |
} |
764 |
|
765 |
/** |
766 |
* Setup the paste operation |
767 |
* |
768 |
* We get the editors Paste operation and sets up a new operation that |
769 |
* checks for the clipboard contents for TemplateTransfer data. |
770 |
*/ |
771 |
private void setupPasteOperation() { |
772 |
fEditorOldPasteAction = fEditor.getAction(ITextEditorActionConstants.PASTE); |
773 |
fEditorPasteAction = new Action(TextEditorTemplateMessages.TemplatesPage_paste) { |
774 |
public void run() { |
775 |
Clipboard clipBoard = new Clipboard(getShell().getDisplay()); |
776 |
Template template = getTemplateFromClipboard(clipBoard); |
777 |
if (template != null) |
778 |
insertTemplate(template, null); |
779 |
else |
780 |
fEditorOldPasteAction.run(); |
781 |
} |
782 |
|
783 |
public void runWithEvent(Event event) { |
784 |
Clipboard clipBoard = new Clipboard(getShell().getDisplay()); |
785 |
Template template = getTemplateFromClipboard(clipBoard); |
786 |
if (template != null) |
787 |
insertTemplate(template, null); |
788 |
else |
789 |
fEditorOldPasteAction.runWithEvent(event); |
790 |
} |
791 |
|
792 |
/** |
793 |
* Convert the clipboard contents into a template |
794 |
* |
795 |
* @param clipBoard |
796 |
* @return the template or null if contents are not valid |
797 |
*/ |
798 |
private Template getTemplateFromClipboard(Clipboard clipBoard) { |
799 |
TemplatePersistenceData[] contents = (TemplatePersistenceData[]) clipBoard |
800 |
.getContents(TemplateTransfer.getInstance()); |
801 |
if (contents != null && contents.length == 1) |
802 |
return contents[0].getTemplate(); |
803 |
return null; |
804 |
} |
805 |
}; |
806 |
fEditorPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE); |
807 |
fEditor.setAction(ITextEditorActionConstants.PASTE, fEditorPasteAction); |
808 |
} |
809 |
|
810 |
/** |
811 |
* Setup a selection listener to monitor the editor |
812 |
*/ |
813 |
private void setupSelectionProvider() { |
814 |
ISelectionProvider selectionProvider = fViewer.getSelectionProvider(); |
815 |
fSelectionChangedListener = new SelectionChangedListener(); |
816 |
if (selectionProvider instanceof IPostSelectionProvider) |
817 |
((IPostSelectionProvider) selectionProvider) |
818 |
.addPostSelectionChangedListener(fSelectionChangedListener); |
819 |
else |
820 |
selectionProvider.addSelectionChangedListener(fSelectionChangedListener); |
821 |
} |
822 |
|
823 |
/** |
824 |
* Setup the editor site as a drop target. |
825 |
*/ |
826 |
private void setupEditorDropTarget() { |
827 |
IDragAndDropService dndService = (IDragAndDropService) fEditor.getSite().getService( |
828 |
IDragAndDropService.class); |
829 |
EditorDropTarget editorDropTarget = new EditorDropTarget(); |
830 |
dndService.addMergedDropTarget((Control) fEditor.getAdapter(Control.class), DND.DROP_COPY, |
831 |
new Transfer[] { TemplateTransfer.getInstance() }, editorDropTarget); |
832 |
} |
833 |
|
834 |
/** |
835 |
* Setup the menu, context menu and toolbar actions. |
836 |
*/ |
837 |
private void setupActions() { |
838 |
createActions(); |
839 |
IActionBars actionBars = getSite().getActionBars(); |
840 |
|
841 |
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction); |
842 |
fPasteAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.PASTE); |
843 |
fPasteAction.setText(TextEditorTemplateMessages.TemplatesPage_paste); |
844 |
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction); |
845 |
fCopyAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.COPY); |
846 |
fCopyAction.setText(TextEditorTemplateMessages.TemplatesPage_copy); |
847 |
fillToolbar(actionBars); |
848 |
fillMenu(actionBars); |
849 |
} |
850 |
|
851 |
/** |
852 |
* Create all the actions |
853 |
*/ |
854 |
private void createActions() { |
855 |
fInsertAction = new Action(TextEditorTemplateMessages.TemplatesPage_insert) { |
856 |
public void run() { |
857 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
858 |
insertTemplate(selectedTemplates[0].getTemplate(), null); |
859 |
} |
860 |
}; |
861 |
fInsertAction.setImageDescriptor(TemplatesPageImages |
862 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_INSERT)); |
863 |
fInsertAction.setDisabledImageDescriptor(TemplatesPageImages |
864 |
.getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_INSERT)); |
865 |
fInsertAction.setToolTipText(TextEditorTemplateMessages.TemplatesPage_insert_tooltip); |
866 |
|
867 |
fAddAction = new Action(TextEditorTemplateMessages.TemplatesPage_new) { |
868 |
public void run() { |
869 |
addTemplate(); |
870 |
} |
871 |
}; |
872 |
fAddAction.setImageDescriptor(TemplatesPageImages |
873 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_NEW)); |
874 |
fAddAction.setToolTipText(TextEditorTemplateMessages.TemplatesPage_new_tooltip); |
875 |
|
876 |
fEditAction = new Action(TextEditorTemplateMessages.TemplatesPage_edit) { |
877 |
public void run() { |
878 |
editTemplate(); |
879 |
} |
880 |
}; |
881 |
fEditAction.setImageDescriptor(TemplatesPageImages |
882 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_EDIT)); |
883 |
fEditAction.setDisabledImageDescriptor(TemplatesPageImages |
884 |
.getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_EDIT)); |
885 |
fEditAction.setToolTipText(TextEditorTemplateMessages.TemplatesPage_edit_tooltip); |
886 |
|
887 |
fRemoveAction = new Action(TextEditorTemplateMessages.TemplatesPage_remove) { |
888 |
public void run() { |
889 |
removeTemplates(); |
890 |
} |
891 |
}; |
892 |
fRemoveAction.setImageDescriptor(TemplatesPageImages |
893 |
.getImageDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_DELETE)); |
894 |
fRemoveAction.setImageDescriptor(TemplatesPageImages |
895 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_DELETE)); |
896 |
fRemoveAction.setToolTipText(TextEditorTemplateMessages.TemplatesPage_remove_tooltip); |
897 |
|
898 |
fLinkWithEditorAction = new Action(TextEditorTemplateMessages.TemplatesPage_link_to_editor, |
899 |
IAction.AS_CHECK_BOX) { |
900 |
public void run() { |
901 |
fPreferenceStore.setValue(LINK_ACTION_PREF_ID, fLinkWithEditorAction.isChecked()); |
902 |
refresh(); |
903 |
} |
904 |
}; |
905 |
fLinkWithEditorAction.setImageDescriptor(TemplatesPageImages |
906 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_LINK)); |
907 |
fLinkWithEditorAction.setChecked(fPreferenceStore.getBoolean(LINK_ACTION_PREF_ID)); |
908 |
fLinkWithEditorAction |
909 |
.setToolTipText(TextEditorTemplateMessages.TemplatesPage_link_to_editor_tooltip); |
910 |
fCollapseAllAction = new Action(TextEditorTemplateMessages.TemplatesPage_collapse_all) { |
911 |
public void run() { |
912 |
fTreeViewer.collapseAll(); |
913 |
} |
914 |
}; |
915 |
fCollapseAllAction.setImageDescriptor(TemplatesPageImages |
916 |
.getImageDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_COLLAPSE_ALL)); |
917 |
fCollapseAllAction.setToolTipText(TextEditorTemplateMessages.TemplatesPage_collapse_all_tooltip); |
918 |
|
919 |
if (getPreferencePageId() != null) { |
920 |
fPreferencePageAction = new Action(TextEditorTemplateMessages.TemplatesPage_preference_page) { |
921 |
public void run() { |
922 |
showPreferencePage(); |
923 |
} |
924 |
}; |
925 |
fPreferencePageAction |
926 |
.setToolTipText(TextEditorTemplateMessages.TemplatesPage_preference_page_tooltip); |
927 |
} |
928 |
|
929 |
fPasteAction = new Action() { |
930 |
public void run() { |
931 |
Clipboard clipBoard = new Clipboard(getShell().getDisplay()); |
932 |
String pattern = ((String) clipBoard.getContents(TextTransfer.getInstance())); |
933 |
if (pattern != null) { |
934 |
final Template template = new Template(createTemplateName(), |
935 |
TextEditorTemplateMessages.TemplatesPage_paste_description, |
936 |
getContextTypeId(), pattern.replaceAll("\\$", "\\$\\$"), true); //$NON-NLS-1$//$NON-NLS-2$ |
937 |
if (template != null) |
938 |
getShell().getDisplay().asyncExec(new Runnable() { |
939 |
public void run() { |
940 |
addTemplate(template); |
941 |
} |
942 |
}); |
943 |
return ; |
944 |
} |
945 |
TemplatePersistenceData[] templates = (TemplatePersistenceData[]) clipBoard |
946 |
.getContents(TemplateTransfer.getInstance()); |
947 |
if (templates != null) |
948 |
copyTemplates(templates, getContextTypeId()); |
949 |
} |
950 |
}; |
951 |
|
952 |
fCopyAction = new Action() { |
953 |
public void run() { |
954 |
Clipboard clipBoard = new Clipboard(getShell().getDisplay()); |
955 |
clipBoard.setContents(new Object[] { getSelectedTemplates() }, |
956 |
new Transfer[] { TemplateTransfer.getInstance() }); |
957 |
} |
958 |
}; |
959 |
} |
960 |
|
961 |
/** |
962 |
* Fill the toolbar |
963 |
* |
964 |
* @param actionBars |
965 |
*/ |
966 |
private void fillToolbar(IActionBars actionBars) { |
967 |
IToolBarManager toolBarManager = actionBars.getToolBarManager(); |
968 |
toolBarManager.add(fInsertAction); |
969 |
toolBarManager.add(fAddAction); |
970 |
toolBarManager.add(fEditAction); |
971 |
toolBarManager.add(fRemoveAction); |
972 |
|
973 |
toolBarManager.add(new Separator()); |
974 |
|
975 |
toolBarManager.add(fLinkWithEditorAction); |
976 |
toolBarManager.add(fCollapseAllAction); |
977 |
} |
978 |
|
979 |
/** |
980 |
* Fill the view menu |
981 |
* |
982 |
* @param actionBars |
983 |
*/ |
984 |
private void fillMenu(IActionBars actionBars) { |
985 |
IMenuManager menuManager = actionBars.getMenuManager(); |
986 |
|
987 |
if (fPreferencePageAction != null) { |
988 |
menuManager.add(fPreferencePageAction); |
989 |
menuManager.add(new Separator()); |
990 |
} |
991 |
|
992 |
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
993 |
} |
994 |
|
995 |
/** |
996 |
* Fill the context menu items |
997 |
* |
998 |
* @param manager |
999 |
*/ |
1000 |
private void fillContextMenu(IMenuManager manager) { |
1001 |
manager.add(fInsertAction); |
1002 |
manager.add(new Separator()); |
1003 |
manager.add(fAddAction); |
1004 |
manager.add(fEditAction); |
1005 |
manager.add(fRemoveAction); |
1006 |
manager.add(new Separator()); |
1007 |
manager.add(fCopyAction); |
1008 |
manager.add(fPasteAction); |
1009 |
// Other plug-ins can contribute there actions here |
1010 |
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
1011 |
} |
1012 |
|
1013 |
/** |
1014 |
* Create the tree to display templates |
1015 |
* |
1016 |
* @param parent |
1017 |
*/ |
1018 |
private void createTemplateTree(Composite parent) { |
1019 |
Composite treeComposite = new Composite(parent, SWT.NONE); |
1020 |
GridData data = new GridData(GridData.FILL_BOTH); |
1021 |
treeComposite.setLayoutData(data); |
1022 |
|
1023 |
TreeColumnLayout columnLayout = new TreeColumnLayout(); |
1024 |
treeComposite.setLayout(columnLayout); |
1025 |
fTemplatesTree = new Tree(treeComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI |
1026 |
| SWT.FULL_SELECTION); |
1027 |
fTemplatesTree.setHeaderVisible(true); |
1028 |
fTemplatesTree.setLinesVisible(true); |
1029 |
|
1030 |
PixelConverter pixelConverter = new PixelConverter(fTemplatesTree); |
1031 |
|
1032 |
TreeColumn columnName = new TreeColumn(fTemplatesTree, SWT.NONE); |
1033 |
columnName.setText(TextEditorTemplateMessages.TemplatesPage_column_name); |
1034 |
int minWidth = fPreferenceStore.getInt(COLUMN_NAME_WIDTH_PREF_ID); |
1035 |
if (minWidth == 0) { |
1036 |
minWidth = pixelConverter.convertWidthInCharsToPixels(30); |
1037 |
} |
1038 |
columnLayout.setColumnData(columnName, new ColumnPixelData(minWidth, true)); |
1039 |
columnName.addControlListener(new ControlListener() { |
1040 |
public void controlMoved(ControlEvent e) { |
1041 |
} |
1042 |
|
1043 |
public void controlResized(ControlEvent e) { |
1044 |
int nameWidth = ((TreeColumn) e.getSource()).getWidth(); |
1045 |
fPreferenceStore.setValue(COLUMN_NAME_WIDTH_PREF_ID, nameWidth); |
1046 |
} |
1047 |
}); |
1048 |
|
1049 |
TreeColumn columnDescription = new TreeColumn(fTemplatesTree, SWT.NONE); |
1050 |
columnDescription.setText(TextEditorTemplateMessages.TemplatesPage_column_description); |
1051 |
minWidth = fPreferenceStore.getInt(COLUMN_DESCRIPTION_WIDTH_PREF_ID); |
1052 |
if (minWidth == 0) { |
1053 |
minWidth = pixelConverter.convertWidthInCharsToPixels(45); |
1054 |
} |
1055 |
columnLayout.setColumnData(columnDescription, new ColumnPixelData(minWidth, false)); |
1056 |
columnDescription.addControlListener(new ControlListener() { |
1057 |
public void controlMoved(ControlEvent e) { |
1058 |
} |
1059 |
|
1060 |
public void controlResized(ControlEvent e) { |
1061 |
int descriptionWidth = ((TreeColumn) e.getSource()).getWidth(); |
1062 |
fPreferenceStore.setValue(COLUMN_DESCRIPTION_WIDTH_PREF_ID, descriptionWidth); |
1063 |
} |
1064 |
}); |
1065 |
|
1066 |
createTreeViewer(fTemplatesTree); |
1067 |
} |
1068 |
|
1069 |
/** |
1070 |
* Create the tree viewer and setup the providers |
1071 |
* |
1072 |
* @param templatesTree |
1073 |
*/ |
1074 |
private void createTreeViewer(Tree templatesTree) { |
1075 |
fTreeViewer = new TreeViewer(fTemplatesTree); |
1076 |
fTreeViewer.setLabelProvider(new TemplateLabelProvider()); |
1077 |
fTreeViewer.setContentProvider(new TemplatesContentProvider()); |
1078 |
|
1079 |
fTreeViewer.setComparator(new TemplateViewerComparator()); |
1080 |
fTreeViewer.setInput(getTemplatePreferenceStore()); |
1081 |
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() { |
1082 |
public void doubleClick(DoubleClickEvent e) { |
1083 |
updateSelectedItems(); |
1084 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
1085 |
insertTemplate(selectedTemplates[0].getTemplate(), null); |
1086 |
} |
1087 |
}); |
1088 |
|
1089 |
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
1090 |
public void selectionChanged(SelectionChangedEvent e) { |
1091 |
updateSelectedItems(); |
1092 |
updateButtons(); |
1093 |
} |
1094 |
}); |
1095 |
fTreeViewer.expandAll(); |
1096 |
} |
1097 |
|
1098 |
/** |
1099 |
* Setup the pattern viewer |
1100 |
* |
1101 |
* @param parent |
1102 |
*/ |
1103 |
private void createPatternForm(Composite parent) { |
1104 |
ViewForm viewForm = new ViewForm(parent, SWT.NONE); |
1105 |
viewForm.setBorderVisible(false); |
1106 |
CLabel previewLabel = new CLabel(viewForm, SWT.NONE); |
1107 |
previewLabel.setText(TextEditorTemplateMessages.TemplatesPage_preview); |
1108 |
previewLabel.setImage(TemplatesPageImages.getImage(TemplatesPageImages.IMG_OBJ_PREVIEW)); |
1109 |
viewForm.setTopLeft(previewLabel); |
1110 |
|
1111 |
fPatternViewer = createPatternViewer(viewForm); |
1112 |
viewForm.setContent(fPatternViewer.getControl()); |
1113 |
viewForm.addControlListener(new ControlListener() { |
1114 |
public void controlMoved(ControlEvent e) { |
1115 |
} |
1116 |
|
1117 |
public void controlResized(ControlEvent e) { |
1118 |
int[] weights = fControl.getWeights(); |
1119 |
int sashSize = (int) (weights[0] * 100.0 / (weights[0] + weights[1])); |
1120 |
fPreferenceStore.setValue(SASH_SIZE_PREF_ID, sashSize); |
1121 |
} |
1122 |
}); |
1123 |
} |
1124 |
|
1125 |
/** |
1126 |
* Hookup the context menu |
1127 |
*/ |
1128 |
private void hookContextMenu() { |
1129 |
MenuManager menuMgr = new MenuManager(POPUP_MENU_ID); |
1130 |
menuMgr.setRemoveAllWhenShown(true); |
1131 |
menuMgr.addMenuListener(new IMenuListener() { |
1132 |
public void menuAboutToShow(IMenuManager manager) { |
1133 |
fillContextMenu(manager); |
1134 |
} |
1135 |
}); |
1136 |
fContextMenu = menuMgr.createContextMenu(fTreeViewer.getControl()); |
1137 |
fTreeViewer.getControl().setMenu(fContextMenu); |
1138 |
getSite().registerContextMenu(POPUP_MENU_ID, menuMgr, fTreeViewer); |
1139 |
} |
1140 |
|
1141 |
/** |
1142 |
* Check whether the template is valid for the given drop position |
1143 |
* |
1144 |
* @param template |
1145 |
* @param position |
1146 |
* @return true if the template is valid |
1147 |
*/ |
1148 |
private boolean isValidTemplateForPosition(Template template, Point position) { |
1149 |
StyledText textWidget = (StyledText) fEditor.getAdapter(Control.class); |
1150 |
IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); |
1151 |
try { |
1152 |
if (position.equals(fCachedPosition)) |
1153 |
return fCachedResult; |
1154 |
fCachedPosition = position; |
1155 |
int offset = getOffset(document, textWidget, textWidget.toControl(position.x, |
1156 |
position.y)); |
1157 |
if (fCachedOffset == offset) |
1158 |
return fCachedResult; |
1159 |
fCachedOffset = offset; |
1160 |
if (isValidTemplate(document, template, offset, 0)) |
1161 |
return fCachedResult = true; |
1162 |
} catch (BadLocationException e) { |
1163 |
} |
1164 |
return fCachedResult = false; |
1165 |
} |
1166 |
|
1167 |
/** |
1168 |
* Update the selected items. |
1169 |
*/ |
1170 |
private void updateSelectedItems() { |
1171 |
setSelectedTemplates(); |
1172 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
1173 |
|
1174 |
if (selectedTemplates.length == 1) |
1175 |
updatePatternViewer(selectedTemplates[0].getTemplate()); |
1176 |
else |
1177 |
updatePatternViewer(null); |
1178 |
} |
1179 |
|
1180 |
/** |
1181 |
* Show the preference page. The action is enabled only if |
1182 |
* getPreferencePageId() returns non-null. |
1183 |
*/ |
1184 |
private void showPreferencePage() { |
1185 |
PreferencesUtil.createPreferenceDialogOn(getShell(), getPreferencePageId(), null, null) |
1186 |
.open(); |
1187 |
} |
1188 |
|
1189 |
/** |
1190 |
* Update the state of the buttons |
1191 |
*/ |
1192 |
private void updateButtons() { |
1193 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
1194 |
fCopyAction.setEnabled(selectedTemplates.length > 0); |
1195 |
fInsertAction.setEnabled(selectedTemplates.length == 1); |
1196 |
fEditAction.setEnabled(selectedTemplates.length == 1); |
1197 |
fRemoveAction.setEnabled(selectedTemplates.length > 0); |
1198 |
} |
1199 |
|
1200 |
/** |
1201 |
* Set the selected templates |
1202 |
*/ |
1203 |
private void setSelectedTemplates() { |
1204 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
1205 |
|
1206 |
Iterator it = selection.iterator(); |
1207 |
TemplatePersistenceData[] data = new TemplatePersistenceData[selection.size()]; |
1208 |
int i = 0; |
1209 |
while (it.hasNext()) { |
1210 |
Object o = it.next(); |
1211 |
if (o instanceof TemplatePersistenceData) |
1212 |
data[i++] = (TemplatePersistenceData) o; |
1213 |
else { |
1214 |
fSelectedTemplates = new TemplatePersistenceData[0]; |
1215 |
return; |
1216 |
} |
1217 |
} |
1218 |
fSelectedTemplates = data; |
1219 |
} |
1220 |
|
1221 |
/** |
1222 |
* Get the currently selected templates |
1223 |
* |
1224 |
* @return selected tempaltes |
1225 |
*/ |
1226 |
private TemplatePersistenceData[] getSelectedTemplates() { |
1227 |
return fSelectedTemplates; |
1228 |
} |
1229 |
|
1230 |
/** |
1231 |
* Add a template |
1232 |
*/ |
1233 |
private void addTemplate() { |
1234 |
String id = getContextTypeId(); |
1235 |
if (id != null) { |
1236 |
Template template = new Template("", "", id, "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1237 |
|
1238 |
addTemplate(template); |
1239 |
} |
1240 |
} |
1241 |
|
1242 |
/** |
1243 |
* Get contextType of the selected template |
1244 |
* |
1245 |
* @return contextType of the selected template or the first from the |
1246 |
* registry if no templates are selected |
1247 |
*/ |
1248 |
private String getContextTypeId() { |
1249 |
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection(); |
1250 |
Object item; |
1251 |
|
1252 |
if (selection.size() == 0) |
1253 |
return ((TemplateContextType) getContextTypeRegistry().contextTypes().next()).getId(); |
1254 |
|
1255 |
if (selection.size() == 1) { |
1256 |
item = selection.getFirstElement(); |
1257 |
if (item instanceof TemplatePersistenceData) |
1258 |
return ((TemplatePersistenceData) item).getTemplate().getContextTypeId(); |
1259 |
return ((TemplateContextType) item).getId(); |
1260 |
} |
1261 |
Iterator it = selection.iterator(); |
1262 |
String contextId = null; |
1263 |
while (it.hasNext()) { |
1264 |
item = it.next(); |
1265 |
if (contextId == null) |
1266 |
contextId = getContextId(item); |
1267 |
else if (!contextId.equals(getContextId(item))) |
1268 |
return ((TemplateContextType) getContextTypeRegistry().contextTypes().next()) |
1269 |
.getId(); |
1270 |
} |
1271 |
return contextId; |
1272 |
} |
1273 |
|
1274 |
/** |
1275 |
* Get the context id for the given item which is either a template or a |
1276 |
* context type. |
1277 |
* |
1278 |
* @param item |
1279 |
* @return the context type id |
1280 |
*/ |
1281 |
private String getContextId(Object item) { |
1282 |
String contextId; |
1283 |
if (item instanceof TemplatePersistenceData) |
1284 |
contextId = ((TemplatePersistenceData) item).getTemplate().getContextTypeId(); |
1285 |
else |
1286 |
contextId = ((TemplateContextType) item).getId(); |
1287 |
return contextId; |
1288 |
} |
1289 |
|
1290 |
/** |
1291 |
* Add a template. The dialog is filled with the values from the given |
1292 |
* template. |
1293 |
* |
1294 |
* @param template |
1295 |
*/ |
1296 |
private void addTemplate(Template template) { |
1297 |
Template newTemplate; |
1298 |
newTemplate = editTemplate(template, false, true); |
1299 |
if (newTemplate != null) { |
1300 |
TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true); |
1301 |
getTemplateStore().add(data); |
1302 |
saveTemplateStore(); |
1303 |
refresh(); |
1304 |
fTreeViewer.setSelection(new StructuredSelection(data), true); |
1305 |
} |
1306 |
} |
1307 |
|
1308 |
/** |
1309 |
* Save the template store |
1310 |
*/ |
1311 |
private void saveTemplateStore() { |
1312 |
try { |
1313 |
getTemplateStore().save(); |
1314 |
} catch (IOException e) { |
1315 |
e.printStackTrace(); |
1316 |
MessageDialog.openError(getShell(), |
1317 |
TextEditorTemplateMessages.TemplatesPage_save_error_message, e.getMessage()); |
1318 |
} |
1319 |
} |
1320 |
|
1321 |
/** |
1322 |
* Edit the selected template |
1323 |
*/ |
1324 |
private void editTemplate() { |
1325 |
Template oldTemplate = getSelectedTemplates()[0].getTemplate(); |
1326 |
Template newTemplate = editTemplate(new Template(oldTemplate), true, true); |
1327 |
if (newTemplate != null) { |
1328 |
if (!newTemplate.getName().equals(oldTemplate.getName()) |
1329 |
&& MessageDialog.openQuestion(getShell(), |
1330 |
TextEditorTemplateMessages.TemplatesPage_question_create_new_title, |
1331 |
TextEditorTemplateMessages.TemplatesPage_question_create_new_message)) { |
1332 |
TemplatePersistenceData templateData = new TemplatePersistenceData(newTemplate, |
1333 |
true); |
1334 |
getTemplateStore().add(templateData); |
1335 |
refresh(); |
1336 |
fTreeViewer.setSelection(new StructuredSelection(templateData), true); |
1337 |
} else { |
1338 |
getSelectedTemplates()[0].setTemplate(newTemplate); |
1339 |
} |
1340 |
} |
1341 |
saveTemplateStore(); |
1342 |
} |
1343 |
|
1344 |
/** |
1345 |
* Move the selected template from one context to another |
1346 |
* |
1347 |
* @param templates |
1348 |
* @param contextId |
1349 |
* |
1350 |
*/ |
1351 |
private void moveTemplates(TemplatePersistenceData[] templates, String contextId) { |
1352 |
for (int i = 0; i < templates.length; i++) { |
1353 |
Template t = templates[i].getTemplate(); |
1354 |
templates[i].setTemplate(new Template(t.getName(), t.getDescription(), contextId, t |
1355 |
.getPattern(), t.isAutoInsertable())); |
1356 |
} |
1357 |
saveTemplateStore(); |
1358 |
fTreeViewer.setSelection(new StructuredSelection(templates), true); |
1359 |
} |
1360 |
|
1361 |
/** |
1362 |
* Copy the selected templates to another context |
1363 |
* |
1364 |
* @param templates |
1365 |
* @param contextId |
1366 |
* |
1367 |
*/ |
1368 |
private void copyTemplates(TemplatePersistenceData[] templates, String contextId) { |
1369 |
TemplatePersistenceData[] newTemplates = new TemplatePersistenceData[templates.length]; |
1370 |
for (int i = 0; i < templates.length; i++) { |
1371 |
Template t = templates[i].getTemplate(); |
1372 |
newTemplates[i] = new TemplatePersistenceData(new Template(t.getName(), t |
1373 |
.getDescription(), contextId, t.getPattern(), t.isAutoInsertable()), true); |
1374 |
getTemplateStore().add(newTemplates[i]); |
1375 |
} |
1376 |
saveTemplateStore(); |
1377 |
refresh(); |
1378 |
fTreeViewer.setSelection(new StructuredSelection(newTemplates), true); |
1379 |
} |
1380 |
|
1381 |
/** |
1382 |
* Remove one or more selected templates |
1383 |
*/ |
1384 |
private void removeTemplates() { |
1385 |
String title; |
1386 |
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates(); |
1387 |
if (selectedTemplates.length == 1) |
1388 |
title = TextEditorTemplateMessages.TemplatesPage_remove_title_single; |
1389 |
else |
1390 |
title = TextEditorTemplateMessages.TemplatesPage_remove_title_multi; |
1391 |
String message; |
1392 |
if (selectedTemplates.length == 1) |
1393 |
message = TextEditorTemplateMessages.TemplatesPage_remove_message_single; |
1394 |
else |
1395 |
message = NLSUtility.format(TextEditorTemplateMessages.TemplatesPage_remove_message_multi, |
1396 |
new Object[] { new Integer(selectedTemplates.length) }); |
1397 |
if (!MessageDialog.openQuestion(getShell(), title, message)) |
1398 |
return; |
1399 |
for (int i = 0; i < selectedTemplates.length; i++) { |
1400 |
getTemplateStore().delete(selectedTemplates[i]); |
1401 |
} |
1402 |
saveTemplateStore(); |
1403 |
fTreeViewer.setSelection(new StructuredSelection(new Object[] {}), true); |
1404 |
} |
1405 |
|
1406 |
/** |
1407 |
* Initialize drag and drop the template items |
1408 |
*/ |
1409 |
private void initializeDND() { |
1410 |
DragSourceAdapter dragListener = new DragSourceAdapter() { |
1411 |
/* |
1412 |
* (non-Javadoc) |
1413 |
* |
1414 |
* @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent) |
1415 |
*/ |
1416 |
public void dragStart(DragSourceEvent event) { |
1417 |
if (getSelectedTemplates().length == 0) { |
1418 |
event.doit = false; |
1419 |
} |
1420 |
} |
1421 |
|
1422 |
/* |
1423 |
* (non-Javadoc) |
1424 |
* |
1425 |
* @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent) |
1426 |
*/ |
1427 |
public void dragSetData(DragSourceEvent event) { |
1428 |
if (TemplateTransfer.getInstance().isSupportedType(event.dataType)) { |
1429 |
event.data = getSelectedTemplates(); |
1430 |
} |
1431 |
} |
1432 |
}; |
1433 |
fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplateTransfer |
1434 |
.getInstance() }, dragListener); |
1435 |
DropTargetAdapter dropListener = new DropTargetAdapter() { |
1436 |
Transfer textTransfer = TextTransfer.getInstance(); |
1437 |
Transfer templateTransfer = TemplateTransfer.getInstance(); |
1438 |
|
1439 |
/* |
1440 |
* (non-Javadoc) |
1441 |
* |
1442 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragEnter(org.eclipse.swt.dnd.DropTargetEvent) |
1443 |
*/ |
1444 |
public void dragEnter(DropTargetEvent event) { |
1445 |
if (event.detail == DND.DROP_DEFAULT) |
1446 |
event.detail = DND.DROP_COPY; |
1447 |
} |
1448 |
|
1449 |
/* |
1450 |
* (non-Javadoc) |
1451 |
* |
1452 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent) |
1453 |
*/ |
1454 |
public void dragOperationChanged(DropTargetEvent event) { |
1455 |
if (event.detail == DND.DROP_DEFAULT) |
1456 |
event.detail = DND.DROP_COPY; |
1457 |
} |
1458 |
|
1459 |
/* |
1460 |
* (non-Javadoc) |
1461 |
* |
1462 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent) |
1463 |
*/ |
1464 |
public void dragOver(DropTargetEvent event) { |
1465 |
event.feedback |= DND.FEEDBACK_SCROLL; |
1466 |
if (event.item == null) { |
1467 |
event.detail = DND.DROP_NONE; |
1468 |
return; |
1469 |
} |
1470 |
int index = 0; |
1471 |
boolean isTemplateTransfer = false; |
1472 |
while (index < event.dataTypes.length) { |
1473 |
if (textTransfer.isSupportedType(event.dataTypes[index])) { |
1474 |
break; |
1475 |
} |
1476 |
if (templateTransfer.isSupportedType(event.dataTypes[index])) { |
1477 |
isTemplateTransfer = true; |
1478 |
break; |
1479 |
} |
1480 |
index++; |
1481 |
} |
1482 |
if (index < event.dataTypes.length) { |
1483 |
event.currentDataType = event.dataTypes[index]; |
1484 |
if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer) |
1485 |
event.detail = DND.DROP_COPY; |
1486 |
return; |
1487 |
} |
1488 |
} |
1489 |
|
1490 |
/* |
1491 |
* (non-Javadoc) |
1492 |
* |
1493 |
* @see org.eclipse.swt.dnd.DropTargetAdapter#drop(org.eclipse.swt.dnd.DropTargetEvent) |
1494 |
*/ |
1495 |
public void drop(DropTargetEvent event) { |
1496 |
if (event.item == null) |
1497 |
return; |
1498 |
Object object = ((TreeItem) event.item).getData(); |
1499 |
final String contextId; |
1500 |
if (object instanceof TemplateContextType) |
1501 |
contextId = ((TemplateContextType) object).getId(); |
1502 |
else |
1503 |
contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId(); |
1504 |
if (textTransfer.isSupportedType(event.currentDataType)) { |
1505 |
String text = ((String) event.data).replaceAll("\\$", "\\$\\$"); //$NON-NLS-1$ //$NON-NLS-2$ |
1506 |
final Template template = new Template(createTemplateName(), |
1507 |
TextEditorTemplateMessages.TemplatesPage_paste_description, contextId, text, |
1508 |
true); |
1509 |
getShell().getDisplay().asyncExec(new Runnable() { |
1510 |
public void run() { |
1511 |
addTemplate(template); |
1512 |
} |
1513 |
}); |
1514 |
return; |
1515 |
} |
1516 |
if (templateTransfer.isSupportedType(event.currentDataType)) { |
1517 |
final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data; |
1518 |
final int dropType = event.detail; |
1519 |
getShell().getDisplay().asyncExec(new Runnable() { |
1520 |
public void run() { |
1521 |
if (dropType == DND.DROP_COPY) |
1522 |
copyTemplates(templates, contextId); |
1523 |
else |
1524 |
moveTemplates(templates, contextId); |
1525 |
} |
1526 |
}); |
1527 |
} |
1528 |
} |
1529 |
}; |
1530 |
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), |
1531 |
TemplateTransfer.getInstance() }; |
1532 |
fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener); |
1533 |
} |
1534 |
|
1535 |
/** |
1536 |
* Create a template name |
1537 |
* |
1538 |
* @return a new template name |
1539 |
*/ |
1540 |
private String createTemplateName() { |
1541 |
for (int i = 1; i < Integer.MAX_VALUE; i++) { |
1542 |
String name = TextEditorTemplateMessages.TemplatesPage_snippet + i; |
1543 |
if (getTemplateStore().findTemplate(name) == null) |
1544 |
return name; |
1545 |
} |
1546 |
return null; |
1547 |
} |
1548 |
|
1549 |
/** |
1550 |
* Store the collapse state of a context |
1551 |
*/ |
1552 |
private void storeCollapseState() { |
1553 |
TreeItem[] items = fTreeViewer.getTree().getItems(); |
1554 |
for (int i = 0; i < items.length; i++) { |
1555 |
fPreferenceStore.setValue(CONTEXT_COLLAPSE_PREF_ID |
1556 |
+ ((TemplateContextType) items[i].getData()).getId(), !items[i].getExpanded()); |
1557 |
} |
1558 |
} |
1559 |
|
1560 |
/** |
1561 |
* Refresh the template tree contents |
1562 |
*/ |
1563 |
private void refresh() { |
1564 |
storeCollapseState(); |
1565 |
fTreeViewer.getTree().setRedraw(false); |
1566 |
try { |
1567 |
fTreeViewer.refresh(); |
1568 |
TreeItem[] items = fTreeViewer.getTree().getItems(); |
1569 |
for (int i = 0; i < items.length; i++) { |
1570 |
boolean isExpanded = !fPreferenceStore.getBoolean(CONTEXT_COLLAPSE_PREF_ID |
1571 |
+ ((TemplateContextType) items[i].getData()).getId()); |
1572 |
if (isExpanded) |
1573 |
fTreeViewer.expandToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS); |
1574 |
else |
1575 |
fTreeViewer.collapseToLevel(items[i].getData(), AbstractTreeViewer.ALL_LEVELS); |
1576 |
} |
1577 |
} finally { |
1578 |
fTreeViewer.getTree().setRedraw(true); |
1579 |
} |
1580 |
} |
1581 |
|
1582 |
/** |
1583 |
* Get the document relative offset from the textwidget relative point |
1584 |
* |
1585 |
* @param document |
1586 |
* @param textWidget |
1587 |
* @param point |
1588 |
* @return the offset |
1589 |
* @throws BadLocationException |
1590 |
*/ |
1591 |
private int getOffset(IDocument document, StyledText textWidget, Point point) |
1592 |
throws BadLocationException { |
1593 |
int widgetCaret = fViewer.getTextWidget().getCaretOffset(); |
1594 |
if (fViewer instanceof ITextViewerExtension5) { |
1595 |
ITextViewerExtension5 ext = (ITextViewerExtension5) fViewer; |
1596 |
try { |
1597 |
return ext.widgetOffset2ModelOffset(textWidget.getOffsetAtLocation(point)); |
1598 |
} catch (IllegalArgumentException e) { |
1599 |
int docLineIndex = ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y)); |
1600 |
String lineDelimiter = document.getLineDelimiter(docLineIndex); |
1601 |
int delimLength = lineDelimiter == null ? 0 : lineDelimiter.length(); |
1602 |
return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) |
1603 |
- delimLength; |
1604 |
} |
1605 |
} |
1606 |
IRegion visible = fViewer.getVisibleRegion(); |
1607 |
return widgetCaret + visible.getOffset(); |
1608 |
} |
1609 |
} |