MVCGroup.java
001 /*
002  * Copyright 2008-2016 the original author or authors.
003  *
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  *
008  *     http://www.apache.org/licenses/LICENSE-2.0
009  *
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 package griffon.core.mvc;
017 
018 import griffon.core.Context;
019 import griffon.core.artifact.GriffonController;
020 import griffon.core.artifact.GriffonModel;
021 import griffon.core.artifact.GriffonView;
022 
023 import javax.annotation.Nonnull;
024 import javax.annotation.Nullable;
025 import java.util.Map;
026 
027 /**
028  * Defines an MVC group and its contents
029  *
030  @author Andres Almiray
031  @since 2.0.0
032  */
033 public interface MVCGroup extends MVCHandler {
034     /**
035      * Returns the configuration of this group.
036      *
037      @return the configuration used to instantiate this group.
038      */
039     @Nonnull
040     MVCGroupConfiguration getConfiguration();
041 
042     /**
043      * Returns the type of this group as set in the application's configuration.
044      *
045      @return the type of the group
046      */
047     @Nonnull
048     String getMvcType();
049 
050     /**
051      * Returns the id of the group.
052      * Ids are used to uniquely identify a group instance.
053      *
054      @return the id of this group.
055      */
056     @Nonnull
057     String getMvcId();
058 
059     /**
060      * Returns the Model portion of this group.
061      *
062      @return a GriffonModel instance if the group has a model member, null otherwise
063      @throws IllegalStateException if the group has been destroyed already
064      */
065     @Nullable
066     GriffonModel getModel();
067 
068     /**
069      * Returns the View portion of this group.
070      *
071      @return a GriffonView instance if the group has a view member, null otherwise
072      @throws IllegalStateException if the group has been destroyed already
073      */
074     @Nullable
075     GriffonView getView();
076 
077     /**
078      * Returns the Controller portion of this group.
079      *
080      @return a GriffonController instance if the group has a controller member, null otherwise
081      @throws IllegalStateException if the group has been destroyed already
082      */
083     @Nullable
084     GriffonController getController();
085 
086     /**
087      * Returns the specified member type.
088      *
089      @param name the type of member to retrieve
090      @return the selected MVC member if a match is found, null otherwise
091      @throws IllegalStateException if the group has been destroyed already
092      */
093     @Nullable
094     Object getMember(@Nonnull String name);
095 
096     /**
097      * Returns a read-only view of all instance members.
098      *
099      @return an unmodifiable Map view of all members.
100      @throws IllegalStateException if the group has been destroyed already
101      */
102     @Nonnull
103     Map<String, Object> getMembers();
104 
105     /**
106      * Destroys the current group.
107      <strong>Should only be called once.</strong>
108      *
109      @throws IllegalStateException if the group has been destroyed already
110      */
111     void destroy();
112 
113     /**
114      * Returns whether this group has been destroyed or not.
115      *
116      @return true if the group has not been destroyed yet, false otherwise
117      */
118     boolean isAlive();
119 
120     /**
121      * Returns the context belonging to this group.
122      *
123      @since 2.2.0
124      */
125     @Nonnull
126     Context getContext();
127 
128     /**
129      * Returns the parent {@code MVCGroup} of this group.
130      <p>The parent may be null if this is a top level MVC group.</p>
131      *
132      @since 2.2.0
133      */
134     @Nullable
135     MVCGroup getParentGroup();
136 
137     /**
138      * Returns an immutable view of all children groups for which this group is a parent
139      *
140      @return an immutable view of children groups, keyed by mvcId.
141      @since 2.4.0
142      */
143     @Nonnull
144     Map<String, MVCGroup> getChildrenGroups();
145 
146     /**
147      * Notifies the group when another MVC group has been destroyed, potentially
148      * a child group.
149      *
150      @param mvcId the id of the group that has been destroyed
151      @since 2.4.0
152      */
153     void notifyMVCGroupDestroyed(@Nonnull String mvcId);
154 }