OpenInspectSessionsHandler : handler for opening the inspect session dialog
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / sessions / InspectSessionsDialog.java
index 3206427e6e0fa66162be4b786c9fcdbbaf823c13..82db7c539083a2a6d45bffcd11bee736002f9c3f 100644 (file)
@@ -21,8 +21,13 @@ import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Dialog;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
@@ -47,7 +52,7 @@ public class InspectSessionsDialog extends Dialog {
 
     protected Object result;
     protected Shell shlInspectSessions;
-    private Text text;
+    private Text txtDebugInfo;
     private Label lblDebugInformation;
 
     private final Cache cdmlibModelCache;
@@ -55,6 +60,10 @@ public class InspectSessionsDialog extends Dialog {
     private final ICdmEntitySession activeSession;
 
     private TreeViewer treeViewer;
+    private Button btnClose;
+    EntityCacherDebugResult ecdr;
+    private SashForm sashForm;
+    private Composite compositeDebug;
     /**
      * Create the dialog.
      * @param parent
@@ -62,9 +71,10 @@ public class InspectSessionsDialog extends Dialog {
      */
     public InspectSessionsDialog(Shell parent, int style) {
         super(parent, style);
-        setText("SWT Dialog");
+        setText("Inspect Active Session");
         cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
         activeSession = CdmStore.getCurrentSessionManager().getActiveSession();
+        ecdr = activeSession.debug();
     }
 
     /**
@@ -72,7 +82,9 @@ public class InspectSessionsDialog extends Dialog {
      * @return the result
      */
     public Object open() {
+
         createContents();
+        setDebugInfoText();
         treeViewer.setContentProvider(new SessionsTreeContentProvider());
         treeViewer.setLabelProvider(new SessionsTreeLabelProvider());
         treeViewer.setInput(getRootElements());
@@ -91,27 +103,51 @@ public class InspectSessionsDialog extends Dialog {
      * Create contents of the dialog.
      */
     private void createContents() {
-        shlInspectSessions = new Shell(getParent(), getStyle());
-        shlInspectSessions.setSize(641, 529);
+        shlInspectSessions = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE);
+        shlInspectSessions.setSize(641, 631);
         shlInspectSessions.setText("Inspect Sessions");
         shlInspectSessions.setLayout(new GridLayout(1, false));
 
-        TreeViewer treeViewer = new TreeViewer(shlInspectSessions, SWT.BORDER);
-        Tree tree = treeViewer.getTree();
-        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+        sashForm = new SashForm(shlInspectSessions, SWT.VERTICAL);
+        sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+                treeViewer = new TreeViewer(sashForm, SWT.BORDER);
+                Tree tree = treeViewer.getTree();
 
-        lblDebugInformation = new Label(shlInspectSessions, SWT.NONE);
-        lblDebugInformation.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
-        lblDebugInformation.setText("Debug Information :");
+                                compositeDebug = new Composite(sashForm, SWT.NONE);
+                                                        compositeDebug.setLayout(new GridLayout(1, false));
 
-        text = new Text(shlInspectSessions, SWT.BORDER);
-        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+                                                        lblDebugInformation = new Label(compositeDebug, SWT.NONE);
+                                                        lblDebugInformation.setAlignment(SWT.CENTER);
+                                                        lblDebugInformation.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
+                                                        lblDebugInformation.setFont(SWTResourceManager.getFont("Ubuntu", 10, SWT.NORMAL));
+                                                        lblDebugInformation.setText("Debug Information");
+
+                                                                                        txtDebugInfo = new Text(compositeDebug, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
+                                                                                        txtDebugInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+                                sashForm.setWeights(new int[] {338, 184});
+
+        btnClose = new Button(shlInspectSessions, SWT.NONE);
+        btnClose.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                shlInspectSessions.dispose();
+            }
+        });
+        GridData gd_btnClose = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+        gd_btnClose.widthHint = 70;
+        btnClose.setLayoutData(gd_btnClose);
+        btnClose.setText("Close");
 
     }
 
+    private void setDebugInfoText() {
+        txtDebugInfo.setText(ecdr.toString());
+    }
     private CdmEntityInfo[] getRootElements() {
-        EntityCacherDebugResult ecdr = activeSession.debug();
-        return (CdmEntityInfo[]) ecdr.getRootElements().toArray();
+
+        List<CdmEntityInfo> rootElemnts = ecdr.getRootElements();
+        return rootElemnts.toArray(new CdmEntityInfo[rootElemnts.size()]);
     }
 
     class SessionsTreeContentProvider implements ITreeContentProvider {