/*
* Created on 2004/07/27 Author aki@www.xucker.jpn.org License Apache2.0 or
* Common Public License
*/
package org.jpn.xucker.commons.swt.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.jpn.xucker.commons.util.ApplicationProperties;
public abstract class OkCancelDialog implements SelectionListener {
/**
* @param shell
*/
private Label filePath;
private Button browseButton;
private Button okButton;
private Button cancelButton;
protected Shell shell;
ApplicationProperties applicationProperties;
OkCancelDialogListener listener;
public Shell getShell() {
return shell;
}
public void setShell(Shell shell) {
this.shell = shell;
}
protected String title;
protected String dialogName="設定";
public OkCancelDialog(OkCancelDialogListener listener,Shell shell) {
this.listener=listener;
this.shell = shell;
beforeInit();
shell.setText(dialogName);
shell.setBounds(0, 0, 270, 150);
RowLayout layout = new RowLayout();
shell.setLayout(layout);
afterInit();
}
public void createOkCancellButton(){
// OK
okButton = new Button(shell, SWT.NULL);
okButton.setText("OK");
okButton.addSelectionListener(this);
RowData okButton_data = new RowData();
okButton.setLayoutData(okButton_data);
//キャンセル
cancelButton = new Button(shell, SWT.NULL);
cancelButton.setText("キャンセル");
cancelButton.addSelectionListener(this);
RowData cancelButton_data = new RowData();
cancelButton.setLayoutData(cancelButton_data);
}
public abstract String getValue(String key);
/**
*
*/
protected abstract void afterInit();
/**
*
*/
protected abstract void beforeInit() ;
public void widgetSelected(SelectionEvent event) {
Object target = event.getSource();
if (target == null) {
//
System.out.println("target==null");
}
//参照
else if (target == browseButton) {
do_browseButton();
}
//OK
else if (target == okButton) {
do_okButton();
}
//キャンセル
else if (target == cancelButton) {
do_cancelButton();
}else{
do_other_ui(event);
}
}
/**
* @param event
*/
protected abstract void do_other_ui(SelectionEvent event);
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
//参照
public void do_browseButton() {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
String path = dialog.open();
if (path != null) {
filePath.setText(path);
}
}
//OK
public void do_okButton() {
listener.clickOkButton(this);
shell.close();
}
//キャンセル
public void do_cancelButton() {
shell.close();
}
public ApplicationProperties getApplicationProperties() {
return applicationProperties;
}
public void setApplicationProperties(
ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}
}
|