Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAchim Loerke2012-03-14 13:26:36 -0400
committerAchim Loerke2012-03-14 13:26:36 -0400
commit5d3415ac9bd4d03662f75bafbd4439587e566455 (patch)
treeeda5989b52a4935d7943a7ace59551367a77cc21 /org.eclipse.jubula.examples.aut.dvdtool
parentb484e1ab2b682ade41369f5086e5afc6fc650245 (diff)
downloadorg.eclipse.jubula.core-5d3415ac9bd4d03662f75bafbd4439587e566455.tar.gz
org.eclipse.jubula.core-5d3415ac9bd4d03662f75bafbd4439587e566455.tar.xz
org.eclipse.jubula.core-5d3415ac9bd4d03662f75bafbd4439587e566455.zip
removed V2 from classname
Diffstat (limited to 'org.eclipse.jubula.examples.aut.dvdtool')
-rw-r--r--org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdAddCategoryAction.java123
-rw-r--r--org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdMainFrameController.java8
2 files changed, 127 insertions, 4 deletions
diff --git a/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdAddCategoryAction.java b/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdAddCategoryAction.java
index de38f489f..5d12a98ea 100644
--- a/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdAddCategoryAction.java
+++ b/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdAddCategoryAction.java
@@ -10,6 +10,20 @@
*******************************************************************************/
package org.eclipse.jubula.examples.aut.dvdtool.control;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+
+import org.eclipse.jubula.examples.aut.dvdtool.DevelopmentState;
+import org.eclipse.jubula.examples.aut.dvdtool.model.DvdCategory;
+import org.eclipse.jubula.examples.aut.dvdtool.resources.Resources;
+
/**
* This is the action class for adding a category
@@ -18,6 +32,13 @@ package org.eclipse.jubula.examples.aut.dvdtool.control;
*/
public class DvdAddCategoryAction extends DvdAbstractDialogAction {
+ /** simulated version state */
+ private static boolean isVersion1 = DevelopmentState.instance().isV1();
+ /** simulated version state */
+ private static boolean isVersion2 = DevelopmentState.instance().isV2();
+ /** simulated version state */
+ private static boolean isVersion3 = DevelopmentState.instance().isV3();
+
/** the controller of the main frame */
private transient DvdMainFrameController m_controller; // see findBugs
@@ -40,4 +61,106 @@ public class DvdAddCategoryAction extends DvdAbstractDialogAction {
// add a category to current selection of the tree
m_controller.addCategory(inputValue);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (isVersion1 || isVersion2 || isVersion3) {
+ final JTextField textField = new JTextField(30);
+
+ final JButton okButton =
+ new JButton(Resources.getString("new.category.input.okLabel")); //$NON-NLS-1$
+ okButton.setName("new.category.input.okButton"); //$NON-NLS-1$
+ JButton cancelButton =
+ new JButton(Resources.getString("new.category.input.cancelLabel")); //$NON-NLS-1$
+ cancelButton.setName("new.category.input.cancelButton"); //$NON-NLS-1$
+ Object[] buttons = { okButton, cancelButton };
+
+ addValidator(textField, okButton);
+ // Create an array of the text and components to be displayed.
+ Object[] array = {
+ Resources.getString("new.category.input.message"), //$NON-NLS-1$
+ textField };
+
+ final JOptionPane pane = new JOptionPane(array,
+ JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION,
+ null, buttons);
+ final JDialog dialog = pane.createDialog(
+ m_controller.getDvdMainFrame(),
+ Resources.getString("new.category.input.message")); //$NON-NLS-1$
+ okButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pane.setValue(textField.getText());
+ dialog.setVisible(false);
+ }
+ });
+ okButton.setEnabled(false);
+ cancelButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pane.setValue(null);
+ dialog.setVisible(false);
+ }
+ });
+
+ dialog.setVisible(true);
+ Object selectedValue = pane.getValue();
+ if (selectedValue instanceof String
+ && ((String) selectedValue).trim().length() != 0) {
+ handleDialogInput((String) selectedValue);
+ }
+ } else {
+ super.actionPerformed(e);
+ }
+ }
+
+ /**
+ * adds validation code to the textfield
+ * @param textField checked field
+ * @param okButton will be disabled if validation fails
+ */
+ private void addValidator(final JTextField textField,
+ final JButton okButton) {
+ textField.addKeyListener(new KeyListener() {
+ public void keyReleased(KeyEvent ev) {
+ if (!okButton.isDefaultButton()) {
+ okButton.getRootPane().setDefaultButton(okButton);
+ }
+ String newCatName = textField.getText();
+ final boolean empty = newCatName.trim().length() == 0;
+ okButton.setEnabled(!empty);
+
+ if (isVersion2 || isVersion3) {
+ if (!empty) {
+ DvdCategory root = DvdManager.singleton()
+ .getRootCategory();
+ okButton.setEnabled(!categoryExists(root,
+ newCatName));
+ }
+ }
+ }
+
+ private boolean categoryExists(DvdCategory cat,
+ String newCatName) {
+ if (cat.getName().equals(newCatName)) {
+ return true;
+ }
+ for (DvdCategory child : cat.getCategories()) {
+ if (categoryExists(child, newCatName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void keyTyped(KeyEvent ev) {
+ // nothing here
+ }
+
+ public void keyPressed(KeyEvent ev) {
+ // nothing here
+ }
+ });
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdMainFrameController.java b/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdMainFrameController.java
index b4f682fe9..494523a80 100644
--- a/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdMainFrameController.java
+++ b/org.eclipse.jubula.examples.aut.dvdtool/src/org/eclipse/jubula/examples/aut/dvdtool/control/DvdMainFrameController.java
@@ -82,8 +82,8 @@ public class DvdMainFrameController {
new DvdInfoAction(Resources.getString("menu.help.about"), this); //$NON-NLS-1$
/** the action for adding a category */
- private DvdAddCategoryActionV2 m_addCategoryAction =
- new DvdAddCategoryActionV2(Resources.getString("menu.edit.add.category"), this); //$NON-NLS-1$
+ private DvdAddCategoryAction m_addCategoryAction =
+ new DvdAddCategoryAction(Resources.getString("menu.edit.add.category"), this); //$NON-NLS-1$
/** the action for enabling a category */
private DvdDisableOrEnableCategoryAction m_enableCategoryAction =
@@ -262,7 +262,7 @@ public class DvdMainFrameController {
*/
public DvdMainFrameController() {
if (DevelopmentState.instance().isV2()) {
- m_addCategoryAction = new DvdAddCategoryActionV2(
+ m_addCategoryAction = new DvdAddCategoryAction(
Resources.getString("menu.edit.add.category"), this); //$NON-NLS-1$
}
@@ -658,7 +658,7 @@ public class DvdMainFrameController {
/**
* @return Returns the addCategoryAction.
*/
- public DvdAddCategoryActionV2 getAddCategoryAction() {
+ public DvdAddCategoryAction getAddCategoryAction() {
return m_addCategoryAction;
}

Back to the top