📄 newmapcompositiontask.java
字号:
* only be set when the <code>saveCurrentMap</code> property
* is <code>true</code>.
*
* @param name Map Composition Name.
*/
public void setName (String name) {
m_formData.setName(name);
}
/**
* Returns the Description 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 Description.
*/
public String getDescription () {
return m_formData.getDescription();
}
/**
* Sets the Description of the Map Composition that the user entered. This will be
* called when the user enters a Description for a Map Composition. A Description will
* only be set when the <code>saveCurrentMap</code> property
* is <code>true</code>.
*
* @param desc Map Composition Description.
*/
public void setDescription (String desc) {
m_formData.setDescription(desc);
}
/**
* Retrieves the confirmation message to display to the user to confirm
* the creation of a new Map Composition.
*
* @return Confirmation message.
*/
public String getConfirmMessage () {
return TextResources.getResourceString("newmapcomp.ui.msg.ConfirmNew");
}
/**
* Sets the reference to the Personalization Context.
*
* @param ctx Reference to {@link IPersonalizationContext}, cannot
* be <code>null</code>.
* @throws NullPointerException Thrown if the <code>ctx</code>
* argument is <code>null</code>.
*/
public void setPersonalizationContext(IPersonalizationContext ctx) {
if (ctx == null) {
throw new NullPointerException();
}
m_persCtx = ctx;
}
/**
* Sets the reference to the Map Template Repository. This repository will
* be used when displaying Map Templates in the GUI. All Map Templates within
* the repository will be displayed in the GUI.
*
* @param repo Reference to Map Template Repository, cannot be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>repo</code> argument
* is <code>null</code>.
*/
public void setMapTemplateRepository (IMapTemplateRepository repo) {
if (repo == null) {
throw new NullPointerException ();
}
m_templateRepo = repo;
refresh();
}
/**
* Sets the reference to the Map Composition Saver object. This object provides
* the business logic for saving a Map Composition within the ADF.
*
* @param saver Map Composition Saver object, cannot be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>saver</code> object is
* <code>null</code>.
*/
public void setSaveMapComposition (ISaveMapComposition saver) {
if (saver == null) {
throw new NullPointerException();
}
m_saver = saver;
}
/**
* Sets the Map Composition Event Producer object. If this object is specified then CREATED and
* SAVED events will be pushed to the Map Composition Event Observers within the producer object.
*
* @param producer Produces Map Composition Events to a set of observers, can be <code>null</code>.
*/
public void setMapCompositionEventProducer (IMapCompositionEventProducer producer) {
m_eventProducer = producer;
}
/**
* Configuration parameter to indicate to create a new Map Composition if the
* current Map Composition's Name is not the same as the Name that the
* user entered.
*
* @param flag
*/
public void setCreateNewOnNameChange (boolean flag) {
m_createNewOnNameChange = flag;
}
/**
* Task Action to create a new Map Composition WITHOUT saving the current
* Map Composition. This action will use the selected Map Template and
* open it within the viewer. A new Map Composition object will also be
* created and set within the Personalization Context as an attribute.
*
* @param event Event information.
*
* @see ADFPersonalizationContext#CURRENT_MAP_COMPOSITION_KEY
* @see IPersonalizationData#createMapComposition()
*/
public void create (TaskEvent event) {
List<String> messages = new ArrayList<String>();
try {
newMapComposition();
} catch (PersonalizationException e) {
LOG.warn("", e);
messages.add(TextResources.getResourceString("newmapcomp.ui.msg.error.Create"));
} finally {
renderErrors(messages);
requestTaskRender();
}
}
/**
* Task Action to save the current Map Composition and create a new
* Map Composition. If the configuration property
* <code>createNewOnNameChange</code> is set to <code>true</code>
* then a new Map Composition will be created if their is a change in Name
* between what the user entered and the current Map Composition.
* This action will use the selected Map Template
* and open it within the viewer. A new Map Composition object will also be
* created and set within the Personalization Context as an attribute.
*
* @param event Event information.
*/
public void saveAndCreate (TaskEvent event) {
String name = getName();
if (name == null || name.trim().length() == 0) {
this.renderResourceMessage("newmapcomp.ui.name.blank.warning", messageType.WARNING);
return;
}
List<String> messages = new ArrayList<String>();
try {
IMapComposition currentMc = getCurrentMapComposition();
///////////////////////////////////////////////////////////
// If the Current Map Composition is not new, then we need
// to compare the Name (user entered vs. current map comp
// name) to see if they are different. If different, then
// a new Map Comp should be created.
///////////////////////////////////////////////////////////
if (!currentMc.isNew()) {
if (!currentMc.getName().equalsIgnoreCase(m_formData.getName())) {
m_formData.setNew(m_createNewOnNameChange);
} else {
m_formData.setNew(false);
}
} else {
m_formData.setNew(true);
}
////////////////////////////////////////////////////////////////////////////////////////
// Use the saver to save the Map Composition. The Map Composition returned should
// be set within the Personalization Context.
////////////////////////////////////////////////////////////////////////////////////////
IMapComposition savedMc = m_saver.save(m_formData);
m_persCtx.setAttribute(
ADFPersonalizationContext.CURRENT_MAP_COMPOSITION_KEY,
savedMc);
String pattern = TextResources.getResourceString("newmapcomp.ui.msg.SaveSuccess");
String msg = MessageFormat.format(pattern, savedMc.getName());
this.renderMessage(msg, IErrorProducerAware.messageType.SUCCESS);
if (m_formData.isNew()) {
/////////////////////////////////////////////////////////////////////
// Map Composition should have been created, fire a CREATED event.
/////////////////////////////////////////////////////////////////////
if (m_eventProducer != null) {
m_eventProducer.push(new MapCompositionEvent(
this,
MapCompositionEvent.MapCompositionEventType.CREATED,
savedMc));
}
}
if (m_eventProducer != null) {
m_eventProducer.push(new MapCompositionEvent(
this,
MapCompositionEvent.MapCompositionEventType.SAVED,
savedMc));
}
messages.addAll(m_saver.getMessages());
if (LOG.isInfoEnabled()) {
pattern = TextResources.getResourceString("savemapcomp.ui.msg.saveSuccess");
msg = MessageFormat.format(pattern, savedMc.getName());
LOG.info(msg);
}
m_formData.clear();
newMapComposition();
} catch (PersonalizationException e) {
messages.addAll(m_saver.getMessages());
messages.add(TextResources.getResourceString("newmapcomp.ui.msg.error.SaveAndCreate"));
LOG.warn("", e);
} finally {
renderErrors(messages);
requestTaskRender();
}
}
/**
* Creates a new Map Composition, sets the Map Composition within the
* Personalization Context, adds default resources into Web Context, and
* refreshes Web Context.
*
* @param event Contains task event information.
* @throws PersonalizationException
*/
private void newMapComposition () throws PersonalizationException {
WebContext wc = m_persCtx.getWebContext();
IMapTemplate template = null;
template = m_templateRepo.getMapTemplate(m_mapTemplateId);
if (template == null) {
return;
} else {
template.open(wc);
}
IMapComposition mc = m_persCtx.getData().createMapComposition();
m_persCtx.setAttribute(ADFPersonalizationContext.CURRENT_MAP_COMPOSITION_KEY, mc);
MapCompositionEvent event = new MapCompositionEvent(this, MapCompositionEvent.MapCompositionEventType.CREATED, mc);
m_eventProducer.push(event);
}
/**
* Refreshes the internal Map Template ID to Name and Description maps and sets the
* currently selected Map Template ID to the first Map Template retrieved
* from {@link IMapTemplateRepository#getMapTemplates()}.
*/
public void refresh() {
if (m_templateRepo == null) {
LOG.error(ERROR_NULL_MAP_TEMPLATE_REPO);
throw new IllegalArgumentException (ERROR_NULL_MAP_TEMPLATE_REPO);
}
clearMappings();
refreshMappings();
java.util.Iterator<String> i = m_mapTemplates.keySet().iterator();
if (i.hasNext()) {
m_mapTemplateId = i.next();
}
requestTaskRender();
}
/**
* Clears the internal Map Template ID to Map Template Name and Description mappings.
*/
protected void clearMappings() {
m_mapTemplates.clear();
m_mapTmplDescriptions.clear();
}
/**
* Refreshes the internal Map Template ID to Name and Description maps.
*/
protected void refreshMappings() {
List<IMapTemplate> templates = null;
templates = m_templateRepo.getMapTemplates();
for (IMapTemplate template : templates) {
m_mapTemplates.put(template.getId(), convertNull(template.getName()));
m_mapTmplDescriptions.put(template.getId(), convertNull(template.getDescription()));
}
}
/**
* Helper method to retrieve the current Map Composition from the
* Personalization Context.
*
* @return Current Map Composition
*/
private IMapComposition getCurrentMapComposition() {
IMapComposition mc = (IMapComposition) m_persCtx.getAttribute(
ADFPersonalizationContext.CURRENT_MAP_COMPOSITION_KEY);
return mc;
}
/**
* Helper method to return a String value of "null" if the String
* argument is <code>null</code>.
*
* @param s String argument.
* @return "null" if the String argument is <code>null</code>, the
* value of <code>s</code> otherwise.
*/
private static String convertNull (String s) {
if (s == null) {
return "";
}
return s;
}
/**
* Renders a list of error messages to the UI.
*
* @param messages List of error messages.
* @see #renderMessage(String)
*/
private void renderErrors (List<String> messages) {
for (String msg : messages) {
this.renderMessage(msg);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -