Listing of Source tools/ToolSample.javapackage se.entra.phantom.server.samples.toolbox;
import se.entra.phantom.server.*;
/**
* A Sample tool for the Server Administration program processing a simple
* dialog box. The method "isPresent" is called to check if this interface
* is "valid" for this server instance. This can be used to e.g. check if the
* correct operating system is running for the type of service to perform,
* or to check if the function has a valid license (for such functions).
*
* <p>Once the tools interface is called, the method "onPanelCreate" is called.
*/
public class ToolSample extends VirtualComponentAdapter implements ServerAdminToolsInterface
{
/**
* Checks if this tools interface is currently present.
*/
@Override
public boolean isPresent()
{
return true;
}
/**
* Called to initialize the panel before it is displayed.
*/
@Override
public void onPanelCreate(VirtualPanel panel)
{
// Initialize the panel just about to be created ("SAMPLE.PHW").
panel.setText("ENTRY","Entry field");
panel.setText("SPIN","123");
panel.insertLine("COMBO","line 1",-1);
panel.insertLine("COMBO","line 2",-1);
panel.insertLine("COMBO","line 3",-1);
panel.setText("COMBO","Combobox");
panel.insertLine("LIST","Line 1\tColumn 2 with a description",-1);
panel.insertLine("LIST","Line 2\tAnother description",-1);
panel.insertLine("LIST","Line 3\tMore text that should be a description",-1);
}
/**
* Called when the close button of a panel is pressed,
* but before any other processing has been done. If this
* function returns false, the application close object
* will be called (if defined), otherwise a faked keypress
* of the Escape key is performed. If these two actions
* failed (because there is no close object or no button or
* menu item is connected to the Escape key), then the
* function <code>onPanelClose</code> is called.
*
* @return true to cancel all default processing.
*/
@Override
public boolean onPanelClosing(VirtualPanel panel)
{
close(panel);
return true;
}
/**
* Closes this panel by ending the current panel session in the
* application panel. This removes all panels that have been created.
*/
private void close(VirtualPanel panel)
{
panel.destroy();
}
/**
* List boxes generates this message. The <code>line</code> and <code>column</code>
* parameter are individually set to -1 if no line or column is selected respectively.
*/
@Override
public void onSelectionChanged(VirtualPanel panel,VirtualCListBox list,String controlID,int line,int column)
{
}
/**
* Check boxes and radio buttons generates this event when state is changed on the client side.
*
* <p>The state is 0=unchecked, 1=checked and 2=third state (only for check boxes,
* or PhantomCCheckBox.STATE_UNDETERMINED).
*/
@Override
public void onCheckedChange(VirtualPanel panel,VirtualControl control,String controlID,int state)
{
}
/**
* Push buttons and menu items generates this event when selected.
*/
@Override
public void onAction(VirtualPanel panel,String controlID)
{
if ( controlID.equals("OK" ) ) performOK(panel);
else if ( controlID.equals("CANCEL" ) ) close(panel);
}
/**
* Performs the OK action.
*/
private void performOK(VirtualPanel panel)
{
// Does a "real" action.
// For example, the line in the listbox must be selected in order to continue...
int line=panel.getNextSelection("LIST",-1);
if ( line<0 )
return;
// Just a little message box.
int rc=panel.messageBox(MB_YESNO,ICON_QUERY,"This message box can\ncontain\nmany\nlines.\n\nDo you wish to proceed?","Message box sample");
if ( rc==MBID_NO )
return;
if ( rc!=MBID_YES ) // To be sure it wasn't cancelled...
return;
// Create the dialog box processing listener for the ANOTHER panel.
final VirtualPanel toolPanel=panel;
VirtualPanelListener listener=new VirtualComponentAdapter()
{
// To close the panel.
private void closeAnother(VirtualPanel panel)
{
panel.destroy();
}
// When panel is about to be closed.
@Override
public boolean onPanelClosing(VirtualPanel panel)
{
closeAnother(panel);
return true;
}
// All actions.
@Override
public void onAction(VirtualPanel panel,String controlID)
{
if ( controlID.equals("OK" ) ) performOKAnother(panel);
else if ( controlID.equals("CANCEL" ) ) closeAnother(panel);
}
// OK action.
private void performOKAnother(VirtualPanel panel)
{
// Close the about pop-up panel and the INIT main panel below.
panel.destroy();
toolPanel.destroy();
}
};
// Bring up the ANOTHER pop-up panel for processing.
// This panel is in this sample not processed as a modal panel,
// but could be created as modal using the method createModalPanel.
// A modal panel is removed and processing continues when the method
// panel.dismissPanel(int returnCode) is called using the instance of
// that panel.
panel.getVirtualSessionManager().createPanel("ANOTHER",listener);
}
}