1
package org.herac.tuxguitar.gui.tools.browser.dialog;
3
import java.util.Iterator;
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.events.SelectionAdapter;
7
import org.eclipse.swt.events.SelectionEvent;
8
import org.eclipse.swt.graphics.Point;
9
import org.eclipse.swt.graphics.Rectangle;
10
import org.eclipse.swt.layout.GridData;
11
import org.eclipse.swt.layout.GridLayout;
12
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.swt.widgets.Control;
14
import org.eclipse.swt.widgets.Menu;
15
import org.eclipse.swt.widgets.MenuItem;
16
import org.eclipse.swt.widgets.Shell;
17
import org.eclipse.swt.widgets.ToolBar;
18
import org.eclipse.swt.widgets.ToolItem;
19
import org.herac.tuxguitar.gui.TuxGuitar;
20
import org.herac.tuxguitar.gui.tools.browser.TGBrowserCollection;
21
import org.herac.tuxguitar.gui.tools.browser.TGBrowserManager;
22
import org.herac.tuxguitar.gui.tools.browser.base.TGBrowserFactory;
24
public class TGBrowserToolBar extends TGBrowserBar{
25
private Composite composite;
26
private ToolBar toolBar;
27
private ToolItem newBrowser;
28
private ToolItem root;
29
private ToolItem back;
30
private ToolItem refresh;
31
protected Menu newBrowserMenu;
32
protected TGBrowserCollectionCombo collections;
34
public TGBrowserToolBar(TGBrowserDialog browser){
38
public void init(Shell shell){
39
this.composite = new Composite(shell,SWT.NONE);
40
this.composite.setLayout(getLayout());
41
this.composite.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
45
public void initItems(){
46
this.toolBar = new ToolBar(this.composite,SWT.FLAT | SWT.WRAP);
48
//---New Book----------------------------------------------------------
49
this.newBrowserMenu = new Menu(this.composite);
50
Iterator bookTypes = TGBrowserManager.instance().getFactories();
51
while(bookTypes.hasNext()) {
52
final TGBrowserFactory bookType = (TGBrowserFactory)bookTypes.next();
53
MenuItem item = new MenuItem(this.newBrowserMenu, SWT.PUSH);
54
item.setText(bookType.getName());
55
item.setData(bookType);
56
item.addSelectionListener(new SelectionAdapter() {
57
public void widgetSelected(SelectionEvent e) {
58
newCollection( bookType.getType());
62
this.newBrowser = new ToolItem(this.toolBar,SWT.DROP_DOWN);
63
this.newBrowser.setImage(TuxGuitar.instance().getIconManager().getBrowserNew());
64
this.newBrowser.addSelectionListener(new SelectionAdapter() {
65
public void widgetSelected(SelectionEvent event) {
66
if (event.detail == SWT.ARROW) {
67
ToolItem item = (ToolItem) event.widget;
68
Rectangle rect = item.getBounds();
69
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
70
TGBrowserToolBar.this.newBrowserMenu.setLocation(pt.x, pt.y + rect.height);
71
TGBrowserToolBar.this.newBrowserMenu.setVisible(true);
76
new ToolItem(this.toolBar, SWT.SEPARATOR);
77
//---Root Folder------------------------------------------------------
78
this.root = new ToolItem(this.toolBar,SWT.PUSH);
79
this.root.setImage(TuxGuitar.instance().getIconManager().getBrowserRoot());
80
this.root.addSelectionListener(new SelectionAdapter() {
81
public void widgetSelected(SelectionEvent e) {
82
getBrowser().getConnection().cdRoot(TGBrowserDialog.CALL_CD_ROOT);
86
//---Back Folder------------------------------------------------------
87
this.back = new ToolItem(this.toolBar,SWT.PUSH);
88
this.back.setImage(TuxGuitar.instance().getIconManager().getBrowserBack());
89
this.back.addSelectionListener(new SelectionAdapter() {
90
public void widgetSelected(SelectionEvent e) {
91
getBrowser().getConnection().cdUp(TGBrowserDialog.CALL_CD_UP);
95
//---Refresh Folder------------------------------------------------------
96
this.refresh = new ToolItem(this.toolBar,SWT.PUSH);
97
this.refresh.setImage(TuxGuitar.instance().getIconManager().getBrowserRefresh());
98
this.refresh.addSelectionListener(new SelectionAdapter() {
99
public void widgetSelected(SelectionEvent e) {
100
getBrowser().getConnection().listElements(TGBrowserDialog.CALL_LIST);
105
new ToolItem(this.toolBar, SWT.SEPARATOR);
107
//---Collections-------------------------------------------------------------
108
this.collections = new TGBrowserCollectionCombo(this.composite, SWT.READ_ONLY);
109
this.collections.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
110
this.collections.addSelectionListener(new SelectionAdapter() {
111
public void widgetSelected(SelectionEvent e) {
117
public void updateItems(){
118
this.newBrowser.setEnabled(!getBrowser().getConnection().isLocked());
119
this.collections.setEnabled(!getBrowser().getConnection().isLocked());
120
this.root.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
121
this.back.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
122
this.refresh.setEnabled(!getBrowser().getConnection().isLocked() && getBrowser().getConnection().isOpen());
125
public void updateCollections(TGBrowserCollection selection){
127
this.collections.removeAll();
129
Iterator it = TGBrowserManager.instance().getCollections();
131
TGBrowserCollection collection = (TGBrowserCollection)it.next();
132
if(collection.getData() != null){
133
this.collections.add(collection);
134
if(selection != null && selection.equals(collection)){
135
this.collections.select(index);
142
public void reload(){
145
this.composite.layout(true,true);
148
public void loadProperties(){
149
this.newBrowser.setToolTipText(TuxGuitar.getProperty("browser.collection.new"));
150
this.root.setToolTipText(TuxGuitar.getProperty("browser.go-root"));
151
this.back.setToolTipText(TuxGuitar.getProperty("browser.go-back"));
152
this.refresh.setToolTipText(TuxGuitar.getProperty("browser.refresh"));
153
this.updateCollections(getBrowser().getCollection());
156
protected void updateCollection(){
157
TGBrowserCollection collection = this.collections.getSelection();
158
if(collection == null){
161
openCollection(collection);
165
private void disposeItems(){
166
Control[] controls = this.composite.getChildren();
167
for(int i = 0; i < controls.length; i ++){
168
controls[i].dispose();
172
private GridLayout getLayout(){
173
GridLayout layout = new GridLayout(2,false);
174
layout.marginWidth = 0;
175
layout.marginHeight = 0;