Skip to content

Commit b081f5e

Browse files
OleksiiMalikovabsap
authored andcommitted
Obj log improvements, added confirmation dialog before pull action (#139)
* added context menu in object log with copy feature, added confirmation dialog before pull action * increased spotbugs version
1 parent b86f547 commit b081f5e

File tree

5 files changed

+95
-46
lines changed

5 files changed

+95
-46
lines changed

org.abapgit.adt.ui/src/org/abapgit/adt/ui/dialogs/AbapGitDialogObjLog.java

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,32 @@
55
import org.abapgit.adt.backend.IObject;
66
import org.abapgit.adt.backend.IRepository;
77
import 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;
812
import org.eclipse.jface.dialogs.IMessageProvider;
913
import org.eclipse.jface.dialogs.TitleAreaDialog;
1014
import org.eclipse.jface.layout.GridDataFactory;
1115
import org.eclipse.jface.layout.RowLayoutFactory;
1216
import org.eclipse.jface.viewers.ArrayContentProvider;
1317
import org.eclipse.jface.viewers.ColumnLabelProvider;
18+
import org.eclipse.jface.viewers.IStructuredSelection;
1419
import org.eclipse.jface.viewers.ITreeContentProvider;
1520
import org.eclipse.jface.viewers.TreeViewer;
1621
import org.eclipse.jface.viewers.TreeViewerColumn;
1722
import org.eclipse.jface.viewers.Viewer;
1823
import org.eclipse.swt.SWT;
24+
import org.eclipse.swt.dnd.Clipboard;
25+
import org.eclipse.swt.dnd.TextTransfer;
1926
import org.eclipse.swt.events.SelectionAdapter;
2027
import org.eclipse.swt.events.SelectionEvent;
2128
import org.eclipse.swt.graphics.Image;
2229
import org.eclipse.swt.layout.GridData;
2330
import org.eclipse.swt.layout.GridLayout;
2431
import org.eclipse.swt.widgets.Composite;
2532
import org.eclipse.swt.widgets.Control;
33+
import org.eclipse.swt.widgets.Menu;
2634
import org.eclipse.swt.widgets.Shell;
2735
import org.eclipse.swt.widgets.ToolBar;
2836
import 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+
392424
class ObjectTreeContentProvider implements ITreeContentProvider {
393425

394426
public String filter;

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/i18n/Messages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class Messages extends NLS {
3838
public static String AbapGitView_repos_not_loaded;
3939
public static String AbapGitView_task_fetch_repos;
4040
public static String AbapGitView_task_fetch_repos_error;
41+
public static String AbapGitView_ConfDialog_title;
42+
public static String AbapGitView_ConfDialog_MsgText;
43+
public static String AbapGitView_ConfDialog_Btn_confirm;
44+
public static String AbapGitView_ConfDialog_Btn_cancel;
4145
public static String AbapGitWizard_task_cloning_repository;
4246
public static String AbapGitWizard_task_pulling_repository;
4347
public static String AbapGitWizard_title;

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/i18n/messages.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ AbapGitView_repos_in_project=abapGit repositories in project {0}\:
3232
AbapGitView_repos_not_loaded=abapGit repositories in project {0} are not loaded, yet. Press 'Refresh' to load the repository list.
3333
AbapGitView_task_fetch_repos=Fetching abapGit Repositories
3434
AbapGitView_task_fetch_repos_error=Error fetching abapGit Repositories
35+
AbapGitView_ConfDialog_title=Confirm pull action
36+
AbapGitView_ConfDialog_MsgText=Attention: Local changes will be overwritten, please confirm by clicking on Continue.
37+
AbapGitView_ConfDialog_Btn_confirm=Continue
38+
AbapGitView_ConfDialog_Btn_cancel=Cancel
3539
AbapGitWizard_task_cloning_repository=Linking repository...
3640
AbapGitWizard_task_pulling_repository=Pulling from repository...
3741
AbapGitWizard_title=Link abapGit Repository

org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/views/AbapGitView.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,16 @@ public void run() {
492492

493493
WizardDialog wizardDialog = new WizardDialog(AbapGitView.this.viewer.getControl().getShell(),
494494
new AbapGitWizardPull(AbapGitView.this.lastProject, this.selRepo, allRepositories));
495-
wizardDialog.open();
495+
496+
// customized MessageDialog with configured buttons
497+
MessageDialog dialog = new MessageDialog(getSite().getShell(), Messages.AbapGitView_ConfDialog_title, null,
498+
Messages.AbapGitView_ConfDialog_MsgText,
499+
MessageDialog.CONFIRM,
500+
new String[] { Messages.AbapGitView_ConfDialog_Btn_confirm, Messages.AbapGitView_ConfDialog_Btn_cancel }, 0);
501+
int confirmResult = dialog.open();
502+
if (confirmResult == 0) {
503+
wizardDialog.open();
504+
}
496505

497506
}
498507

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@
9797
<plugin>
9898
<groupId>com.github.spotbugs</groupId>
9999
<artifactId>spotbugs-maven-plugin</artifactId>
100-
<version>3.1.3</version>
100+
<version>3.1.11</version>
101101
<dependencies>
102102
<dependency>
103103
<groupId>com.github.spotbugs</groupId>
104104
<artifactId>spotbugs</artifactId>
105-
<version>3.1.3</version>
105+
<version>3.1.12</version>
106106
</dependency>
107107
</dependencies>
108108
<executions>

0 commit comments

Comments
 (0)