1. #1
    Ext User
    Join Date
    Mar 2010
    Posts
    14
    Vote Rating
    0
    Maxiflo is on a distinguished road

      0  

    Default Refresh ListStore

    Refresh ListStore


    Hi everybody,

    First of all I present you my deepest apologies if the answer I'm looking forward is already on the forum. I've search for 2 hours now and I didn't be able to find it.

    I work with several grids in different panels, which contain cross data. The problem is when I change an object in a panel, it isn't updated in other grid stores, because of gwt cache control I think.

    My question is what should I do: unable gwt cache control (but only for stores if possible), or force store or grid (or both) refresh every time I select TabItem? And How can I do that?

    Thanks.

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    How are you updateing this model? You need to use BaseModel and you need to set monitoreChanges to true on all stores.

    But to correctly answer your question, i need to see a fully working testcase

  3. #3
    Ext User
    Join Date
    Mar 2010
    Posts
    14
    Vote Rating
    0
    Maxiflo is on a distinguished road

      0  

    Default


    Thanks for fast answer.

    I update my Bean like this:
    Code:
    private void updateLine(TypeManuel leType){
    		//on appelle le service
    		typeManuelService.updateTypeManuel(laConn,leType, new AsyncCallback<Boolean>() {
    			public void onFailure(Throwable caught) {
    				//on affiche un message d'alerte
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(Boolean result) {				
    				if(result){
    					//on supprime la ligne du grid
    					grid.getStore().commitChanges();
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					grid.getStore().rejectChanges();
    					MessageBox.alert("Erreur", "La modification a echoue.", null);
    				}
    			}			
    		});
    	}

  4. #4
    Ext User
    Join Date
    Mar 2010
    Posts
    14
    Vote Rating
    0
    Maxiflo is on a distinguished road

      0  

    Default


    Thanks for answer.

    There's my first panel:
    Code:
    package com.docmust.MCO.client;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    import com.docmust.MCO.Entity.Connexion;
    import com.docmust.MCO.Entity.TypeManuel;
    import com.docmust.MCO.Resources.classes.WorkIcons;
    import com.docmust.MCO.WebService.TypeManuelService;
    import com.docmust.MCO.WebService.TypeManuelServiceAsync;
    import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
    import com.extjs.gxt.ui.client.Style.Orientation;
    import com.extjs.gxt.ui.client.Style.SelectionMode;
    import com.extjs.gxt.ui.client.binding.FormBinding;
    import com.extjs.gxt.ui.client.data.BaseListLoader;
    import com.extjs.gxt.ui.client.data.BeanModel;
    import com.extjs.gxt.ui.client.data.BeanModelLookup;
    import com.extjs.gxt.ui.client.data.BeanModelReader;
    import com.extjs.gxt.ui.client.data.ListLoader;
    import com.extjs.gxt.ui.client.data.RpcProxy;
    import com.extjs.gxt.ui.client.event.ButtonEvent;
    import com.extjs.gxt.ui.client.event.Events;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.event.MenuEvent;
    import com.extjs.gxt.ui.client.event.MessageBoxEvent;
    import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
    import com.extjs.gxt.ui.client.event.SelectionListener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.store.Store;
    import com.extjs.gxt.ui.client.widget.ContentPanel;
    import com.extjs.gxt.ui.client.widget.Info;
    import com.extjs.gxt.ui.client.widget.MessageBox;
    import com.extjs.gxt.ui.client.widget.button.Button;
    import com.extjs.gxt.ui.client.widget.form.Field;
    import com.extjs.gxt.ui.client.widget.form.FormPanel;
    import com.extjs.gxt.ui.client.widget.form.TextField;
    import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
    import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
    import com.extjs.gxt.ui.client.widget.grid.Grid;
    import com.extjs.gxt.ui.client.widget.layout.RowData;
    import com.extjs.gxt.ui.client.widget.layout.RowLayout;
    import com.extjs.gxt.ui.client.widget.menu.Menu;
    import com.extjs.gxt.ui.client.widget.menu.MenuItem;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    import com.google.gwt.user.client.rpc.ServiceDefTarget;
    import com.google.gwt.user.client.ui.AbstractImagePrototype;
    
    @SuppressWarnings({"unchecked"})
    public class TypeManuelPanel extends ContentPanel {
    	
    	private FormBinding formBindings;
    	private TypeManuelServiceAsync typeManuelService;
    	private Grid grid;
    	private FormPanel panel;
    	private Connexion laConn;
    		
    	//constructeur de la liste
    	public TypeManuelPanel(Connexion vlaConn){		
    		
    		this.laConn = vlaConn;
    		
    		try{
    			//on parametre le panel
    			this.setFrame(true); 
    			this.setHeaderVisible(false);
    			this.setSize(798,425);
    			this.setLayout(new RowLayout(Orientation.HORIZONTAL));  
    			
    			// Creation et initialisation du proxy client permettant l’appel du service : TypeApp
    			// 1) Creation du stub
    			typeManuelService = (TypeManuelServiceAsync) GWT.create(TypeManuelService.class);
    			
    			// 2) Definir l’URL : elle doit appartenir au meme domaine que la page
    			ServiceDefTarget endpoint = (ServiceDefTarget) typeManuelService;
    			String moduleRelativeURL = GWT.getModuleBaseURL() + "TypeManuel";
    			endpoint.setServiceEntryPoint(moduleRelativeURL);
    			
    			//on instancie le grid
    			grid = this.createGrid();
    			grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
    		    grid.getSelectionModel().addListener(Events.SelectionChange,  
    		        new Listener<SelectionChangedEvent>() {
    					public void handleEvent(SelectionChangedEvent be) {						 
    				       if (be.getSelectedItem() != null) {				    	   
    				    	   formBindings.bind(be.getSelectedItem());
    				       }
    				       else {  
    				    	   formBindings.unbind();  
    				       }  				         
    					}		          
    		        });		    
    		    
    		   //on ajoute le grid au panel
    			this.add(grid, new RowData(.6, 1));
    			
    			//on instancie le formulaire
    			panel = createForm();  
    		    formBindings = new FormBinding(panel, true);  
    		    formBindings.setStore((Store) grid.getStore());  
    
    		    //on ajoute les boutons de comit et reset
    		    panel.setButtonAlign(HorizontalAlignment.LEFT);  
    		    panel.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
    		      @Override  
    		      public void componentSelected(ButtonEvent ce) {  
    		        grid.getStore().rejectChanges();  
    		        grid.getSelectionModel().deselectAll();
    		      }  
    		    }));  
    		    panel.addButton(new Button("Commit", new SelectionListener<ButtonEvent>() {  
    		      @Override  
    		      public void componentSelected(ButtonEvent ce) { 
    		    	  
    		    	  //on recupere le contenu du textField
    		    	  List<Field<?>> listFields = panel.getFields();
    		    	  
    		    	  //on verifie que les champs nécessaires sont bien remplis
    		    	  if(listFields.get(1).getRawValue().equals("") || listFields.get(2).getRawValue().equals("")){
    		    		  grid.getStore().rejectChanges();
    		    		  MessageBox.alert("Erreur", "Veuillez remplir tous les champs.", null);		    		  
    		    	  }  
    		    	  else{
    		    		  //on recupere le typeManuel
    			    	  TypeManuel newTypeManuel = new TypeManuel();
    			    	  newTypeManuel.setTypeManuel(listFields.get(1).getRawValue());
    		    		  newTypeManuel.setDtdElabAdoc(listFields.get(2).getRawValue());	    		  
    		    		  String id = listFields.get(0).getRawValue();   		  
    			    		  
    		    		  // cas d'un ajout
    			    	  if(id.equals("")){			    		  
    			    		  //on verifie que le type n'existe pas déja
    			    		  boolean b = exist(grid.getStore().getModels(),newTypeManuel);
    			    		  
    			    		  if(b){
    			    			  MessageBox.alert("Erreur", "Ce type existe deja.", null);
    			    			  grid.getStore().rejectChanges();
    			    		  }
    			    		  else{	  
    				    		  //on appelle la fonction d'ajout
    				    		  insertLine(newTypeManuel);		    		  
    			    		  }
    			    	  }
    			    	  //cas d'une modif
    			    	  else{
    			    		//on recup l'id
    			    		  newTypeManuel.setIdTypeManuel(Integer.valueOf(listFields.get(0).getRawValue()));
    			    		 
    			    		  //on appelle la fonction de modif
    			    		  updateLine(newTypeManuel);		    		  
    			    	  }
    		    	  }
    		    	  
    		      }  
    		    })); 		
    		    			
    			//on ajoute le formulaire
    		    this.add(panel, new RowData(.4, 1));  
    		    
    		}
    		catch(Exception ex){
    			System.out.println("Erreur.");
    			System.out.println(ex.getMessage());
    		}
    		
    		
    	}
    	
    	private Grid createGrid(){
    		
    		//on declare le grid
    		//on commence par les colonnes		
    		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
    		columns.add(new ColumnConfig("idTypeManuel", "Id du type manuel", 150));  
    		columns.add(new ColumnConfig("typeManuel", "Type du manuel", 150));  
    		columns.add(new ColumnConfig("dtdElabAdoc", "Dtd Adoc", 150));  
    		ColumnModel cm = new ColumnModel(columns);  
    		
    		// 2) on definit le proxy
    		// proxy and reader  
    		RpcProxy proxy = new RpcProxy() {  
    		  @Override  
    		  public void load(Object loadConfig, AsyncCallback callback) {  
    			  typeManuelService.getListOfTypeManuel(laConn,callback);			 
    		  }  
    		}; 	  	
    		
    		//on declare le reader et le loader
    		BeanModelReader reader = new BeanModelReader();  
    		ListLoader loader = new BaseListLoader(proxy, reader);  
    		final ListStore<BeanModel> store = new ListStore<BeanModel>(loader);		
    		store.setMonitorChanges(true);
    		
    		//on envoie la recuperation de la liste via RCP
    		loader.load();  
    		
    		//on declare le grid
    		grid = new Grid(store, cm);  
    		grid.setWidth(306);
    		grid.setHeight(400);
    		grid.setBorders(true);	
    				
    		//on declare le menu
    		Menu contextMenu = new Menu();  
    		
    		//on declare les icones
    		WorkIcons workIcon = (WorkIcons) GWT.create(WorkIcons.class);
    		AbstractImagePrototype.create(workIcon.add());
    			
    		//on ajoute le menu contextuel au grid
    		MenuItem insert = new MenuItem();  
    	     insert.setText("Insert Item");
    	     insert.setIcon(AbstractImagePrototype.create(workIcon.add()));
    	     insert.addSelectionListener(new SelectionListener<MenuEvent>() {  
    	         public void componentSelected(MenuEvent ce) {  
    	        	 	//on enleve le binding
    					formBindings.unbind();					
    					//on vide le formulaire
    					panel.clear();	 					
    					//on sort du grid
    					grid.getSelectionModel().deselectAll();
    	           }    
    	       });  
    	     
    	      contextMenu.add(insert);   
    		   
    	     MenuItem remove = new MenuItem();  
    	     remove.setText("Remove Selected");
    	     remove.setIcon(AbstractImagePrototype.create(workIcon.delete()));
    	     remove.addSelectionListener(new SelectionListener<MenuEvent>() {
    			public void componentSelected(MenuEvent ce) {
    				//on affiche le message de confirmation
    				MessageBox box = MessageBox.confirm("Confirmer la suppression", "Voulez vous supprimer cet enregistrement?",null);
    				box.addCallback(new Listener<MessageBoxEvent>() {					
    					public void handleEvent(MessageBoxEvent be) {
    						//si la suppression est confirmé
    						if(be.getButtonClicked().getText().equals("Yes")){
    							//on demande la suppression
    							deleteLine();				
    						}
    					}
    				});
    			}
    		 });
    	     
    	     contextMenu.add(remove);
    	     
    	     //et on lie le menu au grid
    	     grid.setContextMenu(contextMenu);
    			
    		return grid;
    	}
    	
    	/**
    	 * Methode qui créé le formulaire
    	 * 
    	 * @return
    	 */
    	private FormPanel createForm(){
    		
    		//on declare le formulaire
    		 FormPanel panel = new FormPanel();  
    		 panel.setHeaderVisible(false);
    		 
    		 //champs id
    		 TextField<String> idTypeManuel = new TextField<String>();  
    		 idTypeManuel.setName("idTypeManuel");  
    		 idTypeManuel.setFieldLabel("Id du Type Manuel");  
    		 idTypeManuel.setEnabled(false);
    		 panel.add(idTypeManuel);  
    		    
    		 // champs type
    		 TextField<String> typeManuel = new TextField<String>();  
    		 typeManuel.setName("typeManuel");  
    		 typeManuel.setFieldLabel("Type Manuel");  
    		 panel.add(typeManuel);
    		 
    		// champs dtd
    		 TextField<String> dtdElabAdoc = new TextField<String>();  
    		 dtdElabAdoc.setName("dtdElabAdoc");  
    		 dtdElabAdoc.setFieldLabel("Dtd Adoc");  
    		 panel.add(dtdElabAdoc);
    		 
    		 return panel;
    	}
    	
    	/**
    	 * Methode qui va supprimer la ligne sélectionnée
    	 */
    	private void deleteLine(){
    		
    		//on appelle le service
    		typeManuelService.deleteTypeManuel(laConn,(Integer)grid.getSelectionModel().getSelectedItem().get("idTypeManuel"), new AsyncCallback<Boolean>() {
    			public void onFailure(Throwable caught) {
    				//on affiche un message d'alerte
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(Boolean result) {				
    				if(result){
    					//on supprime la ligne du grid
    					grid.getStore().remove((BeanModel) grid.getSelectionModel().getSelectedItem());
    					panel.clear();
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					MessageBox.alert("Erreur", "La suppression a echoue.", null);
    				}
    			}			
    		});
    	}
    	
    	/**
    	 * Methode qui va ajouter une ligne
    	 * 
    	 * @param newTypeApp
    	 */
    	private void insertLine(TypeManuel newTypeManuel){		
    		typeManuelService.addTypeManuel(laConn,newTypeManuel, new AsyncCallback<TypeManuel>() {
    			public void onFailure(Throwable caught) {
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(TypeManuel result) {
    				//si l'ajout a fonctionné
    				if(result.getIdTypeManuel() != null){
    					//on ajoute la ligne du grid
    					grid.getStore().add(createModel(result));
    					int lastRow = grid.getStore().getCount() - 1;
    					grid.getSelectionModel().select(lastRow, false);
    					grid.getView().focusRow(lastRow);
    					Info.display("Done", "Operation succeed.");					
    				}
    				else{
    					//on affiche un message d'alerte
    					grid.getStore().rejectChanges();
    					MessageBox.alert("Erreur", "L'ajout a echoue.", null);
    				}
    			}
    		});
    		
    	}
    	
    	/**
    	 * Methode qui va modifier une ligne
    	 * 
    	 * @param leType
    	 */
    	private void updateLine(TypeManuel leType){
    		//on appelle le service
    		typeManuelService.updateTypeManuel(laConn,leType, new AsyncCallback<Boolean>() {
    			public void onFailure(Throwable caught) {
    				//on affiche un message d'alerte
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(Boolean result) {				
    				if(result){
    					//on supprime la ligne du grid
    					grid.getStore().commitChanges();
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					grid.getStore().rejectChanges();
    					MessageBox.alert("Erreur", "La modification a echoue.", null);
    				}
    			}			
    		});
    	}
    	
    	private boolean exist(List listeModels, TypeManuel typeManuel){
    		
    		boolean exist = false;
    		
    		//on boucle dans la liste
    		Iterator it = listeModels.iterator();		
    		while(it.hasNext()){
    			//on le met dans un objet
    			BeanModel bm = (BeanModel) it.next();			
    			TypeManuel leTypeToCompare = bm.getBean();
    			
    			//on compare les labels
    			if(typeManuel.equals(leTypeToCompare)){
    				exist = true;
    			}
    		}
    			
    		return exist;
    	}
    	
    	private BeanModel createModel(TypeManuel leType){		
    		return BeanModelLookup.get().getFactory(TypeManuel.class).createModel(leType);
    	}
    
    }
    And the second one, which use the first:
    Code:
    package com.docmust.MCO.client;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    
    import com.docmust.MCO.Entity.BaliseNonFermante;
    import com.docmust.MCO.Entity.Connexion;
    import com.docmust.MCO.Entity.TypeManuel;
    import com.docmust.MCO.Resources.classes.WorkIcons;
    import com.docmust.MCO.WebService.BaliseNonFermanteService;
    import com.docmust.MCO.WebService.BaliseNonFermanteServiceAsync;
    import com.docmust.MCO.WebService.TypeManuelService;
    import com.docmust.MCO.WebService.TypeManuelServiceAsync;
    import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
    import com.extjs.gxt.ui.client.Style.Orientation;
    import com.extjs.gxt.ui.client.Style.SelectionMode;
    import com.extjs.gxt.ui.client.binding.FormBinding;
    import com.extjs.gxt.ui.client.data.BaseListLoader;
    import com.extjs.gxt.ui.client.data.BeanModel;
    import com.extjs.gxt.ui.client.data.BeanModelLookup;
    import com.extjs.gxt.ui.client.data.BeanModelReader;
    import com.extjs.gxt.ui.client.data.ListLoader;
    import com.extjs.gxt.ui.client.data.RpcProxy;
    import com.extjs.gxt.ui.client.event.ButtonEvent;
    import com.extjs.gxt.ui.client.event.Events;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.event.MenuEvent;
    import com.extjs.gxt.ui.client.event.MessageBoxEvent;
    import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
    import com.extjs.gxt.ui.client.event.SelectionListener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.store.Store;
    import com.extjs.gxt.ui.client.widget.ContentPanel;
    import com.extjs.gxt.ui.client.widget.Info;
    import com.extjs.gxt.ui.client.widget.MessageBox;
    import com.extjs.gxt.ui.client.widget.button.Button;
    import com.extjs.gxt.ui.client.widget.form.Field;
    import com.extjs.gxt.ui.client.widget.form.FormPanel;
    import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
    import com.extjs.gxt.ui.client.widget.form.TextField;
    import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
    import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
    import com.extjs.gxt.ui.client.widget.grid.Grid;
    import com.extjs.gxt.ui.client.widget.layout.RowData;
    import com.extjs.gxt.ui.client.widget.layout.RowLayout;
    import com.extjs.gxt.ui.client.widget.menu.Menu;
    import com.extjs.gxt.ui.client.widget.menu.MenuItem;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    import com.google.gwt.user.client.rpc.ServiceDefTarget;
    import com.google.gwt.user.client.ui.AbstractImagePrototype;
    
    @SuppressWarnings("unchecked")
    public class BaliseNonFermantePanel extends ContentPanel {
    
    	private FormBinding formBindings;
    	private BaliseNonFermanteServiceAsync BaliseNonFermanteService;
    	private Grid grid;
    	private FormPanel panel;
    	private SimpleComboBox comboTypeManuel;
    	private Connexion laConn;
    		
    	//constructeur de la liste
    	public BaliseNonFermantePanel(Connexion vlaConn){
    		
    		this.laConn = vlaConn;
    		
    		try{
    			//on parametre le panel
    			this.setFrame(true); 
    			this.setHeaderVisible(false);
    			this.setSize(798,425);
    			this.setLayout(new RowLayout(Orientation.HORIZONTAL));  
    			
    			// Creation et initialisation du proxy client permettant l’appel du service : TypeApp
    			// 1) Creation du stub
    			BaliseNonFermanteService = (BaliseNonFermanteServiceAsync) GWT.create(BaliseNonFermanteService.class);
    			
    			// 2) Definir l’URL : elle doit appartenir au meme domaine que la page
    			ServiceDefTarget endpoint = (ServiceDefTarget) BaliseNonFermanteService;
    			String moduleRelativeURL = GWT.getModuleBaseURL() + "BaliseNonFermante";
    			endpoint.setServiceEntryPoint(moduleRelativeURL);
    			
    			//on instancie le grid
    			grid = this.createGrid();
    			grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);  
    		    grid.getSelectionModel().addListener(Events.SelectionChange,  
    		        new Listener<SelectionChangedEvent>() {
    					public void handleEvent(SelectionChangedEvent be) {						 
    				       if (be.getSelectedItem() != null) {	
    				    	  
    				    	   formBindings.bind(be.getSelectedItem());
    
    				    	   //on selectionne le bean du combobox
    				    	   BeanModel bm = (BeanModel) be.getSelectedItem().get("typeManuel");
    				    	   int j = comboTypeManuel.getStore().getModels().indexOf(bm);
    				    	   comboTypeManuel.setValue(comboTypeManuel.getStore().getAt(j));
    				       }
    				       else {  
    				    	   formBindings.unbind();  
    				       }  				         
    					}		          
    		        });		    
    		    
    		   //on ajoute le grid au panel
    			this.add(grid, new RowData(.6, 1));
    			
    			//on instancie le formulaire
    			panel = createForm();  
    		    formBindings = new FormBinding(panel, true);  
    		    formBindings.setStore((Store) grid.getStore());  
    
    		    //on ajoute les boutons de comit et reset
    		    panel.setButtonAlign(HorizontalAlignment.LEFT);  
    		    panel.addButton(new Button("Reset", new SelectionListener<ButtonEvent>() {  
    		      @Override  
    		      public void componentSelected(ButtonEvent ce) {  
    		        grid.getStore().rejectChanges();  
    		        grid.getSelectionModel().deselectAll();
    		      }  
    		    }));  
    		    panel.addButton(new Button("Commit", new SelectionListener<ButtonEvent>() {  
    		      @Override  
    		      public void componentSelected(ButtonEvent ce) { 
    		    	  
    		    	  //on recupere le contenu du textField
    		    	  List<Field<?>> listFields = panel.getFields();
    		    	  
    		    	  //on verifie que les champs nécessaires sont bien remplis
    		    	  if(listFields.get(1).getRawValue().equals("") || listFields.get(2).getRawValue().equals("")){
    		    		  grid.getStore().rejectChanges();
    		    		  MessageBox.alert("Erreur", "Veuillez remplir tous les champs.", null);		    		  
    		    	  }  
    		    	  else{
    		    		  //on recupere le BaliseNonFermante
    			    	  BaliseNonFermante newBaliseNonFermante = new BaliseNonFermante();
    			    	  newBaliseNonFermante.setNomBalise(listFields.get(1).getRawValue());
    			    	  
    			    	  //on recupere le TypeManuel
    			    	  BeanModel bm = (BeanModel) listFields.get(2).getValue();
    		    		  newBaliseNonFermante.setTypeManuel((TypeManuel) bm.getBean()); 		  
    		    		  String id = listFields.get(0).getRawValue();   		  
    			    		  
    		    		  // cas d'un ajout
    			    	  if(id.equals("")){			    		  
    			    		  //on verifie que le type n'existe pas déja
    			    		  boolean b = exist(grid.getStore().getModels(),newBaliseNonFermante);
    			    		  
    			    		  if(b){
    			    			  MessageBox.alert("Erreur", "Ce type existe deja.", null);
    			    			  grid.getStore().rejectChanges();
    			    		  }
    			    		  else{	  
    				    		  //on appelle la fonction d'ajout
    				    		  insertLine(newBaliseNonFermante);		    		  
    			    		  }
    			    	  }
    			    	  //cas d'une modif
    			    	  else{
    			    		  //on recup l'id
    			    		  newBaliseNonFermante.setIdBaliseNonFermante(Integer.valueOf(listFields.get(0).getRawValue()));
    			    		 
    			    		  //on appelle la fonction de modif
    			    		  updateLine(newBaliseNonFermante);		    		  
    			    	  }
    		    	  }
    		    	  
    		      }  
    		    })); 		
    		    			
    			//on ajoute le formulaire
    		    this.add(panel, new RowData(.4, 1));  
    		    
    		}
    		catch(Exception ex){
    			System.out.println("Erreur.");
    			System.out.println(ex.getMessage());
    		}
    		
    		
    	}
    	
    	private Grid createGrid(){
    		
    		//on declare le grid
    		//on commence par les colonnes		
    		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();  
    		columns.add(new ColumnConfig("idBaliseNonFermante", "Id du type manuel", 150));  
    		columns.add(new ColumnConfig("nomBalise", "Type du manuel", 150));  
    		columns.add(new ColumnConfig("typeManuel", "Dtd Adoc", 150));  
    		ColumnModel cm = new ColumnModel(columns);  
    		
    		// 2) on definit le proxy
    		// proxy and reader  
    		RpcProxy proxy = new RpcProxy() {  
    		  @Override  
    		  public void load(Object loadConfig, AsyncCallback callback) {  
    			  BaliseNonFermanteService.getListOfBaliseNonFermante(laConn,callback);			 
    		  }  
    		}; 	  	
    		
    		//on declare le reader et le loader
    		BeanModelReader reader = new BeanModelReader();  
    		ListLoader loader = new BaseListLoader(proxy, reader);  
    		final ListStore<BeanModel> store = new ListStore<BeanModel>(loader);		
    		store.setMonitorChanges(true);
    		
    		//on envoie la recuperation de la liste via RCP
    		loader.load();  
    		
    		//on declare le grid
    		grid = new Grid(store, cm);  
    		grid.setWidth(306);
    		grid.setHeight(400);
    		grid.setBorders(true);
    		grid.getView().refresh(false);
    				
    		//on declare le menu
    		Menu contextMenu = new Menu();  
    		
    		//on declare les icones
    		WorkIcons workIcon = (WorkIcons) GWT.create(WorkIcons.class);
    		AbstractImagePrototype.create(workIcon.add());
    			
    		//on ajoute le menu contextuel au grid
    		MenuItem insert = new MenuItem();  
    	     insert.setText("Insert Item");
    	     insert.setIcon(AbstractImagePrototype.create(workIcon.add()));
    	     insert.addSelectionListener(new SelectionListener<MenuEvent>() {  
    	         public void componentSelected(MenuEvent ce) {  
    	        	 	//on enleve le binding
    					formBindings.unbind();					
    					//on vide le formulaire
    					panel.clear();	 					
    					//on sort du grid
    					grid.getSelectionModel().deselectAll();
    	           }    
    	       });  
    	     
    	      contextMenu.add(insert);   
    		   
    	     MenuItem remove = new MenuItem();  
    	     remove.setText("Remove Selected");
    	     remove.setIcon(AbstractImagePrototype.create(workIcon.delete()));
    	     remove.addSelectionListener(new SelectionListener<MenuEvent>() {
    			public void componentSelected(MenuEvent ce) {
    				//on affiche le message de confirmation
    				MessageBox box = MessageBox.confirm("Confirmer la suppression", "Voulez vous supprimer cet enregistrement?",null);
    				box.addCallback(new Listener<MessageBoxEvent>() {					
    					public void handleEvent(MessageBoxEvent be) {
    						//si la suppression est confirmé
    						if(be.getButtonClicked().getText().equals("Yes")){
    							//on demande la suppression
    							deleteLine();				
    						}
    					}
    				});
    			}
    		 });
    	     
    	     contextMenu.add(remove);
    	     
    	     //et on lie le menu au grid
    	     grid.setContextMenu(contextMenu);
    			
    		return grid;
    	}
    	
    	/**
    	 * Methode qui créé le formulaire
    	 * 
    	 * @return
    	 */
    	private FormPanel createForm(){
    		
    		//on declare le formulaire
    		 FormPanel panel = new FormPanel();  
    		 panel.setHeaderVisible(false);
    		 
    		 //champs id
    		 TextField<String> idBaliseNonFermante = new TextField<String>();  
    		 idBaliseNonFermante.setName("idBaliseNonFermante");  
    		 idBaliseNonFermante.setFieldLabel("Id de la balise");  
    		 idBaliseNonFermante.setEnabled(false);
    		 panel.add(idBaliseNonFermante);  
    		    
    		 // champs type
    		 TextField<String> BaliseNonFermante = new TextField<String>();  
    		 BaliseNonFermante.setName("nomBalise");  
    		 BaliseNonFermante.setFieldLabel("Nom de la balise");  
    		 panel.add(BaliseNonFermante);
    		 
    		//----------------------------------------------------------------------
    		 //			CREATION DU COMBOBOX TYPE_MANUEL
    		 //---------------------------------------------------------------------
    		// Creation et initialisation du proxy client permettant l’appel du service : TypeManuel
    			// 1) Creation du stub
    		 final TypeManuelServiceAsync typeManuelService = (TypeManuelServiceAsync) GWT.create(TypeManuelService.class);
    			
    			// 2) Definir l’URL : elle doit appartenir au meme domaine que la page
    			ServiceDefTarget endpoint2 = (ServiceDefTarget) typeManuelService;
    			String moduleRelativeURL2 = GWT.getModuleBaseURL() + "TypeManuel";
    			endpoint2.setServiceEntryPoint(moduleRelativeURL2);
    			
    			//on recupere la liste des typeManuel
    			// 2) on definit le proxy
    			// proxy and reader  
    			RpcProxy proxy2 = new RpcProxy() {  
    			  @Override  
    			  public void load(Object loadConfig, AsyncCallback callback) {  
    				  typeManuelService.getListOfTypeManuel(laConn,callback);	 
    			  }  
    			}; 	  	
    			
    			//on declare le reader et le loader
    			BeanModelReader reader2 = new BeanModelReader();  
    			ListLoader loader2 = new BaseListLoader(proxy2, reader2);  
    			final ListStore<BeanModel> store2 = new ListStore<BeanModel>(loader2);		
    			store2.setMonitorChanges(true);
    						
    			//on envoie la recuperation de la liste via RCP
    			loader2.load();  
    			
    			//on instancie le combobox
    			comboTypeManuel = new SimpleComboBox();
    			comboTypeManuel.setFieldLabel("Type Manuel");
    			comboTypeManuel.setDisplayField("typeManuel");
    			comboTypeManuel.setStore(store2);
    			comboTypeManuel.setLazyRender(false);
    			comboTypeManuel.getView().refresh();
    			
    			//on l'ajoute au formulaire
    			panel.add(comboTypeManuel);
    		//---------------------------------------------------------------
    		 
    		 return panel;
    	}
    	
    	/**
    	 * Methode qui va supprimer la ligne sélectionnée
    	 */
    	private void deleteLine(){
    		
    		//on appelle le service
    		BaliseNonFermanteService.deleteBaliseNonFermante(laConn,(Integer)grid.getSelectionModel().getSelectedItem().get("idBaliseNonFermante"), new AsyncCallback<Boolean>() {
    			public void onFailure(Throwable caught) {
    				//on affiche un message d'alerte
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(Boolean result) {				
    				if(result){
    					//on supprime la ligne du grid
    					grid.getStore().remove((BeanModel) grid.getSelectionModel().getSelectedItem());
    					panel.clear();
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					MessageBox.alert("Erreur", "La suppression a echoue.", null);
    				}
    			}			
    		});
    	}
    	
    	/**
    	 * Methode qui va ajouter une ligne
    	 * 
    	 * @param newTypeApp
    	 */
    	private void insertLine(BaliseNonFermante newBaliseNonFermante){		
    		BaliseNonFermanteService.addBaliseNonFermante(laConn,newBaliseNonFermante, new AsyncCallback<BaliseNonFermante>() {
    			public void onFailure(Throwable caught) {
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(BaliseNonFermante result) {
    				//si l'ajout a fonctionné
    				if(result.getIdBaliseNonFermante() != null){
    					//on ajoute la ligne du grid
    					grid.getStore().add(createModel(result));
    					//on selectionne la ligne insérée
    					int lastRow = grid.getStore().indexOf(createModel(result));
    					grid.getSelectionModel().select(lastRow, false);
    					grid.getView().focusRow(lastRow);
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					grid.getStore().rejectChanges();
    					MessageBox.alert("Erreur", "L'ajout a echoue.", null);
    				}
    			}
    		});
    		
    	}
    	
    	/**
    	 * Methode qui va modifier une ligne
    	 * 
    	 * @param leType
    	 */
    	private void updateLine(BaliseNonFermante leType){
    		//on appelle le service
    		BaliseNonFermanteService.updateBaliseNonFermante(laConn,leType, new AsyncCallback<Boolean>() {
    			public void onFailure(Throwable caught) {
    				//on affiche un message d'alerte
    				MessageBox.alert("Erreur", "L'appel a echoue.", null);
    			}
    			public void onSuccess(Boolean result) {				
    				if(result){
    					//on effectue les changement
    					grid.getStore().commitChanges();
    					//on raffraichi le grid
    					grid.getStore().getLoader().load();
    					panel.clear();
    					Info.display("Done", "Operation succeed.");
    				}
    				else{
    					//on affiche un message d'alerte
    					grid.getStore().rejectChanges();
    					MessageBox.alert("Erreur", "La modification a echoue.", null);
    				}
    			}			
    		});
    	}
    	
    	private boolean exist(List listeModels, BaliseNonFermante BaliseNonFermante){
    		
    		boolean exist = false;
    		
    		//on boucle dans la liste
    		Iterator it = listeModels.iterator();		
    		while(it.hasNext()){
    			//on le met dans un objet
    			BeanModel bm = (BeanModel) it.next();			
    			BaliseNonFermante leTypeToCompare = bm.getBean();
    			
    			//on compare les labels
    			if(BaliseNonFermante.equals(leTypeToCompare)){
    				exist = true;
    			}
    		}
    			
    		return exist;
    	}
    	
    	private BeanModel createModel(BaliseNonFermante leType){		
    		return BeanModelLookup.get().getFactory(BaliseNonFermante.class).createModel(leType);
    	}
    
    }
    Is it enough?

  5. #5
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    That is not a testcase. You just copied your paplication code. Its far too big than i want to read over it.

Thread Participants: 1