lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / AddContextDialog.java
index dda5375e52be1fad8b529455e203bba801d37963..a560219f62c261b7903d87bf794bc524fa9c7e23 100644 (file)
@@ -1,12 +1,12 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
- * 
+ * Copyright (c) 2012, 2014 Ericsson
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors: 
+ *
+ * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
@@ -24,7 +24,7 @@ import org.eclipse.jface.viewers.ICheckStateListener;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
@@ -35,74 +35,67 @@ import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Shell;
 
 /**
- * <b><u>AddContextDialog</u></b>
  * <p>
  * Dialog box for collecting information about contexts to be added to channels/events.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class AddContextDialog extends Dialog implements IAddContextDialog  {
 
     // ------------------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------------------
-    
+
     /**
      * The icon file for this dialog box.
      */
-    public static final String ADD_CONTEXT_ICON_FILE = "icons/elcl16/add-context.gif"; //$NON-NLS-1$ 
+    public static final String ADD_CONTEXT_ICON_FILE = "icons/elcl16/add-context.gif"; //$NON-NLS-1$
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The dialog composite.
-     */
-    private Composite fDialogComposite;
+
     /**
      * A tree viewer for displaying and selection of available contexts.
      */
     private CheckboxTreeViewer fContextsViewer;
+
     /**
      * A Tree model for the checkbox tree viewer.
      */
-    private ContextModel fContextModel = new ContextModel();
+    private final ContextModel fContextModel = new ContextModel();
+
     /**
      * The contexts to add.
      */
-    private List<String> fSelectedContexts = new ArrayList<String>();
-    
+    private final List<String> fSelectedContexts = new ArrayList<>();
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
+
     /**
      * Constructor
      * @param shell - a shell for the display of the dialog
      */
     public AddContextDialog(Shell shell) {
         super(shell);
-        setShellStyle(SWT.RESIZE);
+        setShellStyle(SWT.RESIZE | getShellStyle());
     }
