📄 newmapcompositiontask.java
字号:
package com.esri.solutions.jitk.web.tasks.mapcomp;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.solutions.jitk.common.personalization.ADFPersonalizationContext;
import com.esri.solutions.jitk.common.personalization.IPersonalizable;
import com.esri.solutions.jitk.common.personalization.IPersonalizationContext;
import com.esri.solutions.jitk.common.resources.TextResources;
import com.esri.solutions.jitk.common.templates.map.IMapTemplate;
import com.esri.solutions.jitk.common.templates.map.IMapTemplateRepository;
import com.esri.solutions.jitk.personalization.PersonalizationException;
import com.esri.solutions.jitk.personalization.data.IMapComposition;
import com.esri.solutions.jitk.personalization.data.IPersonalizationData;
import com.esri.solutions.jitk.web.error.IErrorProducerAware;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
/**
* Task to create a new Map Composition within the map viewer. This task will
* provide the user the ability to save the current Map Composition. The user
* will be able to enter the name and description of the saved Map Composition.
*/
public class NewMapCompositionTask extends RenderControlledTask implements IPersonalizable {
private static final long serialVersionUID = 9006902707613625438L;
private static final String ERROR_NULL_MAP_TEMPLATE_REPO = "Map Template Repository is required and cannot be null.";
/**
* Logger to use to log messages from this class.
*/
private static final Logger LOG = LogManager.getLogger(NewMapCompositionTask.class);
/**
* Implementation of {@link ISaveMapCompositionFormData} to expose the
* Task Parameter values through the interface in order to save a Map
* Composition.
*/
private class FormData implements ISaveMapCompositionFormData, Serializable {
private static final long serialVersionUID = 2847917872596238715L;
/**
* Description entered by User.
*/
private String m_description;
/**
* Name entered by User.
*/
private String m_name;
/**
* Flag indicating if the Map Composition is new.
*/
private boolean m_isNew = true;
/**
* Returns the Description entered by the User.
*
* @return Description value or <code>null</code> if
* description has not been set.
*/
public String getDescription() {
return m_description;
}
/**
* Returns the ID of the Map Composition. If the Map
* Composition is not new, then the ID of the Current
* Map Composition is returned, otherwise <code>null</code>
* is returned.
*
* @return Map Composition ID.
*/
public String getId() {
if (!isNew()) {
return getCurrentMapComposition().getId().toString();
}
return null;
}
/**
* Returns the Name of the Map Composition entered by the
* user.
*
* @return Name of Map Composition or <code>null</code> if
* name has not been set.
*/
public String getName() {
return m_name;
}
/**
* Returns a flag indicating if the Map Composition is new.
*
* @return IsNew flag.
*/
public boolean isNew() {
return m_isNew;
}
/**
* Sets the description of the Map Composition. Leading and
* trailing whitespace will be removed.
*
* @param description Description of Map Composition.
*/
public void setDescription(String description) {
m_description = description;
if (m_description != null) {
m_description = m_description.trim();
}
}
/**
* Sets the name of the Map Composition. Leading and
* trailing whitespace will be removed.
*
* @param name Name of Map Composition.
*/
public void setName(String name) {
m_name = name;
if (m_name != null) {
m_name = m_name.trim();
}
}
/**
* Sets the IsNew flag to indicate if the Map Composition
* is new.
*
* @param isNew
*/
public void setNew(boolean isNew) {
m_isNew = isNew;
}
/**
* Clears the internal state of the form data.
*/
void clear () {
m_name = null;
m_description = null;
m_isNew = true;
}
}
/**
* Reference to Personalization Context.
*/
private IPersonalizationContext m_persCtx;
/**
* Flag to indicate if the current Map should be saved before
* creating a new Map Composition.
*/
private boolean m_saveCurrentMap = false;
/**
* Reference to the Map Composition Saver object. This
* object will actually save the Map Composition.
*/
private ISaveMapComposition m_saver;
/**
* Reference to the Map Template Repository. A list of Map
* Templates will be displayed in the GUI.
*/
private IMapTemplateRepository m_templateRepo;
/**
* Map Templates parameter. Maps a Map Template ID to its Name.
*/
private final Map<String,String> m_mapTemplates;
/**
* Map Template Descriptions parameters. Map a Map Template ID to its
* Description.
*/
private final Map<String,String> m_mapTmplDescriptions;
/**
* Selected Map Template ID. This value will be used when creating a new
* Map Composition. The Map Template with this ID will be loaded into
* the viewer.
*/
private String m_mapTemplateId;
/**
* Name of the Map Template Repository name within the bean container.
*/
private String m_repoBeanId;
/**
* Reference to the Form Data for saving a Map Composition. The saver object used
* this type of object to callback to get the required form values.
*/
private final FormData m_formData;
/**
* Reference to the object that fires Map Composition Events to registered observers.
*/
private IMapCompositionEventProducer m_eventProducer;
/**
* Configuration setting to indicate if a new Map Composition should be created
* if the names don't match.
*/
private boolean m_createNewOnNameChange;
/**
* Constructs a new <code>NewMapCompositionTask</code>.
*/
public NewMapCompositionTask () {
this.setTaskInfo(new NewMapCompositionTaskInfo());
m_formData = new FormData();
m_mapTemplates = new LinkedHashMap<String,String>();
m_mapTmplDescriptions = new LinkedHashMap<String,String>();
m_mapTemplateId = "";
}
/**
* Returns the values for the Map Templates parameter. The Map Templates
* parameter maps a set of Map Template IDs to their associated Names. In
* each entry, the ID and Name will not be <code>null</code>. If no Name
* was found then a zero-length string will be present.
*
* @return Map Template parameter, <code>null</code> will never be
* returned.
*/
public Map<String, String> getMapTemplates () {
return m_mapTemplates;
}
/**
* Returns the values for the Map Template Descriptions parameter. The Map
* Templates parameter maps a set of Map Template IDs to their associated
* Descriptions. In each entry, the ID and Description will not be <code>null</code>.
* If no Description was found then a zero-length string will be present.
*
* @return Map Template Descriptions parameter, <code>null</code> will never be
* returned..
*/
public Map<String, String> getMapTemplateDescriptions () {
return m_mapTmplDescriptions;
}
/**
* Returns the ID of the selected Map Template. A Map Template is selected
* via the GUI. The Map Template that is selected will be opened in the
* viewer.
*
* @return ID of the selected Map Template
*/
public String getMapTemplate () {
return m_mapTemplateId;
}
/**
* Sets the ID of the selected Map Template. The Map Template is selected
* within the GUI. The Task Framework will call this method to set the
* selected ID.
*
* @param id ID of the selected Map Template.
*/
public void setMapTemplate (String id) {
m_mapTemplateId = id;
}
/**
* Returns the name of the Map Template Repository Bean Name
* within the bean framework. This will be used to construct a URL
* to get the Map Template Preview Image. The bean name is required
* for the URL.
*
* @return Map Template Repository Bean Name.
*/
public String getMapTemplateRepositoryBeanId () {
return m_repoBeanId;
}
/**
* Sets the name of the Map Template Repository Bean within the bean
* framework. This will be used to construct a URL to get the Map Template
* Preview Image. The bean name is required for the URL. This method is typically
* invoked by the bean framework when configuring the system.
*
* @param beanId Name of the Map Template Repository Bean
*/
public void setMapTemplateRepositoryBeanId (String beanId) {
m_repoBeanId = beanId;
}
/**
* Returns the "Save Current Map" flag. This allows the user to specify
* whether or not the user wants to save the current Map before creating
* a new Map.
*
* @return Save Current Map flag.
*/
public boolean getSaveCurrentMap () {
return m_saveCurrentMap;
}
/**
* Sets the "Save Current Map" flag. This allows te user to specify whether
* or not the user wants to save the current Map before creating a new
* Map.
*
* @param b Save Current Map flag.
*/
public void setSaveCurrentMap (boolean b) {
m_saveCurrentMap = b;
}
/**
* Returns the name of the configured {@link WebContext}. This will
* be used to generate the Preview Image for the Web Map.
*
* @return Web Context Name
*/
public String getWebContextName () {
return this._context.getName();
}
/**
* Returns the Name of the Map Composition that the user entered. This will only
* return a value if the <code>saveCurrentMap</code> property is
* <code>true</code>.
*
* @return Map Composition's Name.
*/
public String getName () {
return m_formData.getName();
}
/**
* Sets the Name of the Map Composition that the user entered. This will be
* called when the user enters a Name for a Map Composition. A Name will
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -