| 1 |
/* |
|---|
| 2 |
DWT/JFace in Action |
|---|
| 3 |
GUI Design with Eclipse 3.0 |
|---|
| 4 |
Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic |
|---|
| 5 |
|
|---|
| 6 |
ISBN: 1932394273 |
|---|
| 7 |
|
|---|
| 8 |
Publisher: Manning |
|---|
| 9 |
|
|---|
| 10 |
Port to the D programming language: |
|---|
| 11 |
Frank Benoit <benoit@tionex.de> |
|---|
| 12 |
Added some stuff to play with the statusbar and its progressmonitor |
|---|
| 13 |
|
|---|
| 14 |
*/ |
|---|
| 15 |
module jface.ActionAndStatusbar; |
|---|
| 16 |
|
|---|
| 17 |
import dwtx.jface.action.Action; |
|---|
| 18 |
import dwtx.jface.action.ActionContributionItem; |
|---|
| 19 |
import dwtx.jface.action.MenuManager; |
|---|
| 20 |
import dwtx.jface.action.StatusLineManager; |
|---|
| 21 |
import dwtx.jface.action.ToolBarManager; |
|---|
| 22 |
import dwtx.jface.resource.ImageDescriptor; |
|---|
| 23 |
import dwtx.jface.window.ApplicationWindow; |
|---|
| 24 |
import dwtx.core.runtime.IProgressMonitor; |
|---|
| 25 |
import dwt.DWT; |
|---|
| 26 |
import dwt.widgets.Composite; |
|---|
| 27 |
import dwt.widgets.Control; |
|---|
| 28 |
import dwt.widgets.Display; |
|---|
| 29 |
|
|---|
| 30 |
import tango.text.convert.Format; |
|---|
| 31 |
version(JIVE) import jive.stacktrace; |
|---|
| 32 |
import dwt.dwthelper.utils; |
|---|
| 33 |
import dwt.dwthelper.Runnable; |
|---|
| 34 |
|
|---|
| 35 |
void main() { |
|---|
| 36 |
auto swin = new ActionAndStatusbar(); |
|---|
| 37 |
swin.setBlockOnOpen(true); |
|---|
| 38 |
swin.open(); |
|---|
| 39 |
Display.getCurrent().dispose(); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
public class ActionAndStatusbar : ApplicationWindow { |
|---|
| 43 |
StatusLineManager slm; |
|---|
| 44 |
|
|---|
| 45 |
StatusAction status_action; |
|---|
| 46 |
|
|---|
| 47 |
ActionContributionItem aci; |
|---|
| 48 |
|
|---|
| 49 |
public this() { |
|---|
| 50 |
super(null); |
|---|
| 51 |
slm = new StatusLineManager(); |
|---|
| 52 |
status_action = new StatusAction(slm); |
|---|
| 53 |
aci = new ActionContributionItem(status_action); |
|---|
| 54 |
addStatusLine(); |
|---|
| 55 |
addMenuBar(); |
|---|
| 56 |
addToolBar(DWT.FLAT | DWT.WRAP); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
protected Control createContents(Composite parent) { |
|---|
| 60 |
getShell().setText("Action/Contribution Example"); |
|---|
| 61 |
parent.setSize(290, 150); |
|---|
| 62 |
aci.fill(parent); |
|---|
| 63 |
return parent; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
protected MenuManager createMenuManager() { |
|---|
| 67 |
MenuManager main_menu = new MenuManager(null); |
|---|
| 68 |
MenuManager action_menu = new MenuManager("Menu"); |
|---|
| 69 |
main_menu.add(action_menu); |
|---|
| 70 |
action_menu.add(status_action); |
|---|
| 71 |
return main_menu; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
protected ToolBarManager createToolBarManager(int style) { |
|---|
| 75 |
ToolBarManager tool_bar_manager = new ToolBarManager(style); |
|---|
| 76 |
tool_bar_manager.add(status_action); |
|---|
| 77 |
return tool_bar_manager; |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
protected StatusLineManager createStatusLineManager() { |
|---|
| 81 |
return slm; |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
class StatusAction : Action { |
|---|
| 86 |
StatusLineManager statman; |
|---|
| 87 |
|
|---|
| 88 |
short triggercount = 0; |
|---|
| 89 |
|
|---|
| 90 |
public this(StatusLineManager sm) { |
|---|
| 91 |
super("&Trigger@Ctrl+T", AS_PUSH_BUTTON); |
|---|
| 92 |
statman = sm; |
|---|
| 93 |
setToolTipText("Trigger the Action"); |
|---|
| 94 |
setImageDescriptor(ImageDescriptor.createFromFile( |
|---|
| 95 |
getImportData!("eclipse-icon-red-16.png"))); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
public void run() { |
|---|
| 99 |
triggercount++; |
|---|
| 100 |
statman.setMessage( Format("The status action has fired. Count: {}", triggercount)); |
|---|
| 101 |
|
|---|
| 102 |
if( triggercount % 5 == 0 ){ |
|---|
| 103 |
statman.setCancelEnabled(true); |
|---|
| 104 |
auto pm = statman.getProgressMonitor(); |
|---|
| 105 |
pm.setCanceled(false); |
|---|
| 106 |
pm.beginTask( "Task", 100 ); |
|---|
| 107 |
auto runner = new class(pm) Runnable { |
|---|
| 108 |
IProgressMonitor pm; |
|---|
| 109 |
int w; |
|---|
| 110 |
this(IProgressMonitor a){ |
|---|
| 111 |
this.pm = a; |
|---|
| 112 |
} |
|---|
| 113 |
void run(){ |
|---|
| 114 |
const incr = 2; |
|---|
| 115 |
this.pm.worked( incr ); |
|---|
| 116 |
w += incr; |
|---|
| 117 |
if( w < 100 && !this.pm.isCanceled() ){ |
|---|
| 118 |
Display.getCurrent().timerExec( 100, this); |
|---|
| 119 |
} |
|---|
| 120 |
else{ |
|---|
| 121 |
this.pm.done(); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
}; |
|---|
| 125 |
Display.getCurrent().syncExec(runner); |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
} |
|---|