📄 openmapcompositiontask.java
字号:
package com.esri.solutions.jitk.web.tasks.mapcomp;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
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.personalization.PersonalizationException;
import com.esri.solutions.jitk.personalization.data.IMapComposition;
import com.esri.solutions.jitk.web.error.DefaultError;
import com.esri.solutions.jitk.web.error.IErrorProducer;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
/**
* Task to open a Map Composition within the map viewer. This task
* provides the ability for the user to open a Map Composition.
* This task also provides the
* ability to display pages of Map Compositions and to navigate through the
* pages using Previous, Next, First, Last operations.
*/
public class OpenMapCompositionTask extends RenderControlledTask implements IPersonalizable {
private static final long serialVersionUID = 5181883486706903270L;
private static final String WARN_UNABLE_RETRIEVE_PERS_DATA = "Unable to retrieve Personalization Data, returning null username";
private static final String ERROR_NULL_OPENER = "Open Map Composition object is required and cannot be null.";
private static final String ERROR_NULL_PERS_CTX = "Personalization Context object is required and cannot be null.";
private static final String INFO_CTOR = "Constructed a new OpenMapCompositionTask object.";
private static final Logger LOG = LogManager.getLogger(OpenMapCompositionTask.class);
/**
* Reference to object that provides business logic for opening a
* Map Composition.
*/
private transient IOpenMapComposition m_opener;
/**
* Reference to Personalization Context to access Personalization Data and
* functionality.
*/
private IPersonalizationContext m_persCtx;
/**
* List of Map Composition objects retrieved from data store.
*/
private transient final List<IMapComposition> m_data;
/**
* Mapping between Map Composition ID and its associated Name.
*/
private final Map<String, String> m_maps;
/**
* Mapping between Map Composition ID and its associated Description.
*/
private final Map<String, String> m_descriptions;
/**
* Map Composition ID that is being selected for opening or deleting.
*/
private String m_map = "";
/**
* Reference to Error Producer that will produce errors on the task's
* behalf.
*/
private IErrorProducer m_errorProducer;
/**
* Reference to Map Composition Event Producer that will produce Map Composition
* Events and fire them to observers.
*/
private IMapCompositionEventProducer m_eventProducer;
/**
* Observes SAVED events for Map Compositions in order to refresh the
* internal data list.
*
* @see #m_data
*/
private final SaveMapCompositionEventObserver m_saveObserver;
/**
* Contains a collection of sorters that will be used to sort the
* list of Map Compositions.
*/
private final Map<String, Comparator<IMapComposition>> m_sorters;
/**
* ID of the Sorter currently in use.
*/
private String m_sorterId;
/**
* Constructs a new <code>OpenMapCompositionTask</code>.
*/
public OpenMapCompositionTask () {
this.setTaskInfo(new OpenMapCompositionTaskInfo());
m_data = new ArrayList<IMapComposition>();
m_maps = new LinkedHashMap<String,String>();
m_descriptions = new LinkedHashMap<String, String>();
m_saveObserver = new SaveMapCompositionEventObserver();
m_sorters = new LinkedHashMap<String, Comparator<IMapComposition>>();
LOG.info(INFO_CTOR);
}
/**
* Refreshes the internal state of this task. The list of Map Compositions
* will be retrieved from the Personalization data store and kept internally.
* The mapping of Map Composition IDs and Names and Descriptions will also be
* reset to the Map Compositions that were retrieved from the Personalization
* data store.
*
* @see #refreshData()
* @see #refreshMappings()
* @see #clearData()
* @see #clearMappings()
*/
public void refresh () {
if (m_persCtx == null) {
LOG.error(ERROR_NULL_PERS_CTX);
throw new IllegalStateException (ERROR_NULL_PERS_CTX);
}
try {
refreshData();
refreshMappings();
this.requestTaskRender();
} catch (PersonalizationException e) {
LOG.warn("", e);
clearData();
clearMappings();
}
}
/**
* Returns the mapping between the Map Composition IDs and their
* associated names. This is needed by the ADF in order to produce
* a list box of Map Compositions. The ID will be the value of the
* Select box and the Name will be the display value of the Select Box.
*
* @return Mapping between Map Composition IDs and their associated names.
* <code>null</code> should never be returned.
*/
public Map<String, String> getMaps () {
return m_maps;
}
/**
* Returns the mapping between the Map Composition IDs and their
* associated descriptions. This is needed within this task in order
* to display the description for a Map Composition.
*
* @return Mapping between Map Composition IDs and their associated descriptions.
* <code>null</code> should never be returned.
*/
public Map<String, String> getMapDescriptions () {
return m_descriptions;
}
/**
* Returns the selected Map Composition ID. A Map Composition is selected if the
* User chooses a Map Composition from the list box and chooses the Open or Delete
* actions.
*
* @return Selected Map Composition ID. This will return an empty string if a Map
* Composition has not been selected. <code>null</code> should never be
* returned.
*/
public String getMap () {
return m_map;
}
/**
* Sets the selected Map Composition ID. A Map Composition is selected if the User
* chooses a Map Composition from the list box and chooses the Open or Delete
* actions.
*
* @param id Selected Map Composition ID.
*/
public void setMap (String id) {
m_map = id;
}
/**
* Returns the current Username of the authenticated session. This will be used
* to build up the URL to access the Map Composition Preview.
*
* @return Current Username
*/
public String getUsername () {
try {
return m_persCtx.getData().getCurrentUser().getId().getUsername();
} catch (PersonalizationException e) {
LOG.warn(WARN_UNABLE_RETRIEVE_PERS_DATA, e);
return null;
}
}
/**
* Returns the sorters to be displayed in the GUI. The Map will
* contain the Sorter ID which is the Key value in the Sorter HashMap and
* the display value for the sorter. The display value is calculated
* by appending the Sorter ID to the end of "openmapcomp.ui.options.sorters."
*
* @return Sorter List for display in the GUI.
*/
public Map<String,String> getSorterList () {
Map<String,String> sorterList = new LinkedHashMap<String,String>();
for (Entry<String, Comparator<IMapComposition>> entry : m_sorters.entrySet()) {
sorterList.put(entry.getKey(), TextResources.getResourceString("openmapcomp.ui.option.sorters." + entry.getKey()));
}
return sorterList;
}
/**
* Returns the currently selected Sorter ID.
*
* @return Currently selected Sorter ID.
*/
public String getSorter() {
return m_sorterId;
}
/**
* Sets the selected Sorter ID. This method is typically called
* by the Task framework when the user chooses a Sorter from the Sorter
* List.
*
* @param sorterId ID of selected Sorter.
*/
public void setSorter (String sorterId) {
m_sorterId = sorterId;
}
/**
* Returns a Map of the Sorter objects. Each Sorter object is assigned
* a unique key for easy retrieval. This method is typically called by
* the bean management framework in order to setup the Sorter objects.
*
* @return Sorter Objects.
*/
public Map<String, Comparator<IMapComposition>> getSorters () {
return m_sorters;
}
/**
* Sets the Sorter objects within this object. The Sorter objects must
* have a unique key within the Map.
*
* @param sorters Sorter objects.
*/
public void setSorters (Map<String, Comparator<IMapComposition>> sorters) {
m_sorters.clear();
if (sorters != null) {
m_sorters.putAll(sorters);
}
}
/**
* Opens the selected Map Composition into the Viewer. The selected Map Composition is set via a call
* by the framework to {@link #setMap}. If the Map Composition is opened successfully, then
* an OPENED event will be produced and fired.
*
* @param event Task Event information.
*/
public void open (TaskEvent event) {
if (m_persCtx == null) {
LOG.error(ERROR_NULL_PERS_CTX);
throw new IllegalStateException (ERROR_NULL_PERS_CTX);
}
if (m_opener == null) {
LOG.error(ERROR_NULL_OPENER);
throw new IllegalStateException (ERROR_NULL_OPENER);
}
IMapComposition mc = null;
List<String> messages = new ArrayList<String>();
try {
mc = m_persCtx.getData().getMapComposition(UUID.fromString(m_map));
m_opener.clearMessages();
m_opener.open(mc);
messages.addAll(m_opener.getMessages());
if (m_eventProducer != null) {
m_eventProducer.push(new MapCompositionEvent(
this,
MapCompositionEvent.MapCompositionEventType.OPENED,
mc));
}
if (LOG.isInfoEnabled()) {
String pattern = TextResources.getResourceString("openmapcomp.ui.msg.openSuccess");
String msg = MessageFormat.format(pattern, mc.getName());
LOG.info(msg);
}
} catch (PersonalizationException e) {
messages.add(TextResources.getResourceString("openmapcomp.ui.msg.error.RETRIEVE_DATA_ERROR"));
LOG.warn(TextResources.getResourceString("openmapcomp.ui.msg.error.RETRIEVE_DATA_ERROR"), e);
} finally {
pushErrors(messages);
this.requestTaskRender();
}
}
/**
* Deletes the selected Map Composition from the Personalization data store. The selected
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -