pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gk_br...@verizon.net>
Subject Re: Binding Issues (converting from 1.5 to 2.0)
Date Mon, 08 Aug 2011 14:25:42 GMT
One thing I see is that you are calling setImage() in a TaskListener. You should wrap that
in a TaskAdapter since you are calling into the UI from a background thread.

On Aug 8, 2011, at 10:08 AM, B.L. Zeebub wrote:

> Ok, I'm slowly getting there.
> 
> I've now got the bindable interface working - partially. The initialize()
> method is being called and my ImageViews are being populated and displayed.
> However, if I change the image in my ImageView, this is not being reflected
> in the display. Similarly, I've got a List<LogEvent> messages assigned to a
> TableView but as I add to the list, the table view is not updating. What
> have I missed now?
> 
> Regards
> 
> <example:Example title="Genesis Client" maximized="true"
> styles="{showWindowControls:false}"
> 	 	xmlns:bxml="http://pivot.apache.org/bxml"
>    	xmlns:example="com.blackbox.x.client"
>        xmlns="org.apache.pivot.wtk">
> 
> 		<Border styles="{color:10, cornerRadii:20}">
> 		
> 				<TablePane>
> 					<columns>
> 						<TablePane.Column />
> 					</columns>
> 					<rows>
> 					<TablePane.Row>
> 					<Border>
> 		
> 					<BoxPane orientation="horizontal" >
> 					<ImageView bxml:id="car" styles="{verticalAlignment:'center'}"/>
> 					<ImageView bxml:id="vci_status" styles="{verticalAlignment:'bottom'}"/>
> 					<ImageView bxml:id="pc" styles="{verticalAlignment:'center'}"/>
> 					<ImageView bxml:id="pc_status" styles="{verticalAlignment:'bottom'}"/>
> 					<ImageView bxml:id="server" styles="{verticalAlignment:'center'}"/>
> 					</BoxPane>
> 			
> 					</Border>
> 					</TablePane.Row>
> 					<TablePane.Row> 
> 					<Border>
> 				
> 					<BoxPane orientation="horizontal">
> 					<ImageView bxml:id="rx" />
> 					<ImageView bxml:id="tx" />
> 					</BoxPane>
> 			
> 					</Border>
> 					</TablePane.Row>
> 					
> 						<TablePane.Row height="300">
> 							<Border>
> 							
> 									<ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
> 										<view>
> 											<TableView bxml:id="tv" selectMode="single">
> 												<columns>
> 													<TableView.Column name="message" width="800"
> 														headerData="Header" />
> 												</columns>
> 											</TableView>
> 										</view>
> 									</ScrollPane>
> 								
> 							</Border>
> 						</TablePane.Row>
> 						<TablePane.Row> 
> 							<Border>
> 							
> 								<ActivityIndicator bxml:id="activityIndicator"
> 									preferredWidth="24" preferredHeight="24" />
> 									
> 							</Border>
> 						</TablePane.Row>
> 					</rows>
> 				</TablePane> 
> 			
> 		</Border>
> </example:Example>
> 
> public class Example extends Frame implements Application,
> MessageBusListener, Bindable,Serializable {
> 
> 	private static String host;
> 	private static String port;
> 	private Window window;
> 	private Display display;
> 	private GenesisClient service;
> 	private List<LogEvent> messages = new ArrayList<LogEvent>();
> 	@BXML private ActivityIndicator activityIndicator = new
> ActivityIndicator();
> 	@BXML private ImageView tx = new ImageView();
> 	@BXML private ImageView rx = new ImageView();
> 	@BXML private ImageView car = new ImageView();
> 	@BXML private ImageView vci_status = new ImageView();
> 	@BXML private ImageView pc = new ImageView();
> 	@BXML private ImageView pc_status = new ImageView();
> 	@BXML private ImageView server = new ImageView();
> 	@BXML private TableView tv = new TableView();
> 	private static String TX_ON = "/com/blackbox/x/client/images/TxOn.png";
> 	private static String RX_ON = "/com/blackbox/x/client/images/RxOn.png";
> 	private static String TX_OFF = "/com/blackbox/x/client/images/TxOff.png";
> 	private static String RX_OFF = "/com/blackbox/x/client/images/RxOff.png";
> 	private static String CAR =
> "/com/blackbox/x/client/images/transportation_car_32.png";
> 	private static String VCI_STATUS_OFF =
> "/com/blackbox/x/client/images/cross.png";
> 	private static String VCI_STATUS_ON =
> "/com/blackbox/x/client/images/tick.png";
> 	private static String PC = "/com/blackbox/x/client/images/generic_pc.png";
> 	private static String PC_STATUS_OFF =
> "/com/blackbox/x/client/images/cross.png";
> 	private static String PC_STATUS_ON =
> "/com/blackbox/x/client/images/tick.png";
> 	private static String SERVER =
> "/com/blackbox/x/client/images/redhat_network_server.png";
> 
> 	private String VERSION ="Pivot Client : Version 0.95.0.3";
> 	
> 	private static final Logger logger = Logger
> 	.getLogger(Example.class.getName());
> 	
> 	public void resume() throws Exception {
> 	
> 
> 	}
> 	
> 
> 	public boolean shutdown(boolean optional) throws Exception {
> 		if (window != null) {
> 			window.close();
> 		}
> 		return false;
> 	}
> 
> 	@SuppressWarnings("unchecked")
> 	public void startup(final Display display, Map&lt;String, String&gt;
> properties)
> 			throws Exception {
> 		
> 		this.display = display;
> 		
> 		registerEventListeners();
> 		
> 		BXMLSerializer wtkxSerializer = new BXMLSerializer();
> 		window = (Window) wtkxSerializer.readObject(Example.class,
> "Example.wtkx");
> 
> 		window.open(display);
> 		
> 		TaskListener<String>  taskListener = new TaskListener<String>() {
>            public void taskExecuted(Task<String> task) {
>            	activityIndicator.setActive(false);
>            	
> 					vci_status.setImage(VCI_STATUS_ON);
> 					window.setEnabled(true);	                       
>            }
> 
>            public void executeFailed(Task<String> task) {
> //            	activityIndicator.setActive(false);
>            	window.setEnabled(true);
>            	Exception e = (Exception) task.getFault().getCause();
>            	if (e instanceof VciNotFoundException) {
>            	Alert.alert(MessageType.ERROR,"No VCI device found. Please
> check that your"
>     	        		+ " Vci device is connected securely to your car and PC.
> Please ensure that the" 
>     	        		+ " ignition is turned on and re-try running this program.",
> window, new DialogCloseListener()
> 				 {
> 
>    				public void dialogClosed(Dialog dialog, boolean modal) {
>    						try {
>    							display.getHostWindow().dispose();
>    							shutdown(true);
>    							
>    						} catch (Exception e) {
>    							e.printStackTrace();
>    						}
>    					
>    				}
>    		
>    				
>    			});
>            	}
>            	
>            	
>            }
>        };
> //activityIndicator.setActive(true);
> window.setEnabled(false);
> new ClientTask().execute(new TaskAdapter<String>(taskListener));
> 		
> 
> 	}
> 
> 
> 	@SuppressWarnings("unchecked")
> 	private void registerEventListeners() {
> 		MessageBus.subscribe(LogEvent.class, this);
> 		MessageBus.subscribe(DataWriteEvent.class, this);
> 		MessageBus.subscribe(DataReadEvent.class, this);
> 		MessageBus.subscribe(ServerCloseEvent.class, this);
> 		MessageBus.subscribe(ErrorEvent.class, this);
> 		MessageBus.subscribe(ConnectEvent.class, this);
> 		MessageBus.subscribe(ContactEvent.class, this);
> 	}
> 
> 		
> 
> 	public void suspend() throws Exception {
> 		
> 
> 	}
> 
> 	public static void main(String[] args) {
> 		if (args[0] == null) {
> 			host = "localhost";
> 		
> 		} else {
> 			host = args[0];
> 		}
> 		DesktopApplicationContext.main(Example.class, args);
> 	}
> 	
> 	
> 	private void sleep(int interval) {
> 		
> 		try {
> 			Thread.sleep(interval);
> 		} catch (InterruptedException e) {
> 			
> 			e.printStackTrace();
> 		}
> 			}
> 	
> 
> 	private class ClientTask extends Task<String> {
> 
> 
> 		@Override
> 		public String execute() throws TaskExecutionException {
> 			messages.add(new LogEvent(VERSION));
> 			
> 			service = new GenesisClient(host);
> 			try {
> 				DataEventListener listener = new PivotDataEventListener();
> 				service.setListener(listener);
> 				
> 				service.start();
> 			} catch (IOException e) {
> 				logger.error("GenesisClient throws IOException during startup");
> 				} catch (VciNotFoundException e) {
> 				logger.error("GenesisClient cannot find Vci device during startup");
> 				throw new TaskExecutionException(e);		
> 			}
> 			return "Done";
> 		}
> 		
> 	}
> 
> 	public void messageSent(Object message) {
> 		
> 		if (message instanceof LogEvent) {
> 			messages.add((LogEvent) message);
> 			return;
> 		} 
> 		
> 		
> 		if (message instanceof ServerCloseEvent) {
> 			pc_status.setImage(PC_STATUS_OFF);
> 			Alert.alert(MessageType.ERROR,"The Faultmate Genesis server has closed
> the connection. ", window, new DialogCloseListener()
> 					 {
> 
> 				public void dialogClosed(Dialog dialog, boolean modal) {
> 						try {
> 							window.close();
> 							shutdown(true);
> 							
> 						} catch (Exception e) {
> 							e.printStackTrace();
> 						}
> 					
> 				}
> 		
> 				
> 			});
>        	    
>        }
> 		
> 		if (message instanceof ErrorEvent) {
> 			vci_status.setImage(VCI_STATUS_OFF);
> 			Alert.alert(MessageType.ERROR,((ErrorEvent) message).getMessage(),
> window, new DialogCloseListener()
> 					 {
> 
> 				public void dialogClosed(Dialog dialog, boolean modal) {
> 						try {
> 							window.close();
> 							shutdown(true);
> 						} catch (Exception e) {
> 							e.printStackTrace();
> 						}
> 					
> 				}
> 		
> 				
> 			});
> 
> 		}
> 		
> 		if (message instanceof ContactEvent) {
> 			vci_status.setImage(VCI_STATUS_OFF);
> 			messages.add(new LogEvent(((ContactEvent) message).getMessage()));
> 			Alert.alert(MessageType.ERROR,((ContactEvent) message).getMessage(),
> window, new DialogCloseListener()
> 					 {
> 
> 				public void dialogClosed(Dialog dialog, boolean modal) {
> 						try {
> 							window.close();
> 							shutdown(true);
> 							} catch (Exception e) {
> 							e.printStackTrace();
> 						}
> 					
> 				}
> 		
> 				
> 			});
> 
> 		}
> 		
> 		if (message instanceof ConnectEvent) {
> 			messages.add(new LogEvent(((ConnectEvent) message).getMessage()));
> 			if (((ConnectEvent) message).isConnected()) {
> 				pc_status.setImage(PC_STATUS_ON);
> 			} else {
> 				pc_status.setImage(PC_STATUS_OFF);
> 			}
> 		}
> 		
> 	}
> 	
> 
> 	@Override
> 	public void initialize(Map&lt;String, Object&gt; namespace, URL location,
> 			Resources resources) {
> 		messages = new ArrayList<LogEvent>();
> 		tv.setTableData(messages);
> 		/* Set the initial Modem light position */
> 		tx.setImage(TX_OFF);
> 		rx.setImage(RX_OFF);
> 		/* Set the initial "Connection" icon status.*/
> 		car.setImage(CAR);
> 		vci_status.setImage(VCI_STATUS_OFF);
> 		pc.setImage(PC);
> 		pc_status.setImage(PC_STATUS_OFF);
> 		server.setImage(SERVER);
> 
> 	}
> 
> 	
> 
> 	
> 	
> }
> 
> 
> 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3235662.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Mime
View raw message