I am using WizardNewFileCreationPage to create a New File
public void addPages() {
mainPage = new WizardNewFileCreationPage("FILE", getSelection());
mainPage.setTitle("New File");
mainPage.setDescription("Add new file");
addPage(mainPage);
}
I want to add some Radio Buttons to it representing file extensions in this wizard so that users can select one of them as a file extension.
The WizardNewFileCreationPage is not meant to be extended with custom controls. From its JavaDoc:
Subclasses may override
getInitialContents
getNewFileLabel
Subclasses may extend
handleEvent
If you still want to add the radio buttons 'at your own risk', you can try to override createAdvancedControls and append you controls to the parent after calling super.
protected void createAdvancedControls(Composite parent) {
super.createAdvancedControls( parent );
Button radioButton = new Button( parent, SWT.RADIO );
// ...
}
Note that the layout of parent (currently) is a single-columned GridLayout, set the layout data accordingly.
Related
I want to show a dialog inside my tornadofx application, but I don't want to create the dialog in the view. I've tried to create a dialog at the controller, but this doesn't seem to work.
This is an working example on how I can create a dialog inside my View
class MainScreenSelect : View("tool") {
override val root = vbox {
dialog("dialog") {
// Code how the dialog looks and how it behaves
}
}
}
My problem is, that I don't want to create my dialog inside my View, I want to create the dialog inside my controller. I assign the Vbox of my View to a variable inside my controller and want to create the dialog inside my controller.
This will be my View then
class MainScreenSelect : View("tool") {
private val controller : Controller by inject()
override val root = vbox {
controller.vbox = this
controller.showDialog()
}
}
The Vbox of the View is assigned to a variable inside the controller and the next line should create a dialog.
My controller will look like this
class ChatScreenController : Controller() {
var vbox : Vbox by singleassign()
fun showDialog(){
vbox.apply{
dialog{} // Here is the error, I can't call dialog at this point, but I can
// call it if I do vbox.apply inside the View
}
}
My problem is, why can't I create the dialog inside my controller? I can create any other elements inside vbox.apply, like another vbox, button... , but no dialog. Where is my error and how can I create a dialog from a controller instead of a view?
edit: I already tried to create a dialog with
Dialog<R>().apply{
//CODE
}
This creates a dialog, but it doesn't lock my mainscreen to force an input and I can't close this window by pressing X(To be honest I didn't really know what I did with the Dialog, but if this is the way to go I'll look into it, how to work with this Dialog)
SOLVED: My mistake was, that I thought 'dialog' belonged to the UI Element vbox, but dialog is related to the View. Changing the variable inside the controller to View instead of an UI Element made it possible to create a dialog for this View.
This is the new Controller
class ChatScreenController : Controller() {
var view : View by singleassign()
fun showDialog(){
view.dialog{
// Code for the Dialog
}
}
The View needs to be changed to assign itself to the variable view inside the controller
class MainScreenSelect : View("tool") {
private val controller : Controller by inject()
override val root = vbox {
controller.view = this#MainScreenSelect
controller.showDialog()
}
}
I have to create a custom wizard to develop a Eclipse Plug-in. I wish to use a DirectoryDialog but I can't get work with the other elements. I'm seeing that the DirectoyDialog is used in a "extends composite" class, but, is there any way to use in a "wizardPage"?
Thanks at all!
org.eclipse.swt.widgets.DirectoryDialog extends Dialog and can only be used as a pop-up dialog. It cannot be embedded in a wizard.
You can put a Button on the wizard page that displays the directory dialog when clicked.
Use the following code in your WizardPage
Button btnBrowse = new Button(container, SWT.NONE);
btnBrowse.setText("Browse..");
btnBrowse.addListener(SWT.Selection, new Listener() {
#Override
public void handleEvent(Event e) {
DirectoryDialog dirDialog = new DirectoryDialog(getShell());
dirDialog.setText("Select the parent directory for tools");
String location = dirDialog.open();
}
});
getShell() api used in 4th line is from WizardPage class.
I am working on a Compact Framework application. This particular hardware implementation has a touchscreen, but its Soft Input Panel has buttons that are simply too small to be useful. There are more than one form where typed input is required, so I created a form with buttons laid out like a keypad. The forms that use this "keypad" form are modal dialogs. When a dialog requiring this "keypad" loads, I load the "keypad" form as modeless:
private void CardInputForm_Load(object sender, EventArgs e)
{
...
keypadForm = new KeypadForm();
keypadForm.Owner = this;
keypadForm.SetCallback(keyHandler);
keypadForm.Show();
}
The SetCallback method tells the "keypad" form where to send the keystrokes (as a Delegate).
The problem I'm having is that the modeless "keypad" form does not take input. It is displayed as I expect, but I get a beep when I press any of its buttons, and its caption is grayed-out. It seems like the modal dialog is blocking it.
I've read other posts on this forum that says modal dialogs can create & use modeless dialogs. Can anyone shed light on this situation? Is there a problem with my implementation?
I found the answer: Set the keypad form's Parent property, not its Owner property, to the form instance wanting the keystrokes. The keypad dialog's title bar stays grayed out, but the form is active.
private void CardInputForm_Load(object sender, EventArgs e)
{
// (do other work)
keypadForm = new KeypadForm();
keypadForm.Parent = this;
keypadForm.Top = 190; // set as appropriate
keypadForm.Show();
}
Be sure to clean up when done with the parent form. This can be in the parent's Closing or Closed events.
private void CardInputForm_Closing(object sender, CancelEventArgs e)
{
// (do other work)
keypadForm.Close();
keypadForm.Dispose();
}
There are two panels on the keypad form, one with numerals and one with letters and punctuation that I want. There is also an area not on a panel that is common to both, containing buttons for clear, backspace, enter/OK, and cancel. Each panel has a button to hide itself and unhide its counterpart ('ABC', '123', for example). I have all the buttons for input on the keypadForm fire a common event. All it does is send the button instance to the parent. The parent is responsible for determining what action or keystroke is desired. In my case I named the buttons "btnA", "btnB", "btn0", "btn1", "btnCancel", etc. For keystrokes, the parent form takes the last character of the name to determine what key is desired. This is a bit messy but it works. Any form wishing to use the keypad form inherits from a base class, defining a method for callback.
public partial class TimeClockBase : Form
{
public TimeClockBase()
{
InitializeComponent();
}
// (other implementation-specific base class functionality)
public virtual void KeyCallback(Button button)
{
}
}
The click event on the keypad form looks like this.
private void btnKey_Click(object sender, EventArgs e)
{
// play click sound if supported
(Parent as TimeClockBase).KeyCallback(sender as Button);
}
The method in the parent form looks like this.
public override void KeyCallback(Button button)
{
switch (button.Name)
{
case "btnCancel":
// setting result will cause form to close
DialogResult = DialogResult.Cancel;
break;
case "btnClear":
txtCardID.Text = string.Empty;
break;
// (handle other cases)
}
}
In my project I need to create some play,pause,stop buttons in one composite.
For that I created one composite and added these buttons there. Also I have added the images
for each button. But after drawing, it does not look good. I mean images on the buttons does not look good.Clients are not satisfied. Now is it possible to add Images to Label and give some Toggle button actions to the label? I know I can add images to the label. But when I click the label,it does not give button effect..
If you want a custom look for your 'buttons' you could use labels with custom images (one for the normal state and one for the "pushed" state. Something like:
final Label stop = new Label(composite, SWT.NONE);
stop.setSize(STOP_IMG.getImageData().width, STOP_IMG.getImageData().height)
stop.setBackgroundImage(STOP_IMG);
stop.addMouseListener(new MouseAdapter()
{
#Override
public void mouseUp(MouseEvent e)
{
stop.setBackgroundImage(STOP_IMG);
}
#Override
public void mouseDown(MouseEvent e)
{
stop.setBackgroundImage(STOP_DOWN_IMG);
// DO ACTION
}
});
For a nice UI you could also add a MouseTrack listener and have different images for the mouse over states.
Disadvantage of this is you are making it less accessible as it will only respond to mouse events. If you go for this approach you should look at creating your own class that extends MouseAdapter, and takes the label, images and action to invoke in a constructor so you don't end up with tonnes of very similar anonymous classes.
I have used toolbars in the past to achieve a nice effect.
This will create a toolbar with an item that behaves like a regular button:
//Toolbar button
ToolBar toolBar = new ToolBar(composite,SWT.FLAT);
ToolItem toolItem = new ToolItem(toolBar,SWT.PUSH);
toolItem.setImage(image);
This will a toolbar with an item that has toggle behaviour:
//Create a toggle effect
ToolBar toggleToolBar = new ToolBar(composite,SWT.FLAT);
ToolItem toggleToolItem = new ToolItem(toggleToolBar,SWT.CHECK);
toggleToolItem.setImage(image);
i am facing one problem in SCSF.
I have two workspaces
MdiWorkspace
DeckWorkspace
i have two views in a module
Viewer (display in mdiworkspace)
Property Viewer (in deckworkspace)
in Viewer i have a button in toolbar whose purpose is to display PropertyViewer (another View).
how can i display this PropertyViewer in deckworkspace agaist button click event.
NOTE: i am not using Command[CommandName].AddInvoker(control, "click:) and CommandHandler
I'm going to assume your toolbar sits in a SmartPart that implements the MVP pattern. Have the button click event handler in the SmartPart fire an event that its presenter will handle. Your presenter code would look like this:
// Presenter code
protected override void OnViewSet()
{
this.View.ToolbarButtonClick += View_ToolbarButtonClick;
}
public void View_ToolbarButtonClick(object sender, EventArgs e)
{
// remove the handler so the property viewer
// will only be added the first time
this.View.OnToolbarButtonClick -= View_ToolbarButtonClick;
var propertyView = new PropertyViewer();
this.WorkItem.Workspaces[WorkspaceNames.MyDeckWorkspace].Show(propertyView);
}