1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.panels.internal

File PanelClassDocumentInitializer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
12
3
1
104
50
4
0.33
4
3
1.33

Classes

Class Line # Actions
PanelClassDocumentInitializer 46 12 0% 4 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.panels.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.model.reference.LocalDocumentReference;
29    import org.xwiki.sheet.SheetBinder;
30    import org.xwiki.uiextension.internal.AbstractUIExtensionClassDocumentInitializer;
31   
32    import com.xpn.xwiki.doc.XWikiDocument;
33    import com.xpn.xwiki.objects.classes.BaseClass;
34    import com.xpn.xwiki.objects.classes.ListClass;
35    import com.xpn.xwiki.objects.classes.TextAreaClass.EditorType;
36   
37    /**
38    * Update XWiki.UIExtensionClass document with all required informations.
39    *
40    * @version $Id: 6640965128513008f3f90a83fd87af0c0f624442 $
41    * @since 9.8RC1
42    */
43    @Component
44    @Named(PanelClassDocumentInitializer.CLASS_REFERENCE_STRING)
45    @Singleton
 
46    public class PanelClassDocumentInitializer extends AbstractUIExtensionClassDocumentInitializer
47    {
48    /**
49    * The local reference of the class used to defined panels xobjects as a String.
50    */
51    public static final String CLASS_REFERENCE_STRING = "Panels.PanelClass";
52   
53    /**
54    * The name of the space containing the panel class.
55    */
56    public static final String CLASS_SPACE = "Panels";
57   
58    /**
59    * The local reference of the class used to defined panels xobjects.
60    */
61    public static final LocalDocumentReference CLASS_REFERENCE = new LocalDocumentReference(CLASS_SPACE, "PanelClass");
62   
63    /**
64    * Used to bind a class to a document sheet.
65    */
66    @Inject
67    @Named("class")
68    private SheetBinder classSheetBinder;
69   
70    /**
71    * Default constructor.
72    */
 
73  76 toggle public PanelClassDocumentInitializer()
74    {
75  76 super(CLASS_REFERENCE);
76    }
77   
 
78  115 toggle @Override
79    protected void createClass(BaseClass xclass)
80    {
81  115 xclass.addStaticListField("category", "Category", 1, false, "Information|Navigation|Tools|Administration|Other",
82    ListClass.DISPLAYTYPE_SELECT);
83  115 xclass.addTextAreaField("description", "Description", 40, 5, EditorType.TEXT);
84  115 xclass.addTextField("name", "Name", 40);
85  115 xclass.addStaticListField("type", "Panel type", 1, false, "view|edit", ListClass.DISPLAYTYPE_SELECT);
86   
87  115 super.createClass(xclass);
88    }
89   
 
90  115 toggle @Override
91    public boolean updateDocument(XWikiDocument document)
92    {
93  115 boolean needsUpdate = super.updateDocument(document);
94   
95    // Use PanelSheet to display documents having PanelClass objects if no other class sheet is specified.
96  115 if (this.classSheetBinder.getSheets(document).isEmpty()) {
97  36 String wikiName = document.getDocumentReference().getWikiReference().getName();
98  36 DocumentReference sheet = new DocumentReference(wikiName, CLASS_SPACE, "PanelSheet");
99  36 needsUpdate |= this.classSheetBinder.bind(document, sheet);
100    }
101   
102  115 return needsUpdate;
103    }
104    }