001package csheets.ext.simple.ui; 002 003import java.awt.event.ActionEvent; 004 005import javax.swing.JOptionPane; 006 007import csheets.ui.ctrl.BaseAction; 008import csheets.ui.ctrl.UIController; 009 010/** 011 * An action of the simple extension that exemplifies how to interact with the spreadsheet. 012 * @author Alexandre Braganca 013 */ 014public class ExampleAction extends BaseAction { 015 016 /** The user interface controller */ 017 protected UIController uiController; 018 019 /** 020 * Creates a new action. 021 * @param uiController the user interface controller 022 */ 023 public ExampleAction(UIController uiController) { 024 this.uiController = uiController; 025 } 026 027 protected String getName() { 028 return "Example..."; 029 } 030 031 protected void defineProperties() { 032 } 033 034 /** 035 * A simple action that presents a confirmation dialog. 036 * If the user confirms then the contents of the cell A1 of the current sheet are set to the string "Changed". 037 * @param event the event that was fired 038 */ 039 public void actionPerformed(ActionEvent event) { 040 041 // Lets user select a font 042 int result=JOptionPane.showConfirmDialog(null, "You have selected the Example option. Do you want to set cell A1 to 'Changed'"); 043 044 if (result==JOptionPane.YES_OPTION) { 045 // Vamos exemplificar como se acede ao modelo de dominio (o workbook) 046 try { 047 this.uiController.getActiveSpreadsheet().getCell(0, 0).setContent("Changed"); 048 } catch (Exception ex) { 049 // para ja ignoramos a excepcao 050 } 051 } 052 } 053}