View Javadoc

1   package org.ximtec.igesture.tool.view.devicemanager.action;
2   
3   import java.awt.event.ActionEvent;
4   import java.io.File;
5   
6   import javax.swing.JButton;
7   import javax.swing.JFileChooser;
8   
9   import org.sigtec.graphix.widget.BasicAction;
10  import org.ximtec.igesture.tool.GestureConstants;
11  import org.ximtec.igesture.tool.service.GuiBundleService;
12  import org.ximtec.igesture.tool.util.FileType;
13  import org.ximtec.igesture.tool.view.devicemanager.DeviceManagerController;
14  
15  /**
16   * Action to save the user-device configuration to file. It extends {@link org.sigtec.graphix.widget.BasicAction}.
17   * @author Bjorn Puype, bpuype@gmail.com
18   *
19   */
20  public class SaveDeviceConfigurationAction extends BasicAction {
21  
22  	private DeviceManagerController controller;
23  	
24  	public SaveDeviceConfigurationAction(DeviceManagerController controller)
25  	{
26  		super(GestureConstants.SAVE_DEVICE_CONFIGURATION, controller.getLocator().getService(
27  	            GuiBundleService.IDENTIFIER, GuiBundleService.class));
28  		this.controller = controller;
29  	}
30  	
31  	@Override
32  	public void actionPerformed(ActionEvent e) {
33  		
34  		JFileChooser fileChooser = new JFileChooser();
35  	    fileChooser.setFileFilter(FileType.deviceConfiguration.getFilter());
36  	    if(fileChooser.showSaveDialog((JButton) e.getSource())==JFileChooser.APPROVE_OPTION)
37  	    {
38  		    File selectedFile = fileChooser.getSelectedFile();
39  		
40  		    if (selectedFile != null) {
41  		      controller.saveConfiguration(selectedFile);
42  		    }
43  	    }
44  	}
45  
46  }