3D PLM Enterprise Architecture

Webtop

The Portal DialogBox

The use of the Portal DialogBox component
Technical Article

Abstract

This article shows how to add a property page to a property sheet for a given workshop or workbench displayed in the Tools->Options dialog box.


What Is the DialogBox

The DialogBox component is a dialog which implements the default combinations of buttons and the layout described by the ergonomics rules. The buttons of the DialogBox are arranged in a left-to-right flow on the bottom of the dialog, and are right-justified. The DialogBox listens to default buttons and close the dialog when the Ok, Cancel, or Close button is pressed (This default implementation is disconnectable.)

The default buttons combinations are:

OK_CANCEL
Must be used:
OK_CANCEL_PREVIEW
Must be used when the user cannot see directly the result after modifying a parameter of the dialog box
OK_APPLY_CLOSE
Must be used when interactions inside the command are not "undo-able"
CLOSE
Must be used:

The DialogBox has the same functionalities than the CATDialog class, so you can use it as a simple Dialog (you can create components and add them), the DialogBox will furtermore create the buttons.

The CommandDialog and the CATletDialog extend this DialogBox, so all the following methods are also available for these classes.

[Top]

DialogBox Class Definition

package com.dassault_systemes.catweb.base.awt;

/**
 * Properties describing the type of buttons combination
 */
 public static final int OK_CANCEL = 0;
 public static final int OK_CANCEL_PREVIEW = 1;
 public static final int OK_APPLY_CLOSE = 2;
 public static final int CLOSE = 3;
/**
 * The actions command associated to default buttons
 */
 public static final String OK_CMD = "OK";
 public static final String CANCEL_CMD = "CANCEL";
 public static final String APPLY_CMD = "APPLY";
 public static final String PREVIEW_CMD = "PREVIEW";
 public static final String CLOSE_CMD = "CLOSE";

/**
 * Constructors
 */
 public DialogBox(Frame parent)
 public DialogBox(Frame parent,boolean modal)
 public DialogBox(Frame parent,String title)
 public DialogBox(Frame parent,String title, boolean modal)
 public DialogBox(Frame parent,String title, boolean modal, boolean useSettings)

/**
 * Sets the type of buttons combination display in the dialog
 * The possible combinations are OK_CANCEL, OK_CANCEL_PREVIEW, OK_APPLY_CLOSE and CLOSE
 */
 public void setButtonsCombination(int buttonsType)

/**
 * Creates a DialogButton with the label and the action command actionCmd,
 * and add it to the dialog at South-East
 */
 public Button addButton(String label, String actionCmd)

/**
 * Creates a DialogButton with the label and the action command actionCmd,
 * and add it to the dialog at South-East
 */
 public Button addRightButton(String label, String actionCmd)

/**
 * Creates a DialogButton with the label and the action command actionCmd,
 * and add it to the dialog at South-West
 */
 public Button addLeftButton(String label, String actionCmd)

/**
 * Returns the list of buttons of the DialogBox
 */
 public Button[] getButtons()

/**
 * Returns the button specified by its action command
 */
 public Button getButton(String actionCmd)

/**
 * Returns true if the Dialog Box listen to default commands in order to close dialog for action
 * OK, CANCEL or CLOSE.
 */
public boolean isListenDefaultCommands()

public void setListenDefaultCommand(boolean flag)

/**
 *Adds an ActionListener for buttons ActionEvent
 */
public void addButtonActionListener(ActionListener listener)

public void removeButtonActionListener(ActionListener listener)

[Top]

How to Use the DialogBox

This section explains:

[Top]

How to Create a CLOSE Dialog

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog Close");
dialog.setName("MyCloseDialog");

// --- specifies the buttons combination
dialog.setButtonsCombination(DialogBox.CLOSE);

// --- add component to the dialog
dialog.add(new Label("My Label"));

[Top]

How to Create an OK_CANCEL Dialog and Listen to the OK Button's ActionEvent

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog Ok-Cancel");

// --- specifies the OK_CANCEL button combination
dialog.setButtonsCombination(DialogBox.OK_CANCEL);

// --- subscribes to buttons ActionEvent
dialog.addButtonActionListener(this);
...
// ------------------------------------------------
// --- implementation of the actionPerformed method
public void actionPerformed(ActionEvent evt)
{
  if (DialogBox.OK_CMD.equals(evt.getActionCommand()))
  {
    // --- do your specific action
    System.out.println("Ok Button click");
  }
}

[Top]

How to Create an OK_CANCEL Dialog That Doesn't Listen to Button's ActionEvent

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog Ok-Cancel");

// --- specifies the OK_CANCEL button combination
dialog.setButtonsCombination(DialogBox.OK_CANCEL);

// --- subscribes to buttons ActionEvent
dialog.addButtonActionListener(this);

// --- DialogBox doesn't listen to default buttons and thus doesn't close alone the dialog
dialog.setListenDefaultCommand(false);
...
// ------------------------------------------------
// --- implementation of the actionPerformed method
public void actionPerformed(ActionEvent evt)
{
  if(DialogBox.OK_CMD.equals(evt.getActionCommand()))
  {
    // --- do your specific action
    System.out.println("Ok Button click");

    // --- close the dialog, because default implementation is disconnected
    dialog.dispose();
  }
  else if (DialogBox.CANCEL_CMD.equals(evt.getActionCommand()))
  {
    // --- cancel modification and close the dialog
    dialog.dispose();
  }
}

[Top]

How to Create an OK_CANCEL Dialog with a "default" Button on the Left

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog Ok-Cancel");

// --- specifies the OK_CANCEL button combination
dialog.setButtonsCombination(DialogBox.OK_CANCEL);
      

// --- add a button "Default" at left dialog.addLeftButton("Default", "DefaultAction");

// --- subscribe to buttons ActionEvent dialog.addButtonActionListener(this); ... // ------------------------------------------------ // --- implementation of the actionPerformed method public void actionPerformed(ActionEvent evt) { if (DialogBox.OK_CMD.equals(evt.getActionCommand())) { // --- do your specific OK action System.out.println("Ok Button click"); } else if (evt.getActionCommand().equals(DefaultAction")) { // --- do your your default action System.out.println("Default Action"); } }

[Top]

How to Enable/Disable the Buttons of the DialogBox

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog Ok-Cancel-Preview");

// --- specify the OK_CANCEL_PREVIEW button combination
dialog.setButtonsCombination(DialogBox.OK_CANCEL_PREVIEW);

// --- subscribe to buttons ActionEvent
dialog.addButtonActionListener(this);

// --- disabled preview button while nothing to preview
dialog.getButton(DialogBox.PREVIEW_CMD).setEnabled(false);

[Top]

How to Create a Dialog with No Default Button but with Two Specific Buttons on the South-East

DialogBox dialog = new DialogBox(CommonSupport.getMainFrame(), "My Dialog One-Two");

// --- don't specify buttons combination
// --- create first button "one"
dialog.addRightButton("One", "ActionOne");

// --- create second button "two"
dialog.addRightButton("Two", "ActionTwo");

// --- subscribe to buttons ActionEvent
dialog.addButtonActionListener(this);

[Top]


History

Version: 1 [Mar 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.