Coverage Report - org.openpermis.editor.policy.view.DomainEditor
 
Classes in this File Line Coverage Branch Coverage Complexity
DomainEditor
0%
0/44
0%
0/4
1.2
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.view;
 11  
 
 12  
 import java.awt.Component;
 13  
 import java.awt.Container;
 14  
 import java.net.URI;
 15  
 
 16  
 import javax.swing.JComponent;
 17  
 import javax.swing.JList;
 18  
 import javax.swing.JPanel;
 19  
 import javax.swing.JScrollPane;
 20  
 import javax.swing.JTextField;
 21  
 
 22  
 import org.jdesktop.application.Action;
 23  
 import org.jdesktop.application.ApplicationContext;
 24  
 import org.jdesktop.beansbinding.BeanProperty;
 25  
 import org.jdesktop.beansbinding.Binding;
 26  
 import org.jdesktop.beansbinding.BindingGroup;
 27  
 import org.jdesktop.beansbinding.Bindings;
 28  
 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
 29  
 import org.slf4j.Logger;
 30  
 import org.slf4j.LoggerFactory;
 31  
 
 32  
 import com.jgoodies.forms.layout.CellConstraints;
 33  
 import com.jgoodies.forms.layout.FormLayout;
 34  
 
 35  
 import org.openpermis.editor.policy.adapter.AdapterTrader;
 36  
 import org.openpermis.editor.policy.gui.ActionForwarder;
 37  
 import org.openpermis.editor.policy.gui.binding.ErrorBindingListener;
 38  
 import org.openpermis.editor.policy.gui.binding.UriConverter;
 39  
 import org.openpermis.editor.policy.presenter.DomainPresenter;
 40  
 
 41  
 /**
 42  
  * Tool view that displays all target access rules in a policy.
 43  
  * @since 0.1.0
 44  
  */
 45  
 public class DomainEditor
 46  
         extends AbstractEditor<DomainPresenter>
 47  
 {
 48  
 
 49  
         //---- Static
 50  
 
 51  
         /**
 52  
          * The logger object of this class.
 53  
          * @since 0.1.0
 54  
          */
 55  0
         private static final Logger LOGGER =
 56  
                 LoggerFactory.getLogger(DomainEditor.class);
 57  
 
 58  
         //---- State
 59  
 
 60  
         /**
 61  
          * The identity URI of the resource domain.
 62  
          * @since 0.1.0
 63  
          */
 64  
         private JTextField identity;
 65  
 
 66  
         //---- Constructors
 67  
 
 68  
         /**
 69  
          * Creates a domain editor.
 70  
          * @param context the application context used to lookup the action and resource map.
 71  
          * @param presenter the presenter of this view.
 72  
          * @since 0.1.0
 73  
          */
 74  
         public DomainEditor (
 75  
                 ApplicationContext context, AdapterTrader trader, DomainPresenter presenter
 76  
         ) {
 77  0
                 super(context, trader, presenter);
 78  0
         }
 79  
 
 80  
         //---- Actions
 81  
 
 82  
         /**
 83  
          * @since 0.1.0
 84  
          */
 85  
         @Action
 86  
         public void addSubDomain () {
 87  0
                 LOGGER.debug("addSubDomain");
 88  0
         }
 89  
 
 90  
         /**
 91  
          * @since 0.1.0
 92  
          */
 93  
         @Action
 94  
         public void removeSubDomain () {
 95  0
                 LOGGER.debug("removeSubDomain");
 96  0
         }
 97  
 
 98  
         /**
 99  
          * @since 0.1.0
 100  
          */
 101  
         @Action
 102  
         public void editSubDomain () {
 103  0
                 LOGGER.debug("editSubDomain");
 104  0
         }
 105  
 
 106  
         /**
 107  
          * @since 0.1.0
 108  
          */
 109  
         @Action
 110  
         public void close () {
 111  0
                 LOGGER.debug("close");
 112  0
                 closeView(this, false);
 113  0
         }
 114  
 
 115  
         //---- AbstractEditor
 116  
 
 117  
         /**
 118  
          * @since 0.1.0
 119  
          */
 120  
         @Override
 121  
         protected void bind (BindingGroup bindings) {
 122  0
                 final Binding<DomainPresenter, URI, JTextField, String> identityBinding =
 123  
                         Bindings.createAutoBinding(
 124  
                                 UpdateStrategy.READ_WRITE,
 125  
                                 getPresenter(),
 126  
                                 BeanProperty.<DomainPresenter, URI>create("identity"),
 127  
                                 this.identity,
 128  
                                 BeanProperty.<JTextField, String>create("text_ON_ACTION_OR_FOCUS_LOST")
 129  
                         );
 130  0
                 identityBinding.setConverter(new UriConverter());
 131  0
                 identityBinding.addBindingListener(
 132  
                         new ErrorBindingListener(
 133  
                                 this,
 134  
                                 getResourceMap(),
 135  
                                 this.identity,
 136  
                                 "identityError"
 137  
                         )
 138  
                 );
 139  0
                 bindings.addBinding(identityBinding);
 140  0
         }
 141  
 
 142  
         //---- View
 143  
 
 144  
         /**
 145  
          * @since 0.1.0
 146  
          */
 147  
         private JComponent headerIdentity () {
 148  0
                 final FormLayout layout = new FormLayout(
 149  
                         "pref, 2dlu, fill:50dlu:grow, 2dlu, pref",
 150  
                         "pref"
 151  
                 );
 152  0
                 final JPanel panel = new JPanel();
 153  0
                 panel.setLayout(layout);
 154  0
                 final CellConstraints cc = new CellConstraints();
 155  0
                 panel.add(label("identity"), cc.xy(1, 1));
 156  0
                 panel.add(this.identity, cc.xy(3, 1));
 157  0
                 return panel;
 158  
         }
 159  
 
 160  
         private void disable (Component parent) {
 161  0
                 parent.setEnabled(false);
 162  0
                 if (parent instanceof Container) {
 163  0
                         for (Component child : ((Container) parent).getComponents()) {
 164  0
                                 disable(child);
 165  
                         }
 166  
                 }
 167  0
         }
 168  
 
 169  
         /**
 170  
          * @since 0.1.0
 171  
          */
 172  
         private JComponent list (String label, String toolBar) {
 173  0
                 final FormLayout layout = new FormLayout(
 174  
                         "pref, fill:pref:grow",
 175  
                         "pref, fill:pref:grow"
 176  
                 );
 177  0
                 final JPanel panel = new JPanel();
 178  0
                 panel.setLayout(layout);
 179  0
                 final CellConstraints cc = new CellConstraints();
 180  0
                 panel.add(label(label), cc.xy(1, 1));
 181  0
                 panel.add(toolBar(toolBar), cc.xy(2, 1));
 182  0
                 panel.add(new JScrollPane(new JList()), cc.xyw(1, 2, 2));
 183  
                 // Disable because this is not implemented yet.
 184  0
                 disable(panel);
 185  0
                 return panel;
 186  
         }
 187  
 
 188  
         /**
 189  
          * @since 0.1.0
 190  
          */
 191  
         public void fillContentPane (JPanel panel) {
 192  0
                 final CellConstraints cc = new CellConstraints();
 193  0
                 this.identity = new JTextField();
 194  0
                 panel.add(headerIdentity(), cc.xy(2, 2));
 195  0
                 panel.add(list("subDomains", "subDomainsToolBar"), cc.xy(2, 4));
 196  
 
 197  
                 // note this handler to close the view, when field was changed
 198  0
                 this.identity.addActionListener(new ActionForwarder(getActionMap().get("close")));
 199  
 
 200  0
         }
 201  
 
 202  
 }