-    
+
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#setAvalibleContexts(java.util.List)
-     */
+
     @Override
     public void setAvalibleContexts(List<String> contexts) {
         fContextModel.setAvalibleContexts(contexts);
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#getContexts()
-     */
+
     @Override
     public List<String> getContexts() {
-        List<String> ret = new ArrayList<String>();
+        List<String> ret = new ArrayList<>();
         ret.addAll(fSelectedContexts);
         return ret;
     }
@@ -110,10 +103,7 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
-     */
+
     @Override
     protected void configureShell(Shell newShell) {
         super.configureShell(newShell);
@@ -121,54 +111,42 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
         newShell.setImage(Activator.getDefault().loadIcon(ADD_CONTEXT_ICON_FILE));
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected Control createDialogArea(Composite parent) {
 
         // Main dialog panel
-        fDialogComposite = new Composite(parent, SWT.NONE);
+        Composite dialogComposite = new Composite(parent, SWT.NONE);
         GridLayout layout = new GridLayout(1, true);
-        fDialogComposite.setLayout(layout);
-        fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+        dialogComposite.setLayout(layout);
+        dialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
 
         // Contexts list
-        Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        Group contextGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
         contextGroup.setText(Messages.TraceControl_AddContextAvailableContextsLabel);
         layout = new GridLayout(1, true);
         contextGroup.setLayout(layout);
         contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
-        
+
         fContextsViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
-        fContextsViewer.getTree().setToolTipText(Messages.TraceControl_AddContextAvailableContextsTooltip); 
+        fContextsViewer.getTree().setToolTipText(Messages.TraceControl_AddContextAvailableContextsTooltip);
 
         fContextsViewer.setContentProvider(new ContextsContentProvider());
         fContextsViewer.setLabelProvider(new ContextsLabelProvider());
         fContextsViewer.addCheckStateListener(new ContextCheckListener());
         fContextsViewer.setInput(fContextModel);
         fContextsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
-        
+
         getShell().setMinimumSize(new Point(500, 450));
-        
-        return fDialogComposite;
+
+        return dialogComposite;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected void createButtonsForButtonBar(Composite parent) {
         createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
         createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
-     */
     @Override
     protected void okPressed() {
         fSelectedContexts.clear();
@@ -180,18 +158,18 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
                 fSelectedContexts.add(component.getName());
             }
         }
-        
+
         // validation successful -> call super.okPressed()
         super.okPressed();
     }
-    
+
     // ------------------------------------------------------------------------
     // Helper classes and methods
     // ------------------------------------------------------------------------
     /**
      * Content provider for the contexts tree
      */
-    final public static class ContextsContentProvider implements ITreeContentProvider {
+    public static final class ContextsContentProvider implements ITreeContentProvider {
 
         @Override
         public void dispose() {
@@ -234,10 +212,10 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
     /**
      * Label provider for the contexts tree
      */
-    final public static class ContextsLabelProvider extends ColumnLabelProvider {
+    public static final class ContextsLabelProvider extends ColumnLabelProvider {
         @Override
         public String getText(Object element) {
-            
+
             if ((element != null) && (element instanceof IContextModelComponent)) {
                 return ((IContextModelComponent)element).getName();
             }
@@ -245,18 +223,18 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
             return "";//$NON-NLS-1$
         }
     }
-    
+
     /**
-     * Check state listener for the contexts tree. 
+     * Check state listener for the contexts tree.
      */
-    final public class ContextCheckListener implements ICheckStateListener {
+    public final class ContextCheckListener implements ICheckStateListener {
         @Override
         public void checkStateChanged(CheckStateChangedEvent event) {
           if (event.getChecked()) {
               if (event.getElement() instanceof AllContexts) {
                   fContextsViewer.setSubtreeChecked(event.getElement(), true);
-              } 
-          } else { 
+              }
+          } else {
               if (event.getElement() instanceof AllContexts) {
                   fContextsViewer.setSubtreeChecked(event.getElement(), false);
               } else {
@@ -272,21 +250,30 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
      */
     public static class ContextModel implements IContextModelComponent {
 
-        private AllContexts fAllContexts;
-        
+        private final AllContexts fAllContexts;
+
+        /**
+         * Constructor
+         */
         public ContextModel() {
             fAllContexts = new AllContexts(this);
         }
 
+        /**
+         * Sets the available contexts
+         *
+         * @param contexts
+         *            The contexts to set
+         */
         public void setAvalibleContexts(List<String> contexts) {
             fAllContexts.setAvalibleContexts(contexts);
         }
-        
+
         @Override
         public String getName() {
             return "root"; //$NON-NLS-1$
         }
-        
+
         @Override
         public Object getParent() {
             return null;
@@ -306,25 +293,37 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
     }
 
     /**
-     * Model element (to select/deselect) all contexts) for the context tree viewer 
+     * Model element (to select/deselect) all contexts) for the context tree viewer
      */
     public static class AllContexts implements IContextModelComponent {
         /**
          * The available list of contexts.
          */
         private List<Context> fAvailableContexts;
-        
-        private IContextModelComponent fParent;
 
+        private final IContextModelComponent fParent;
+
+        /**
+         * Constructor
+         *
+         * @param parent
+         *            The parent component
+         */
         public AllContexts(IContextModelComponent parent) {
             fParent = parent;
         }
-        
+
+        /**
+         * Sets the available contexts
+         *
+         * @param contexts
+         *            The contexts to set
+         */
         public void setAvalibleContexts(List<String> contexts) {
-            fAvailableContexts = new ArrayList<Context>();
+            fAvailableContexts = new ArrayList<>();
             if (contexts != null) {
                 for (Iterator<String> iterator = contexts.iterator(); iterator.hasNext();) {
-                    String name = (String) iterator.next();
+                    String name = iterator.next();
                     fAvailableContexts.add(new Context(this, name));
                 }
             }
@@ -334,17 +333,17 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
         public String getName() {
             return Messages.TraceControl_AddContextAllLabel;
         }
-        
+
         @Override
         public Object[] getChildren() {
             return fAvailableContexts.toArray();
         }
-        
+
         @Override
         public Object getParent() {
             return fParent;
         }
-        
+
         @Override
         public boolean hasChildren() {
             return true;
@@ -352,18 +351,26 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
     }
 
     /**
-     * Model element (the context) for the context tree viewer 
+     * Model element (the context) for the context tree viewer
      */
     public static class Context implements IContextModelComponent {
 
-        private String fContextName;
-        private IContextModelComponent fParent; 
-        
+        private final String fContextName;
+        private final IContextModelComponent fParent;
+
+        /**
+         * Constructor
+         *
+         * @param parent
+         *            The parent component
+         * @param name
+         *            The name of this context
+         */
         public Context(IContextModelComponent parent, String name) {
             fParent = parent;
             fContextName = name;
         }
-        
+
         @Override
         public String getName() {
             return fContextName;
@@ -386,12 +393,28 @@ public class AddContextDialog extends Dialog implements IAddContextDialog  {
     }
 
     /**
-     * Interface for the tree model used for the context tree viewer. 
+     * Interface for the tree model used for the context tree viewer.
      */
     public interface IContextModelComponent {
-        public String getName();
-        public Object getParent();
-        public Object[] getChildren();
-        public boolean hasChildren();
+
+        /**
+         * @return The name of this component
+         */
+        String getName();
+
+        /**
+         * @return The parent component
+         */
+        Object getParent();
+
+        /**
+         * @return The array of children of this component
+         */
+        Object[] getChildren();
+
+        /**
+         * @return If this component has children or not
+         */
+        boolean hasChildren();
     }
 }
This page took 0.029088 seconds and 5 git commands to generate.