You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by "B.L. Zeebub" <ro...@googlemail.com> on 2011/08/08 16:08:55 UTC

Binding Issues (converting from 1.5 to 2.0)

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.

Re: Binding Issues (converting from 1.5 to 2.0)

Posted by Greg Brown <gk...@verizon.net>.
Oh, OK.

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

> 
> 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.
> 
> If you mean the line at around 114 in the source, the tasklistener is
> wrapped in a TaskAdaptor at line 148 with 
> new ClientTask().execute(new TaskAdapter<String>(taskListener));
> 
> Regards
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3235758.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Binding Issues (converting from 1.5 to 2.0)

Posted by "B.L. Zeebub" <ro...@googlemail.com>.
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.

If you mean the line at around 114 in the source, the tasklistener is
wrapped in a TaskAdaptor at line 148 with 
new ClientTask().execute(new TaskAdapter<String>(taskListener));

Regards

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3235758.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Binding Issues (converting from 1.5 to 2.0)

Posted by Greg Brown <gk...@verizon.net>.
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.


Re: Binding Issues (converting from 1.5 to 2.0)

Posted by Greg Brown <gk...@verizon.net>.
Not sure if this is related, but it is a bit strange that your Frame implements Application. Generally you'll implement Application in one class (e.g. "MyApplication") and your main window in another class ("MyFrame"). MyApplication would then load my_frame.bxml, assign the return value to a member field, and open the frame.

On Aug 9, 2011, at 2:30 AM, B.L. Zeebub wrote:

> Ok, I've changed that. Debug now shows that at the line
> 
> window = (Window) wtkxSerializer.readObject(Example.class, "Example.wtkx"); 
> 
> before execution variable rx (for example) is null. During execution, the
> initialize() method is called and rx assumes a value, the initial image is
> assigned. After execution, rx is null again.
> 
> I'm obviously still doing something stupid, but I just can't see what.
> 
> 
> <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;
> 	@BXML private ImageView tx;
> 	@BXML private ImageView rx;
> 	@BXML private ImageView car;
> 	@BXML private ImageView vci_status;
> 	@BXML private ImageView pc;
> 	@BXML private ImageView pc_status;
> 	@BXML private ImageView server;
> 	@BXML private TableView tv;
> 	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) {
> 		
> 		this.tv.setTableData(this.messages);
> 		/* Set the initial Modem light position */
> 		this.tx.setImage(TX_OFF);
> 		this.rx.setImage(RX_OFF);
> 		/* Set the initial "Connection" icon status.*/
> 		this.car.setImage(CAR);
> 		this.vci_status.setImage(VCI_STATUS_OFF);
> 		this.pc.setImage(PC);
> 		this.pc_status.setImage(PC_STATUS_OFF);
> 		this.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-tp3235662p3238026.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Binding Issues (converting from 1.5 to 2.0)

Posted by Chris Bartlett <cb...@gmail.com>.
Roger,

Can you please try to make a SSCCE (http://sscce.org), zip it up and
post to the list.  It will enable us to try to help without requiring
additional effort just to make the example work, and in many cases
merely creating the SSCCE can lead to the identification of the
underlying problem.

Just have a minimal BXML file - just a Window, maybe a BoxPane or
something and then your ImageView.  Have a small class that implements
Bindable with the @BXML annotation on the ImageView field, and see if
you can replicate the problems you are seeing.

If you can replicate the problem, we can investigate it easily.  If
you can't replicate it, it will give you something to work with to
figure out what is wrong in your 'real' code.

Chris

On 9 August 2011 13:30, B.L. Zeebub <ro...@googlemail.com> wrote:
> Ok, I've changed that. Debug now shows that at the line
>
> window = (Window) wtkxSerializer.readObject(Example.class, "Example.wtkx");
>
> before execution variable rx (for example) is null. During execution, the
> initialize() method is called and rx assumes a value, the initial image is
> assigned. After execution, rx is null again.
>
> I'm obviously still doing something stupid, but I just can't see what.
>
>
> <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;
>        @BXML private ImageView tx;
>        @BXML private ImageView rx;
>        @BXML private ImageView car;
>        @BXML private ImageView vci_status;
>        @BXML private ImageView pc;
>        @BXML private ImageView pc_status;
>        @BXML private ImageView server;
>        @BXML private TableView tv;
>        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) {
>
>                this.tv.setTableData(this.messages);
>                /* Set the initial Modem light position */
>                this.tx.setImage(TX_OFF);
>                this.rx.setImage(RX_OFF);
>                /* Set the initial "Connection" icon status.*/
>                this.car.setImage(CAR);
>                this.vci_status.setImage(VCI_STATUS_OFF);
>                this.pc.setImage(PC);
>                this.pc_status.setImage(PC_STATUS_OFF);
>                this.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-tp3235662p3238026.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>

Re: Binding Issues (converting from 1.5 to 2.0)

Posted by "B.L. Zeebub" <ro...@googlemail.com>.
Ok, I've changed that. Debug now shows that at the line

window = (Window) wtkxSerializer.readObject(Example.class, "Example.wtkx"); 

before execution variable rx (for example) is null. During execution, the
initialize() method is called and rx assumes a value, the initial image is
assigned. After execution, rx is null again.

I'm obviously still doing something stupid, but I just can't see what.


<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;
	@BXML private ImageView tx;
	@BXML private ImageView rx;
	@BXML private ImageView car;
	@BXML private ImageView vci_status;
	@BXML private ImageView pc;
	@BXML private ImageView pc_status;
	@BXML private ImageView server;
	@BXML private TableView tv;
	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) {
		
		this.tv.setTableData(this.messages);
		/* Set the initial Modem light position */
		this.tx.setImage(TX_OFF);
		this.rx.setImage(RX_OFF);
		/* Set the initial "Connection" icon status.*/
		this.car.setImage(CAR);
		this.vci_status.setImage(VCI_STATUS_OFF);
		this.pc.setImage(PC);
		this.pc_status.setImage(PC_STATUS_OFF);
		this.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-tp3235662p3238026.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Binding Issues (converting from 1.5 to 2.0)

Posted by Greg Brown <gk...@verizon.net>.
Don't do this:

@BXML private ImageView tx = new ImageView();

Do this:

@BXML private ImageView tx;

The value of these fields will be set by injection, so any value you initialize them with will be overwritten by the load process.

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

> Sticking a debugger on example.java shows that the instance of, for example
> ImageView tx before the binding initialize() method is the same as the tx
> instance after the binding initialize() is called, but it is not the same as
> the tx instance used in the initialize() method itself. So I'm guessing that
> the reason that I'm  not seeing any changes is that the instances that I'm
> working on are not the instances that are used in the BXML binding - if that
> makes sense.
> 
> For what started out to be a simple question as to how to close a
> java.awt.Window object - this is starting to get a PITA :)
> 
> Any clues anyone?
> 
> Regards
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3235723.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Binding Issues (converting from 1.5 to 2.0)

Posted by "B.L. Zeebub" <ro...@googlemail.com>.
Sticking a debugger on example.java shows that the instance of, for example
ImageView tx before the binding initialize() method is the same as the tx
instance after the binding initialize() is called, but it is not the same as
the tx instance used in the initialize() method itself. So I'm guessing that
the reason that I'm  not seeing any changes is that the instances that I'm
working on are not the instances that are used in the BXML binding - if that
makes sense.

For what started out to be a simple question as to how to close a
java.awt.Window object - this is starting to get a PITA :)

Any clues anyone?

Regards

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Binding-Issues-converting-from-1-5-to-2-0-tp3235662p3235723.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.