1 14 15 package wingset; 16 17 import org.wings.*; 18 import org.wings.border.SEmptyBorder; 19 import org.wings.event.SRenderEvent; 20 import org.wings.event.SRenderListener; 21 import org.wings.event.SInvalidLowLevelEventListener; 22 import org.wings.event.InvalidLowLevelEvent; 23 24 import java.awt.*; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 28 37 public class BackButtonExample extends WingSetPane { 38 private final SForm mainPanel = new SForm(); 39 private final SLabel epochLabel = new SLabel(); 40 private final SButton newEpochButton = new SButton("After changing mode, click here SEVERAL times generate browser history entries"); 41 42 private final SButton regularButton = new SButton("Regular button"); 43 private final SLabel regularButtonSignal = new SLabel("Regular button pressed"); 44 45 private final SButton virtualBackButton = new SButton("Virtual back button"); 46 private final SLabel virtualBackButtonSignal = new SLabel("Virtual back button pressed"); 47 48 private final SButton nonEpochedButton = new SButton("Non epoch-checked button"); 49 private final SLabel nonEpochedButtonSignal = new SLabel("Non epoch-checked button pressed"); 50 51 protected SComponent createExample() { 52 mainPanel.setLayout(new SFlowDownLayout()); 53 mainPanel.setPreferredSize(new SDimension("300px", null)); 54 mainPanel.setHorizontalAlignment(CENTER); 55 mainPanel.add(new SLabel("<html>wingS is able to handle browser back navigation in different ways<br><ul>" + 56 "<li><b>Default: </b>Drop requests from old views and just redisplay page</li>" + 57 "<li><b>Extended default: </b>Register a virtual \"back\" button and trigger this on back operations" + 58 "You can use this. i.e. to display a information message or for navigation purpose.</li>" + 59 "<li><b>Allow: </b>Allow & don't intercept back navigation. Modifications (i.e. clicks) on past pages will" + 60 "be ignored by default, but can be enabled via setEpochCheckEnabled() for selected components</li>" + 61 "</ul>" + 62 "<p>Below is some example to experiment with these different modes to handle back navigation")); 63 64 mainPanel.addRenderListener(new SRenderListener() { 65 public void startRendering(SRenderEvent e) { 66 epochLabel.setText("<html><p>Current epoch: <b>" + epochLabel.getParentFrame().getEventEpoch() + "</b><p>"); 67 } 68 69 public void doneRendering(SRenderEvent e) { 70 virtualBackButtonSignal.setVisible(false); 71 regularButtonSignal.setVisible(false); 72 nonEpochedButtonSignal.setVisible(false); 73 } 74 }); 75 76 virtualBackButton.addActionListener(new ActionListener () { 77 public void actionPerformed(ActionEvent e) { 78 virtualBackButtonSignal.setVisible(true); 79 } 80 }); 81 82 SPanel signalPanel = new SPanel(new SFlowLayout()); 83 signalPanel.add(virtualBackButtonSignal); 84 virtualBackButtonSignal.setBorder(new SEmptyBorder(10, 10, 10, 10)); 85 virtualBackButtonSignal.setBackground(Color.YELLOW); 86 virtualBackButtonSignal.setFont(new SFont(SFont.BOLD)); 87 virtualBackButtonSignal.setVisible(false); 88 89 signalPanel.add(regularButtonSignal); 90 regularButtonSignal.setBorder(new SEmptyBorder(10, 10, 10, 10)); 91 regularButtonSignal.setBackground(Color.GREEN); 92 regularButtonSignal.setFont(new SFont(SFont.BOLD)); 93 regularButtonSignal.setVisible(false); 94 95 signalPanel.add(nonEpochedButtonSignal); 96 nonEpochedButtonSignal.setBorder(new SEmptyBorder(10, 10, 10, 10)); 97 nonEpochedButtonSignal.setBackground(Color.GREEN); 98 nonEpochedButtonSignal.setFont(new SFont(SFont.BOLD)); 99 nonEpochedButtonSignal.setVisible(false); 100 mainPanel.add(signalPanel); 101 102 regularButton.setVisible(false); 103 nonEpochedButton.setVisible(false); 104 105 final SButtonGroup buttonGroup = new SButtonGroup(); 106 final SRadioButton postMode = new SRadioButton("<html><b>Default:</b> HTTP POST " + 107 "(Browsers present a 'repost form' query after submits. wingS can optionally identify back operations"); 108 final SRadioButton getMode = new SRadioButton("<html><b>Extended default:</b> HTTP GET mode (Browsers <i>don't</i> present" + 109 " a 'repost form' query. wingS <i>immediately</i> catches back operations and triggers virtual back button)"); 110 final SRadioButton getMode2 = new SRadioButton("<html><b>Allow:</b> HTTP GET mode and no page refresh on back navigation." + 111 "wingS doesn't catch back navigation and may allow manipulation on selected buttons. " + 112 "<br>Clicks on <b>regular</b> buttons lead to an <i>delayed</i> back button event." + 113 "<br>Clicks on <b>Not epoch-checked button</b> will be accepted."); 114 buttonGroup.add(postMode); 115 buttonGroup.add(getMode); 116 buttonGroup.add(getMode2); 117 postMode.setSelected(true); 118 mainPanel.add(postMode); 119 mainPanel.add(getMode); 120 mainPanel.add(getMode2); 121 122 buttonGroup.addActionListener(new ActionListener () { 123 public void actionPerformed(ActionEvent e) { 124 regularButton.setVisible(false); 125 nonEpochedButton.setVisible(false); 126 127 if (buttonGroup.getSelection() == postMode) { 128 mainPanel.setPostMethod(true); 129 mainPanel.getParentFrame().setNoCaching(true); 130 } else if (buttonGroup.getSelection() == getMode) { 131 mainPanel.setPostMethod(false); 132 mainPanel.getParentFrame().setNoCaching(true); 133 } else if (buttonGroup.getSelection() == getMode2) { 134 mainPanel.setPostMethod(false); 135 mainPanel.getParentFrame().setNoCaching(false); 136 nonEpochedButton.setEpochCheckEnabled(false); 138 postMode.setEpochCheckEnabled(false); 141 getMode.setEpochCheckEnabled(false); 142 getMode2.setEpochCheckEnabled(false); 143 mainPanel.setEpochCheckEnabled(false); 144 regularButton.setVisible(true); 145 nonEpochedButton.setVisible(true); 146 } 147 } 148 }); 149 150 mainPanel.add(epochLabel); 151 152 newEpochButton.addActionListener(new ActionListener () { 153 public void actionPerformed(ActionEvent e) { 154 mainPanel.reload(); } 156 }); 157 mainPanel.add(newEpochButton); 158 159 160 regularButton.addActionListener(new ActionListener () { 161 public void actionPerformed(ActionEvent e) { 162 regularButtonSignal.setVisible(true); 163 } 164 }); 165 mainPanel.add(regularButton); 166 167 nonEpochedButton.addActionListener(new ActionListener () { 168 public void actionPerformed(ActionEvent e) { 169 nonEpochedButtonSignal.setVisible(true); 170 } 171 }); 172 mainPanel.add(nonEpochedButton); 173 174 return mainPanel; 175 } 176 177 protected void initializePanel() { 178 super.initializePanel(); mainPanel.getParentFrame().setBackButton(virtualBackButton); 180 181 mainPanel.getParentFrame().addInvalidLowLevelEventListener(new SInvalidLowLevelEventListener() { 182 public void invalidLowLevelEvent(InvalidLowLevelEvent e) { 183 log.info("Invalid Low-Level event detected on "+e.getSource()); 184 } 185 }); 186 } 187 188 } 189 | Popular Tags |