Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 77:5b5ec0403844
Limited the area for CollectionView to the size of FLYSWorkspace.
flys-client/trunk@1583 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 28 Mar 2011 10:40:50 +0000 |
parents | 571843833129 |
children | b8acb6a615f2 |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.Tab; import com.smartgwt.client.widgets.tab.TabSet; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.ArtifactDescription; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.OutputMode; import de.intevation.flys.client.shared.model.User; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.FLYS; import de.intevation.flys.client.client.FLYSMessages; import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; import de.intevation.flys.client.client.event.CollectionChangeEvent; import de.intevation.flys.client.client.event.CollectionChangeHandler; import de.intevation.flys.client.client.event.ParameterChangeEvent; import de.intevation.flys.client.client.event.ParameterChangeHandler; import de.intevation.flys.client.client.services.AddArtifactService; import de.intevation.flys.client.client.services.AddArtifactServiceAsync; import de.intevation.flys.client.client.services.CreateCollectionService; import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class CollectionView extends Window implements CollectionChangeHandler, HasCollectionChangeHandlers, ParameterChangeHandler { /** The ArtifactService used to communicate with the Artifact server. */ protected CreateCollectionServiceAsync createCollectionService = GWT.create(CreateCollectionService.class); /** The AddArtifactService used to add an artifact to a collection. */ protected AddArtifactServiceAsync addArtifactService = GWT.create(AddArtifactService.class); /** The message class that provides i18n strings.*/ protected FLYSMessages messages = GWT.create(FLYSMessages.class); /** The FLYS instance used to call services.*/ protected FLYS flys; /** The ParameterList.*/ protected ParameterList parameterList; /** The list of ValueChangeHandlers.*/ protected List<CollectionChangeHandler> handlers; /** The collection to be displayed.*/ protected Collection collection; /** The artifact that handles the parameterization.*/ protected Artifact artifact; protected TabSet tabs; /** The parameter tab.*/ protected Tab parameterTab; /** The output tab.*/ protected Map<String, OutputTab> outputTabs; /** The layout.*/ protected Layout layout; /** * This constructor creates a new CollectionView that is used to display the * <i>collection</i>. * * @param collection The collection to be displayed. */ public CollectionView(FLYS flys, Collection collection) { this.flys = flys; this.collection = collection; this.tabs = new TabSet(); this.parameterTab = new Tab(messages.winfo()); this.outputTabs = new HashMap<String, OutputTab>(); this.parameterList = new ParameterList(flys, this); this.handlers = new ArrayList<CollectionChangeHandler>(); this.layout = new VLayout(); addCollectionChangeHandler(this); parameterList.addParameterChangeHandler(this); parameterList.addParameterChangeHandler(parameterList); init(); } /** * This method handles the initial layout stuff. */ protected void init() { setWidth(700); setHeight(600); layout.setWidth100(); setCanDragReposition(true); setCanDragResize(true); setKeepInParentRect(true); DateTimeFormat dtf = DateTimeFormat.getFormat(messages.date_format()); String lastAccess = dtf.format(collection.getLastAccess()); setTitle(lastAccess + " - " + collection.getName()); addItem(layout); layout.addMember(tabs); tabs.addTab(parameterTab); tabs.setTabTitle(0, messages.new_calculation()); tabs.updateTab(0, parameterList); } /** * This method triggers the CreateCollectionService to create a new * collection in the artifact server. * * @param ownerId The uuid of the user that should own the new collection. */ protected void createNewCollection(String ownerId) { Config config = Config.getInstance(); final String serverUrl = config.getServerUrl(); createCollectionService.create( serverUrl, ownerId, new AsyncCallback<Collection>() { public void onFailure(Throwable caught) { GWT.log("Could not create the new collection."); GWT.log(caught.getMessage()); } public void onSuccess(Collection collection) { GWT.log("Successfully created a new collection."); Artifact artifact = getArtifact(); addArtifactService.add(collection, artifact, serverUrl, new AsyncCallback<Collection>() { public void onFailure(Throwable caught) { GWT.log("An error occured while adding artifact."); GWT.log(caught.getMessage()); } public void onSuccess(Collection newCollection) { GWT.log("Successfully added artifact."); setCollection(newCollection); } } ); } }); } protected FLYS getFlys() { return flys; } /** * This method registers a new ValueChangeHandler. * * @param handler The new ValueChangeHandler. */ public void addCollectionChangeHandler(CollectionChangeHandler handler) { if (handler != null) { handlers.add(handler); } } /** * This method calls the <code>onValueChange()</code> method of all * registered ValueChangeHanders. */ protected void fireCollectionChangeEvent( Collection old, Collection newCol) { for (CollectionChangeHandler handler: handlers) { handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); } } /** * This method returns true, if the Collection is new and no plugins has * been chosen. * * @return true, if the Collection is new. */ public boolean isNew() { return collection.getItemLength() == 0 ? true : false; } /** * Returns the artifact that is used for the parameterization. * * @return the artifact that is used for the parameterization. */ protected Artifact getArtifact() { return artifact; } /** * Set the current artifact that is the master of the parameterization. * * @param artifact The new artifact. */ protected void setArtifact(Artifact artifact) { this.artifact = artifact; } /** * Implements the onCollectionChange() method to do update the GUI after the * parameterization has changed. * * @param event The ParameterChangeEvent. */ public void onParameterChange(ParameterChangeEvent event) { GWT.log("Parameter have changed."); Artifact art = event.getNewValue(); ArtifactDescription desc = art.getArtifactDescription(); OutputMode[] outs = desc.getOutputModes(); setArtifact(art); if (outs != null) { User user = getFlys().getCurrentUser(); createNewCollection(user.identifier()); } else { clearOutputTabs(); updateView(); } } /** * Returns the collection of displayed by this view. * * @return the collection of this view. */ protected Collection getCollection() { return collection; } /** * Set the current collection. * * @param collection The new collection. */ protected void setCollection(Collection collection) { Collection tmp = this.collection; this.collection = collection; fireCollectionChangeEvent(tmp, this.collection); } public void onCollectionChange(CollectionChangeEvent event) { Collection newCol = event.getNewValue(); Map<String, OutputMode> outs = newCol.getOutputModes(); Set<String> keys = outs.keySet(); for (String outname: keys) { addOutputTab(outname, outs.get(outname)); } updateView(); } /** * Adds a new tab for the OutputMode <i>out</i>. * * @param name The name and title of the output. */ protected void addOutputTab(String name, OutputMode out) { GWT.log("Add new output tab for '" + name + "'"); // TODO Source this out to a factory that creates the different // OutputTabs. OutputTab tab = new ChartOutputTab(name, getCollection(), out); outputTabs.put(name, tab); } /** * Removes all output mode tabs from tab bar. */ protected void clearOutputTabs() { GWT.log("Clear OutputTabs."); int num = tabs.getNumTabs(); for (int i = num-1; i >= 1; i--) { tabs.removeTab(i); } outputTabs.clear(); } /** * Update the view (refresh the list of old and current data). */ protected void updateView() { GWT.log("CollectionView.updateView()"); updateOutputTabs(); } /** * This method is used to update the tabs to show specific output modes. */ protected void updateOutputTabs() { GWT.log("Update output tabs."); if (outputTabs != null) { Set<String> keys = outputTabs.keySet(); for (String key: keys) { tabs.addTab(outputTabs.get(key)); } } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :