⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 openmapcompositiontask.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * Map Composition ID is set via a call by the framework to {@link #setMap}.  If the selected
	 * Map Composition was deleted successfully then a DELETED event will be produced and 
	 * fired to observers.
	 * 
	 * @param event  Task event information.
	 */
	public void delete (TaskEvent event) {
		if (m_persCtx == null) {
			LOG.error(ERROR_NULL_PERS_CTX);
			throw new IllegalStateException (ERROR_NULL_PERS_CTX);
		}
		
		UUID id = null;
		IMapComposition mc = null;
		IMapComposition currentMc = null;
		id = UUID.fromString(m_map);
		String currentName = "";
		List<String> messages = new ArrayList<String>();
		
		try {
			
			currentMc = (IMapComposition) m_persCtx.getAttribute(
					ADFPersonalizationContext.CURRENT_MAP_COMPOSITION_KEY);
			
			//////////////////////////////////////////////////////////////////////
			// Check the current Map Composition in the Personalization Context.
			// If its ID matches the selected Map Composition's ID, then call
			// delete on the Map Composition object in the Personalization Context.
			// Otherwise, load from Personalization using ID and call delete.
			//////////////////////////////////////////////////////////////////////
			if (id.equals(currentMc.getId())) {
				currentName = currentMc.getName();
				currentMc.remove();
			} else {
				mc = m_persCtx.getData().getMapComposition(id);
				currentName = mc.getName();
				mc.remove();
			}
			
			if (m_eventProducer != null) {
				m_eventProducer.push(new MapCompositionEvent(
						this, 
						MapCompositionEvent.MapCompositionEventType.DELETED, 
						mc));
			}
			
			refresh();
			
			if (LOG.isInfoEnabled()) {
				String pattern = TextResources.getResourceString("openmapcomp.ui.msg.deleteSuccess");
				String msg = MessageFormat.format(pattern, currentName);
				LOG.info(msg);
			}
			
		} catch (PersonalizationException e) {
			String pattern = TextResources.getResourceString("openmapcomp.ui.msg.error.DELETE_DATA_ERROR");
			String msg = null;
			
			try {
				msg = MessageFormat.format(pattern, currentName);
			} catch (IllegalArgumentException e1) {
				LOG.warn("", e);
				msg = pattern;
			}
			
			messages.add(msg);
		} finally {
			pushErrors(messages);
			this.requestTaskRender();
		}
	}
	
	/**
	 * Sorts the Map list with the sorter that was chosen.  The sorters
	 * are configured within the bean management framework.  Users can
	 * choose a sorter to have the Map list sorted in the specified fashion.
	 * 
	 * @param event Contains event information.
	 */
	public void sort (TaskEvent event) {
		if (m_persCtx == null) {
			LOG.error(ERROR_NULL_PERS_CTX);
			throw new IllegalStateException (ERROR_NULL_PERS_CTX);
		}
		
		try {
			refreshData();
			Comparator<IMapComposition> sorter = m_sorters.get(m_sorterId);
			
			if (sorter != null) {
				Collections.sort(this.m_data, sorter);
				refreshMappings();
			}
			this.requestTaskRender();
		} catch (PersonalizationException e) {
			LOG.warn("", e);
			clearData();
			clearMappings();
		}
	}
	
	/**
	 * Returns the delete confirmation message
	 * 
	 * @return	Delete confirmation message.
	 */
	public String getConfirmDeleteMessage () {
		String msg = TextResources.getResourceString("openmapcomp.ui.msg.ConfirmDelete");
		return msg;
	}
	
	/**
	 * Returns the Description Header Label from the Resource Bundle.
	 * 
	 * @return	Description Header Label
	 */
	public String getDescriptionHeaderLabel () {
		String lbl = TextResources.getResourceString("openmapcomp.ui.label.header.Description");
		return lbl;
	}
	
	/**
	 * Returns the Preview Header Label from the Resource Bundle.
	 * 
	 * @return  Preview Header Label.
	 */
	public String getPreviewHeaderLabel () {
		String lbl = TextResources.getResourceString("openmapcomp.ui.label.header.Preview");
		return lbl;
	}
	
	/**
	 * Returns the No Preview Available Message from the Resource Bundle
	 * 
	 * @return  No Preview Available Message
	 */
	public String getNoPreviewAvailableMessage () {
		String msg = TextResources.getResourceString("openmapcomp.ui.msg.NoPreviewAvailable");
		return msg;
	}

	/**
	 * Returns the reference to the Save Map Composition Event observer.  This observer
	 * will listen for SAVED events in order to update the internal Map Composition data list and
	 * mappings and to flag this task for rendering.
	 * 
	 * @return Reference to the Save Map Composition Event observer.
	 */
	public IMapCompositionEventObserver getSaveMapCompositionObserver () {
		return m_saveObserver;
	}
	
	/**
	 * Sets the reference to the Error Producer object.  The Error Producer will push
	 * error messages to registered observers.  The Error Producer is optional for this
	 * task.
	 * 
	 * @param producer	Reference to Error Producer, can be <code>null</code>.
	 */
	public void setErrorProducer (IErrorProducer producer) {
		m_errorProducer = producer;
	}
	
	/**
	 * Sets the reference to the object that opens Map Compositions within
	 * the Viewer.  This object is required for this task to execute.
	 * 
	 * @param opener	Reference to object that opens Map Compositions, cannot
	 * 					be <code>null</code>.
	 * @throws NullPointerException		Thrown if the <code>opener</code> argument
	 * 									is <code>null</code>.
	 */
	public void setOpenMapComposition (IOpenMapComposition opener) {
		if (opener == null) {
			throw new NullPointerException ();
		}
		m_opener = opener;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.esri.solutions.jitk.common.personalization.IPersonalizable#setPersonalizationContext(com.esri.solutions.jitk.common.personalization.IPersonalizationContext)
	 */
	public void setPersonalizationContext(IPersonalizationContext ctx) {
		if (ctx == null) {
			throw new NullPointerException ();
		}
		m_persCtx = ctx;
		refresh();
	}

	/**
	 * Sets the Map Composition Event Producer object.  If this object is specified then OPENED and DELETED
	 * 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;
	}
	
	/**
	 * Clears the internal Map Composition Data.
	 */
	protected void clearData() {
		m_data.clear();
	}

	/**
	 * Clears the mapping between Map Composition ID and its Name and Description.
	 */
	protected void clearMappings() {
		m_maps.clear();
		m_descriptions.clear();
	}

	/**
	 * Refresh the mappings between a Map Composition ID and its Name and
	 * Description.  The Map Composition data must be refreshed prior to calling
	 * this method in order to make the correct mappings.
	 */
	protected void refreshMappings() {
		clearMappings();
		for (IMapComposition mc : m_data) {
			m_maps.put(mc.getId().toString(), convertNull(mc.getName()));
			m_descriptions.put(mc.getId().toString(), convertNull(mc.getDescription()));
		}
	}

	/**
	 * Refreshes the internal Map Composition list.  The Map Composition list will
	 * be retrieved from the Personalization data store.
	 * 
	 * @throws PersonalizationException		Thrown if there was an access problem to
	 * 										Personalization.
	 */
	protected void refreshData() throws PersonalizationException {
		List<IMapComposition> data = m_persCtx.getData().getMapCompositions();
		clearData();
		m_data.addAll(data);
		Comparator<IMapComposition> sorter = getFirstSorter();
		if (sorter != null) {
			Collections.sort(m_data, sorter);
		}
	}
	
	/**
	 * Returns the first sorter object in the collection of Sorters.
	 * 
	 * @return Comparator object to compare two Map Composition objects.
	 */
	protected Comparator<IMapComposition> getFirstSorter () {
		for (Comparator<IMapComposition> sorter : m_sorters.values()) {
			return sorter;
		}
		
		return null;
	}
	
	/**
	 * 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;
	}
	
	/**
	 * Pushes a list of errors to the Error Producer.
	 * 
	 * @param messages	List of error messages.
	 */
	private void pushErrors (List<String> messages) {
		if (m_errorProducer != null) {
			for (String msg : messages) {
				DefaultError error = new DefaultError();
				error.setMessage(msg);
				m_errorProducer.push(error);
			}
		}
	}
	
	/**
	 * Observes SAVED events for a Map Composition.  When a Map
	 * Composition is saved, this task is refreshed in order to
	 * update its internal data.
	 */
	private class SaveMapCompositionEventObserver implements IMapCompositionEventObserver {
	
		/*
		 * (non-Javadoc)
		 * @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#created(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
		 */
		public void created(MapCompositionEvent event) {
		}

		/*
		 * (non-Javadoc)
		 * @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#deleted(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
		 */
		public void deleted(MapCompositionEvent event) {
		}

		/*
		 * (non-Javadoc)
		 * @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#opened(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
		 */
		public void opened(MapCompositionEvent event) {
		}

		/*
		 * (non-Javadoc)
		 * @see com.esri.solutions.jitk.web.tasks.mapcomp.IMapCompositionEventObserver#saved(com.esri.solutions.jitk.web.tasks.mapcomp.MapCompositionEvent)
		 */
		public void saved(MapCompositionEvent event) {
			refresh();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -