55import org .abapgit .adt .backend .IObject ;
66import org .abapgit .adt .backend .IRepository ;
77import org .abapgit .adt .ui .internal .i18n .Messages ;
8+ import org .eclipse .jface .action .Action ;
9+ import org .eclipse .jface .action .IMenuListener ;
10+ import org .eclipse .jface .action .IMenuManager ;
11+ import org .eclipse .jface .action .MenuManager ;
812import org .eclipse .jface .dialogs .IMessageProvider ;
913import org .eclipse .jface .dialogs .TitleAreaDialog ;
1014import org .eclipse .jface .layout .GridDataFactory ;
1115import org .eclipse .jface .layout .RowLayoutFactory ;
1216import org .eclipse .jface .viewers .ArrayContentProvider ;
1317import org .eclipse .jface .viewers .ColumnLabelProvider ;
18+ import org .eclipse .jface .viewers .IStructuredSelection ;
1419import org .eclipse .jface .viewers .ITreeContentProvider ;
1520import org .eclipse .jface .viewers .TreeViewer ;
1621import org .eclipse .jface .viewers .TreeViewerColumn ;
1722import org .eclipse .jface .viewers .Viewer ;
1823import org .eclipse .swt .SWT ;
24+ import org .eclipse .swt .dnd .Clipboard ;
25+ import org .eclipse .swt .dnd .TextTransfer ;
1926import org .eclipse .swt .events .SelectionAdapter ;
2027import org .eclipse .swt .events .SelectionEvent ;
2128import org .eclipse .swt .graphics .Image ;
2229import org .eclipse .swt .layout .GridData ;
2330import org .eclipse .swt .layout .GridLayout ;
2431import org .eclipse .swt .widgets .Composite ;
2532import org .eclipse .swt .widgets .Control ;
33+ import org .eclipse .swt .widgets .Menu ;
2634import org .eclipse .swt .widgets .Shell ;
2735import org .eclipse .swt .widgets .ToolBar ;
2836import org .eclipse .swt .widgets .ToolItem ;
@@ -46,7 +54,7 @@ public class AbapGitDialogObjLog extends TitleAreaDialog {
4654 private final Image errorImage ;
4755 private final Image successImage ;
4856 private final Image infoImage ;
49- // private final Image blankImage ;
57+ private Action actionCopy ;
5058 private final static String ERROR_FLAG = "E" ; //$NON-NLS-1$
5159 private final static String WARNING_FLAG = "W" ; //$NON-NLS-1$
5260 private final static String INFO_FLAG = "I" ; //$NON-NLS-1$
@@ -62,7 +70,6 @@ public AbapGitDialogObjLog(Shell parentShell, List<IObject> pullObjects, IReposi
6270 this .errorImage = AbstractUIPlugin .imageDescriptorFromPlugin ("org.eclipse.ui" , "icons/full/obj16/error_tsk.png" ).createImage (); //$NON-NLS-1$ //$NON-NLS-2$
6371 this .successImage = AbstractUIPlugin .imageDescriptorFromPlugin ("org.eclipse.ui" , "icons/full/obj16/activity.png" ).createImage (); //$NON-NLS-1$//$NON-NLS-2$
6472 this .infoImage = AbstractUIPlugin .imageDescriptorFromPlugin ("org.eclipse.ui" , "icons/full/obj16/info_tsk.png" ).createImage (); //$NON-NLS-1$ //$NON-NLS-2$
65- // this.blankImage = AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", "icons/full/obj16/blank.png").createImage(); //$NON-NLS-1$ //$NON-NLS-2$
6673
6774 }
6875
@@ -120,7 +127,6 @@ protected boolean isParentMatch(Viewer viewer, Object element) {
120127 };
121128
122129 ToolItem expandAllToolItem = new ToolItem (bar , SWT .PUSH | SWT .FLAT );
123- // expandAllToolItem.setText(Messages.AbapGitDialogPageObjLog_filter_expand_all);
124130 expandAllToolItem .setToolTipText (Messages .AbapGitDialogPageObjLog_filter_expand_all_tooltip );
125131 expandAllToolItem
126132 .setImage (AbstractUIPlugin .imageDescriptorFromPlugin ("org.eclipse.ui" , "icons/full/elcl16/expandall.png" ).createImage ()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -134,7 +140,6 @@ public void widgetSelected(SelectionEvent e) {
134140 });
135141
136142 ToolItem collapseAllToolItem = new ToolItem (bar , SWT .PUSH | SWT .FLAT );
137- // collapseAllToolItem.setText(Messages.AbapGitDialogPageObjLog_filter_collapse_all);
138143 collapseAllToolItem .setToolTipText (Messages .AbapGitDialogPageObjLog_filter_collapse_all_tooltip );
139144 collapseAllToolItem .setImage (PlatformUI .getWorkbench ().getSharedImages ().getImage (ISharedImages .IMG_ELCL_COLLAPSEALL ));
140145 collapseAllToolItem .addSelectionListener (new SelectionAdapter () {
@@ -147,7 +152,6 @@ public void widgetSelected(SelectionEvent e) {
147152 });
148153
149154 ToolItem filterErrorToolItem = new ToolItem (bar , SWT .PUSH | SWT .FLAT );
150- // filterErrorToolItem.setText(Messages.AbapGitDialogPageObjLog_filter_error);
151155 filterErrorToolItem .setToolTipText (Messages .AbapGitDialogPageObjLog_filter_error_tooltip );
152156 filterErrorToolItem .setImage (this .errorImage );
153157 filterErrorToolItem .addSelectionListener (new SelectionAdapter () {
@@ -159,7 +163,6 @@ public void widgetSelected(SelectionEvent e) {
159163 });
160164
161165 ToolItem filterWarningToolItem = new ToolItem (bar , SWT .PUSH | SWT .FLAT );
162- // filterWarningToolItem.setText(Messages.AbapGitDialogPageObjLog_filter_warning);
163166 filterWarningToolItem .setToolTipText (Messages .AbapGitDialogPageObjLog_filter_warning_tooltip );
164167 filterWarningToolItem .setImage (this .warningImage );
165168 filterWarningToolItem .addSelectionListener (new SelectionAdapter () {
@@ -171,7 +174,6 @@ public void widgetSelected(SelectionEvent e) {
171174 });
172175
173176 ToolItem filterAllToolItem = new ToolItem (bar , SWT .PUSH | SWT .FLAT );
174- // filterAllToolItem.setText(Messages.AbapGitDialogPageObjLog_filter_all);
175177 filterAllToolItem .setToolTipText (Messages .AbapGitDialogPageObjLog_filter_all_tooltip );
176178 filterAllToolItem .setImage (PlatformUI .getWorkbench ().getSharedImages ().getImage (ISharedImages .IMG_OBJ_FILE ));
177179 filterAllToolItem .addSelectionListener (new SelectionAdapter () {
@@ -199,6 +201,10 @@ public void widgetSelected(SelectionEvent e) {
199201
200202 this .abapObjTable .setInput (this .abapObjects );
201203
204+
205+ makeActions ();
206+ // hookContextMenu();
207+
202208 return parent ;
203209 }
204210
@@ -227,42 +233,7 @@ public String getText(Object element) {
227233 return result ;
228234 }
229235 });
230-
231- // createTableViewerColumn(Messages.AbapGitDialogImport_column_obj_status, 50).setLabelProvider(new ColumnLabelProvider() {
232- // @Override
233- // public String getText(Object element) {
234- // return null;
235- // }
236- //
237- // @Override
238- // public Image getImage(Object element) {
239- // IObject p = (IObject) element;
240- // String objStatus = p.getObjStatus();
241- //
242- // if (objStatus != null && objStatus.equals("W")) { //$NON-NLS-1$
243- // return AbapGitDialogObjLog.this.warningImage;
244- // }
245- //
246- // if (objStatus != null && objStatus.equals("E")) { //$NON-NLS-1$
247- // return AbapGitDialogObjLog.this.errorImage;
248- // }
249- //
250- // if (objStatus != null && objStatus.equals("A")) { //$NON-NLS-1$
251- // return AbapGitDialogObjLog.this.stopImage;
252- // }
253- //
254- // if (objStatus != null && objStatus.equals("S")) { //$NON-NLS-1$
255- // return AbapGitDialogObjLog.this.successImage;
256- // }
257- //
258- // if (objStatus != null && objStatus.equals("I")) { //$NON-NLS-1$
259- // return AbapGitDialogObjLog.this.infoImage;
260- // }
261- //
262- // return AbapGitDialogObjLog.this.blankImage;
263- // }
264- //
265- // });
236+ hookContextMenu (this .abapObjTable );
266237
267238 createTableViewerColumn (Messages .AbapGitDialogImport_column_msg_type , 200 ).setLabelProvider (new ColumnLabelProvider () {
268239 @ Override
@@ -377,6 +348,45 @@ private TreeViewerColumn createTableViewerColumn(String title, int bound) {
377348 return viewerColumn ;
378349 }
379350
351+ private void hookContextMenu (TreeViewer treeViewer ) {
352+ final MenuManager menuManager = new MenuManager ("#PopupMenu" ); //$NON-NLS-1$
353+ menuManager .setRemoveAllWhenShown (true );
354+
355+ Menu menu = menuManager .createContextMenu (treeViewer .getTree ());
356+ treeViewer .getTree ().setMenu (menu );
357+
358+ menuManager .addMenuListener (new IMenuListener () {
359+ @ Override
360+ public void menuAboutToShow (IMenuManager manager ) {
361+ fillContextMenu (manager );
362+ }
363+
364+ private void fillContextMenu (IMenuManager manager ) {
365+
366+ IStructuredSelection selection = (IStructuredSelection ) AbapGitDialogObjLog .this .tree .getViewer ().getSelection ();
367+ if (selection .size () != 1 ) {
368+ return ;
369+ }
370+ menuManager .add (AbapGitDialogObjLog .this .actionCopy );
371+
372+ }
373+ });
374+
375+ }
376+
377+ private void makeActions () {
378+ this .actionCopy = new Action () {
379+ public void run () {
380+ copy ();
381+ }
382+ };
383+ this .actionCopy .setText (Messages .AbapGitView_action_copy );
384+ this .actionCopy .setToolTipText (Messages .AbapGitView_action_copy );
385+
386+ this .actionCopy .setAccelerator (SWT .ALT | 'C' );
387+ this .actionCopy .setImageDescriptor (PlatformUI .getWorkbench ().getSharedImages ().getImageDescriptor (ISharedImages .IMG_TOOL_COPY ));
388+ }
389+
380390 @ Override
381391 protected boolean isResizable () {
382392 return true ;
@@ -387,8 +397,30 @@ protected void okPressed() {
387397 super .okPressed ();
388398 }
389399
400+ /**
401+ * Copies the current selection to the clipboard.
402+ *
403+ * @param table
404+ * the data source
405+ */
406+ protected void copy () {
407+
408+ Object firstElement = AbapGitDialogObjLog .this .tree .getViewer ().getStructuredSelection ().getFirstElement ();
409+ final StringBuilder data = new StringBuilder ();
410+
411+ IObject selectedAbapObj = (IObject ) firstElement ;
412+ data .append (selectedAbapObj .getObjName () + " | " + selectedAbapObj .getObjType () + " | " + selectedAbapObj .getMsgType () + " | " //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
413+ + selectedAbapObj .getMsgText ());
414+
415+ final Clipboard clipboard = new Clipboard (AbapGitDialogObjLog .this .tree .getViewer ().getControl ().getDisplay ());
416+ clipboard .setContents (new String [] { data .toString () }, new TextTransfer [] { TextTransfer .getInstance () });
417+ clipboard .dispose ();
418+
419+ }
420+
390421}
391422
423+
392424class ObjectTreeContentProvider implements ITreeContentProvider {
393425
394426 public String filter ;
0 commit comments