Coverage Report - org.openpermis.editor.policy.view.AuthorityEditor
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorityEditor
0%
0/29
N/A
1
 
 1  
 /*
 2  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 3  
  * All rights reserved.
 4  
  * 
 5  
  * Licensed under the Open Permis License which accompanies this distribution, 
 6  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 7  
  */
 8  
 package org.openpermis.editor.policy.view;
 9  
 
 10  
 import java.net.URI;
 11  
 
 12  
 import javax.swing.JComponent;
 13  
 import javax.swing.JPanel;
 14  
 import javax.swing.JTextField;
 15  
 
 16  
 import org.jdesktop.application.Action;
 17  
 import org.jdesktop.application.ApplicationContext;
 18  
 import org.jdesktop.beansbinding.BeanProperty;
 19  
 import org.jdesktop.beansbinding.Binding;
 20  
 import org.jdesktop.beansbinding.BindingGroup;
 21  
 import org.jdesktop.beansbinding.Bindings;
 22  
 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
 23  
 import org.slf4j.Logger;
 24  
 import org.slf4j.LoggerFactory;
 25  
 
 26  
 import com.jgoodies.forms.layout.CellConstraints;
 27  
 import com.jgoodies.forms.layout.FormLayout;
 28  
 
 29  
 import org.openpermis.editor.policy.adapter.AdapterTrader;
 30  
 import org.openpermis.editor.policy.gui.ActionForwarder;
 31  
 import org.openpermis.editor.policy.gui.binding.ErrorBindingListener;
 32  
 import org.openpermis.editor.policy.gui.binding.UriConverter;
 33  
 import org.openpermis.editor.policy.presenter.AuthorityPresenter;
 34  
 
 35  
 /**
 36  
  * Tool view that displays the content of an {@link AuthorityPresenter}.
 37  
  * @since 0.3.0
 38  
  */
 39  
 public class AuthorityEditor
 40  
         extends AbstractEditor<AuthorityPresenter>
 41  
 {
 42  
 
 43  
         //---- Static
 44  
 
 45  
         /**
 46  
          * @since 0.3.0
 47  
          */
 48  0
         private static final Logger LOGGER =
 49  
                 LoggerFactory.getLogger(AuthorityEditor.class);
 50  
 
 51  
         //---- State
 52  
 
 53  
         /**
 54  
          * @since 0.3.0
 55  
          */
 56  
         private JTextField identity;
 57  
 
 58  
         //---- Constructors
 59  
 
 60  
         /**
 61  
          * Creates an {@link AuthorityEditor}.
 62  
          * @param context the application context used to lookup the action and resource map.
 63  
          * @param presenter the presenter of this view.
 64  
          * @since 0.3.0
 65  
          */
 66  
         public AuthorityEditor (
 67  
                 ApplicationContext context, AdapterTrader trader, AuthorityPresenter presenter
 68  
         ) {
 69  0
                 super(context, trader, presenter);
 70  0
         }
 71  
 
 72  
         //---- Actions
 73  
 
 74  
         /**
 75  
          * @since 0.3.0
 76  
          */
 77  
         @Action
 78  
         public void addSubDomain () {
 79  0
                 LOGGER.debug("addSubDomain");
 80  0
         }
 81  
 
 82  
         /**
 83  
          * @since 0.3.0
 84  
          */
 85  
         @Action
 86  
         public void removeSubDomain () {
 87  0
                 LOGGER.debug("removeSubDomain");
 88  0
         }
 89  
 
 90  
         /**
 91  
          * @since 0.3.0
 92  
          */
 93  
         @Action
 94  
         public void editSubDomain () {
 95  0
                 LOGGER.debug("editSubDomain");
 96  0
         }
 97  
 
 98  
         /**
 99  
          * @since 0.3.0
 100  
          */
 101  
         @Action
 102  
         public void close () {
 103  0
                 LOGGER.debug("close");
 104  0
                 closeView(this, false);
 105  0
         }
 106  
 
 107  
         //---- AbstractEditor
 108  
 
 109  
         /**
 110  
          * @since 0.3.0
 111  
          */
 112  
         @Override
 113  
         protected void bind (BindingGroup bindings) {
 114  0
                 final Binding<AuthorityPresenter, URI, JTextField, String> identityBinding =
 115  
                         Bindings.createAutoBinding(
 116  
                                 UpdateStrategy.READ_WRITE,
 117  
                                 getPresenter(),
 118  
                                 BeanProperty.<AuthorityPresenter, URI>create("identity"),
 119  
                                 this.identity,
 120  
                                 BeanProperty.<JTextField, String>create("text_ON_ACTION_OR_FOCUS_LOST")
 121  
                         );
 122  0
                 identityBinding.setConverter(new UriConverter());
 123  0
                 identityBinding.addBindingListener(
 124  
                         new ErrorBindingListener(
 125  
                                 this,
 126  
                                 getResourceMap(),
 127  
                                 this.identity,
 128  
                                 "identityError"
 129  
                         )
 130  
                 );
 131  0
                 bindings.addBinding(identityBinding);
 132  0
         }
 133  
 
 134  
         //---- View
 135  
 
 136  
         /**
 137  
          * @since 0.3.0
 138  
          */
 139  
         private JComponent headerIdentity () {
 140  0
                 final FormLayout layout = new FormLayout(
 141  
                         "pref, 2dlu, fill:50dlu:grow, 2dlu, pref",
 142  
                         "pref"
 143  
                 );
 144  0
                 final JPanel panel = new JPanel();
 145  0
                 panel.setLayout(layout);
 146  0
                 final CellConstraints cc = new CellConstraints();
 147  0
                 panel.add(label("identity"), cc.xy(1, 1));
 148  0
                 panel.add(this.identity, cc.xy(3, 1));
 149  0
                 return panel;
 150  
         }
 151  
 
 152  
         /**
 153  
          * @since 0.3.0
 154  
          */
 155  
         public void fillContentPane (JPanel panel) {
 156  0
                 final CellConstraints cc = new CellConstraints();
 157  0
                 this.identity = new JTextField();
 158  0
                 panel.add(headerIdentity(), cc.xy(2, 2));
 159  
 
 160  
                 // note this handler to close the view, when field was changed
 161  0
                 this.identity.addActionListener(new ActionForwarder(getActionMap().get("close")));
 162  
 
 163  0
         }
 164  
 
 165  
 }