Coverage Report - org.trails.component.NewLink
 
Classes in this File Line Coverage Branch Coverage Complexity
NewLink
85% 
N/A 
2
 
 1  
 /*
 2  
  * Copyright 2004 Chris Nelson
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 7  
  * Unless required by applicable law or agreed to in writing,
 8  
  * software distributed under the License is distributed on an "AS IS" BASIS,
 9  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 10  
  * See the License for the specific language governing permissions and limitations under the License.
 11  
  */
 12  
 package org.trails.component;
 13  
 
 14  
 import java.lang.reflect.Constructor;
 15  
 
 16  
 import org.apache.tapestry.IRequestCycle;
 17  
 import org.trails.TrailsRuntimeException;
 18  
 import org.trails.page.EditPage;
 19  
 import org.trails.page.PageResolver;
 20  
 import org.trails.page.TrailsPage;
 21  
 
 22  
 /**
 23  
  * Render a link allowing a new entity of the parameterized type to be created.
 24  
  *
 25  
  * @author fus8882
 26  
  * @date Sep 29, 2004
 27  
  */
 28  4
 public abstract class NewLink extends AbstractTypeNavigationLink
 29  
 {
 30  1
         public static String SUFFIX = "Edit";
 31  
 
 32  
         public void click(IRequestCycle cycle)
 33  
         {
 34  
 
 35  2
                 PageResolver pageResolver = getPageResolver();
 36  2
                 EditPage page = (EditPage) pageResolver.resolvePage(cycle, getType(), TrailsPage.PageType.Edit);
 37  
 
 38  
                 try {
 39  2
                         Constructor constructor = getType().getDeclaredConstructor();
 40  2
                         constructor.setAccessible(true);
 41  2
                         page.setModel(constructor.newInstance());
 42  2
                         cycle.activate(page);
 43  0
                 } catch (Exception ex)
 44  
                 {
 45  0
                         throw new TrailsRuntimeException(ex, getType());
 46  
                 }
 47  2
         }
 48  
 
 49  
         /**
 50  
          * Get the text for the rendered link
 51  
          *
 52  
          * @return Full i18n text in the form "List Foobars"
 53  
          */
 54  
         public String getLinkText()
 55  
         {
 56  1
                 String name = getClassDescriptor().getDisplayName();
 57  1
                 return generateLinkText(name, "org.trails.component.newlink", "[TRAILS][ORG.TRAILS.COMPONENT.NEWLINK]");
 58  
         }
 59  
 }