summaryrefslogtreecommitdiff
path: root/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/Browser.java
blob: 4ab592fd312e9026213da524e8ea9a5c772d1567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright (c) 2006 Manuel Traut and Volker Dahnke
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors: Manuel Traut and Volker Dahnke

package YalpClients.SwtClient.GUI;

import YalpClients.*;
import YalpClients.SwtClient.*;

import YalpInterfaces.*;

import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import java.util.LinkedList;

 * Class Browser
 *
 * <em></em>
 *
 * @author Volker Dahnke / Manuel Traut
 *
 * @version 1 02-04-2006<br>

public class Browser extends Composite{
	private Composite parentComposite;
	private Display display1;
	private Shell shell;
	private Model model;
	private LinkedList<String> alreadyBrowsed;
	private Tree tree;
	private Button add;
	private Button cancel;
	
	Browser( Composite parent,
					 final Model model,
					 Display display,
					 Composite parentComposite,
					 int style )
	{
		super(parent, style);
		this.parentComposite=parentComposite;
		this.alreadyBrowsed = new LinkedList<String>();
		this.model = model;
		this.display1 = display;
		this.shell = new Shell(this.display1,SWT.NONE);
		this.setSize(300,400);
		GridLayout gridLayout = new GridLayout();
		this.shell.setLayout(gridLayout);
		gridLayout.numColumns = 2;

		GridData treeGrid = new GridData();
		treeGrid.horizontalSpan = 2;
		treeGrid.widthHint = 300;
		treeGrid.heightHint = 400;
		treeGrid.grabExcessHorizontalSpace = true;
		treeGrid.grabExcessVerticalSpace = true;
		treeGrid.horizontalAlignment = SWT.FILL;
		treeGrid.verticalAlignment = SWT.FILL;

		this.tree = new Tree(this.shell, SWT.SINGLE);
		this.tree.setLayoutData(treeGrid);

		TreeItem tmp;

		for(YalpFile aFile : model.getDir("/")){
			tmp = new TreeItem(this.tree, SWT.NULL);
			tmp.setText(aFile.name);
			if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
			else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
		}

		this.tree.addSelectionListener (
			new SelectionAdapter() {

				public void widgetSelected(SelectionEvent e) {
					String path = getPath();
					if(!alreadyBrowsed.contains(path)){
						alreadyBrowsed.add(path);
						TreeItem tmp;

						for(YalpFile aFile : model.getDir(path)){
							tmp = new TreeItem(tree.getSelection()[0],SWT.NULL);
							tmp.setText(aFile.name);
							if(aFile.isDir) tmp.setImage(new Image(display1, "folder.gif"));
							else tmp.setImage(new Image(display1, "yalpV2_klein.gif"));
							tmp.getParentItem().setExpanded(true);
						}
					}
				}
			}
		);

		GridData buttonGrid1 = new GridData();
		buttonGrid1.horizontalSpan = 1;

		this.add = new Button(this.shell, SWT.PUSH);
		this.add.setText("Indicate");
		this.add.setLayoutData(buttonGrid1);
		this.add.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e){
			//	model.addDir(getPath());
				parentEnable(true);
				shell.setVisible(false);
			}
		});

		GridData buttonGrid2 = new GridData();
		buttonGrid2.horizontalSpan = 1;
		buttonGrid2.horizontalAlignment = SWT.END;

		this.cancel = new Button(this.shell, SWT.PUSH);
		this.cancel.setText("Cancel");
		this.cancel.setLayoutData(buttonGrid2);
		this.cancel.addSelectionListener(new SelectionAdapter(){
			public void widgetSelected(SelectionEvent e){
				parentEnable(true);
				shell.setVisible(false);
			}
		});
	}

	public void show(){
		parentEnable(false);
		Point size=this.getSize();
		Rectangle parentRec=((Shell)this.parentComposite).getBounds();
		Rectangle thisRec=this.shell.computeTrim(parentRec.x+(parentRec.width/2)-(size.x/2),parentRec.y+(parentRec.height/2)-(size.y/2),size.x,size.y);
		shell.setBounds(thisRec);
		shell.open();
		while(!shell.isDisposed()){
			if(!this.display1.readAndDispatch()) this.display1.sleep();
		}
		this.display1.dispose();
	}

	private String getPath(){
		TreeItem actualItem = tree.getSelection()[0];
		String path = "/"+tree.getSelection()[0].getText();
		while(actualItem.getParentItem() != null){
			actualItem = actualItem.getParentItem();
			path = "/" + actualItem.getText() + path;
		}
		return path;
	}
	private void parentEnable(boolean bool){
		parentComposite.setEnabled(bool);
	}
}
*/