Professional Documents
Culture Documents
Eclipse SWT Ve Plugin Gelistirme MAGIN
Eclipse SWT Ve Plugin Gelistirme MAGIN
i.c
dil
Hacettepe Üniversitesi
Bilgisayar Mühendisli i Bölümü
Bil447 Yaz l m Mühendisli i
ja va
Numaras : 20221504
Ara$t rma Konusu : Eclipse SWT ve Plug-in Geli!tirme
ww
&Ç&NDEK&LER
m
I. ECLIPSE SWT
I.I. G&R&3.................................................................................................................3
o
I.II. AVANTAJLARI/DEZAVANTAJLARI.......................................................3
i.c
ÇALI3TIRILMASI.................................................................................................4
II.I. G&R&3.............................................................................................................18
III.
dil
II.II. ECLIPSE PLUG-IN YAZMA ÖRNE@&...................................................18
KAYNAKÇA.........................................................................................................34
ja va
w.
ww
2
m
I.ECLIPSE SWT
I.I. G&R&3
o
IBM taraf&ndan olu!turulmu! Grafiksel Kullan&c& abirimi kütüphaneleine SWT
(Standard Widget Toolkit) denir. Sun taraf&ndan olu!turulan AWT ve Swing’den farkl& olarak
i.c
SWT platforma özgün geli!tirilmi!tir.
Eclipse’e bir Eclipse plug-in’i katmak için gelis!tiriciler SWT’yi kullan&r. Eclipse
d&!&nda SWT tek ba!&na bir programda da kullan&labilir.
SWT’yi güçlü k&lan özelli6i performans ve verimdir. Ama ayn& zamanda SWT’nin
tüm i!letim sistemleri için kendine özgü bile!enler gerektirmesi Java’n&n “Bir kere yaz,
heryerde çal&!t&r” felsefesine uyum sa6layamam&!t&r hatta yok etmi!tir.
bile!enlerini kullan&r.
A!letim sisteminin UI bile!enlerini kullanmas& sonucunda bir çok avantaj do6ar.
Sadece h&zl& olmas& de6il ayn& zamanda temel GUI gösterimini daha da iyile!tirmesi
bunlardan biridir.SWT platform’un bile!enlerini kulland&6& için i!letim sistemiyle tam uyum
gösterir.Görsel i!letim sistemlerinde (Windows XP gibi), Swing SWT’nin gösterdi6i gibi
w.
3
o m
i.c
I.III. SWT’N&N TEK BA3INA B&R PROGRAM OLARAK
ÇALI3TIRILMASI
Gerekli Kurulumlar :
dil
• Java SDK www.java.com çekilir.
• Eclipse IDE www.eclipse.org ‘dan çekilir. (Çok güçlü bir IDE’dir. SWT kütüphanesi
Eclipse ile birlikte gelir.)
va
• Denetim Masas& Sistem Geli!mi! Ortam De6i!kenleri ‘ne JAVA_HOME
tan&m& ap&l&r ve java SDK nereye kurulduysa yolu belirtilir.
ja
w.
ww
4
Eclipse
o m
i.c
dil
va
5
m o
i.c
dil
va
ProjeninYarat&lmas&
File New Project seçilir.
ja
w.
ww
6
m o
i.c
dil
va
JAVA Java Project seçilir ve de Next seçilir.
ja
w.
ww
7
m o
i.c
dil
va
8
o m
i.c
dil
va
9
o m
src klasörümüzü yaratt&ktan sonra OK seçildi6inde Eclipse bize Output klasörünü bin olarak
olu!turay&m m& diye sorar. Eclipse’in sorusuna Yes seçilir.
i.c
dil
ja va
w.
Finish seçilir.
ww
Alk defa çal&!t&rd&6& için Perspective görüntüsüne geçti6i belirtilir.Burda Yes seçilir.
10
ww
w.
java
dil
i.c
om
11
m o
i.c
dil
Selam Class’&n&n yarat&lmas&.
ja va
w.
ww
12
o m
i.c
dil
va
13
o m
i.c
Run Run As Java Application seçilir.
dil
va
Alk Console uygulam&z& çal&!t&rd&k. Rimdi de bu ç&kt&y& SWT kütüphanesi kullanarak Label
componentine yazd&ral&m.
ja
w.
ww
14
o m
i.c
dil
va
Selam projesi seçilerek Mouse’un sa6 t&klanmas&ndan Properties seçilir.
ja
w.
ww
15
o m
i.c
dil
va
Java Build Path den Libraries seçilir. Buradan da Add External Jar’s seçilir.
Son olarak swt.jar kütüphaneleri seçilir ve OK seçilir.
Böylelikle swt kütüphanemiz projemize eklenir ve hata mesajlar& kalkar.
ja
w.
16
o m
swt-win32-3007.dll dosyam&z kullan&lan sürüme göre de6i!ebilir. Her yeni sürümde tekrar
i.c
yeni dosya kopyalanmal&d&r.
Akinci Yol:
C:\Windows\System32 dizinin içine
C:\Documents and Settings\tahir\Desktop\eclipse\plugins\org.eclipse.swt.win32_2.1.0\os
\win32\x86\swt-win32-3007.dll dosyas&n& kopyalar&z. Böylelikle birden fazla proje bu file’&
Selam’&n çal&!t&r&lmas&
Run Selam seçilir.
dil
kullan&yorsa tekrar tekrar kopyalanmak zorunda kal&nmaz.
va
17
II. PLUG-IN GEL&3T&RME
II.I. G&R&3
m
Eclipse platformu bir tak&m plug-in’lerin birle!tirilmesi ile olu!turulmu! bir çekirdek
çal&!ma zaman& makinesidir. Plug-in’ler platforma önceden tan&ml& ek noktalarda
ba6lanm&!t&r. UI kendisi zaten bir plug-in’dir. Çal&!ma ortam& ba!lat&ld&6&nda, sadece tek bir
Java program’& ba!lat&lmaz ayn& zamanda dinamik olarak kay&tl& plug-in’leri ara!t&ran ve
gerekti6inde onlar& çal&!t&ran bir çal&!ma zaman& platformu da aktivite edilir.
o
Platform iyi tan&mlanm&! bir ek noktalar kümesine sahiptir. Bu noktalar sisteme
kat&l&nd&6& ve sistem davran&!&nda pay sahibi olundu6u yerlerdir. Platform aç&s&ndan sizin
plug-in’inizin kaynak yönetimi ya da çal&!ma ortam& gibi temel plug-in’lerden hiçbir fark&
i.c
yoktur.
18
Soldaki pencereden Plug-in Development’& seçin ve sonra sa6daki pencereden Plug-in
Project’i seçin. Next’i t&klay&n.
o m
i.c
dil
ja va
19
Proje için bir ad seçin.Proje için herhangi bir ad verebilmenize ra6men, sihirbaz&n
sonraki bölümlerinde verilen bu ad Java paketinin ad& olacakt&r. Ad& girdikten sonra Next’i
t&klay&n.
o m
i.c
dil
ja va
w.
ww
20
Project Structure penceresi kar!&m&za ç&kar. E6er do6ru formatta proje ad& seçilmi!se,
bu pencerde de6i!iklik yapman&za gerek yok. Tamamland&6&nda Next’i t&klay&n.
o m
i.c
dil
ja va
w.
ww
21
Plug-in Code Generators penceresinde ise “Plug-in with a popuup menu” seçilir. E6er
plug-in’lerle ha!&r ne!irseniz “Create a blank plug-in project”i seçebilirsiniz. Haz&rlad&ktan
sonra Next’i t&klay&n.
o m
i.c
dil
ja va
w.
.
ww
22
Bu a!amada Plug-in Content penceresi görüntülenir. Class ad&, yarat&lacak plug-in
class’&n&n ad&d&r. A!lem tamamlan&nca Next’i t&klay&n.
o m
i.c
dil
ja va
w.
ww
23
Sample Popup Menu kar!&m&za ç&kar. Bu pencere popup menuye özgü parçalar için
kullan&c&y& te!fik eder.
m
Target Object’s Class, popup menu göründü6ünde seçilecek dosyan&n s&n&f ad&d&r.
Name Filter e6er bir döküman seçilip ve fare sa6 t&klan&nca popup menude menu
eleman& görünürse karar vermek için kullan&l&r. Bu durumda, ek .xml’de sonlanan dosya için
sadece menu eleman&n&n belirmesini isteriz.
Submenu Name popup menuyew eklenecek alt menunün ad&d&r.
o
Action Label alt menudeki menu eleman&nda görünen metindir.
Single Selection seçilirse a6açta sadece seçilmi! bir dü6üm kullan&laca6&na dair
harekete k&s&tlama getirilmi! olur.
i.c
dil
ja va
w.
ww
24
Aki s&n&f yarat&lacakt&r. Bunlar; BuildAction ve TestSWTPlugin’dir.
m
platformu nas&l geni!letti6ini anlat&r.
package com.amo.testswt;
o
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
i.c
import org.eclipse.swt.layout.*;
/**
* This class prompts the user to build data object classes from
* a deployment descriptor.
*/
public class TestSWT {
dil
private String baseDirectory = "";
private Display display = null;
private Text descriptorText = null;
private Button recordCheck = null;
private Button tableCheck = null;
private Button doCheck = null;
va
private Button finderCheck = null;
private Button doimplCheck = null;
private Button validatorCheck = null;
private ProgressBar progressBar = null;
private Label statusLabel = null;
private Text outputDirectoryText = null;
ja
if(!display.readAndDispatch()) {
display.sleep();
}
}
// Garbage collect the main display
display.dispose();
System.exit(0);
}
25
/**
* Construct a XMLGeneratorFrame
*/
m
public TestSWT() {
super();
}
/**
* Open the shell using the display passed in.
o
* @param display The display to use.
* @return The shell created to display the widgets.
*/
public Shell open(Display display) {
i.c
this.display = display;
// Create the shell
Shell shell = new Shell(display);
// set the text at the top of the window
shell.setText("Data Object Builder");
// create and set a layout for the shell
layout.marginWidth = 0;
shell.setLayout(layout);
// add the widgets
dil
GridLayout layout = new GridLayout(1, true);
layout.marginHeight = 0;
createSeparator(shell);
createButtonPanel(shell);
createStatusPanel(shell);
// pack the widgets in the shell
shell.pack();
w.
/**
* Center the shell on the display
*/
private void centerOnScreen(Display display, Shell shell) {
Rectangle rect = display.getClientArea();
Point size = shell.getSize();
int x = (rect.width - size.x) / 2;
int y = (rect.height - size.y) / 2;
26
shell.setLocation(new Point(x,y));
}
/**
m
* Add a separator line to the shell
* @param shell
*/
private void createSeparator(Shell shell) {
Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
o
GridData gd = new GridData();
gd.horizontalAlignment = GridData.FILL;
separator.setLayoutData(gd);
}
i.c
/**
* Add a vertical space to the shell
* @param shell
*/
private void createSpacer(Shell shell) {
new Label(shell, SWT.NONE);
}
/**
* Add a label to the shell.
* @param shell
*/
dil
private void createLabel(Shell shell, String text) {
Label label = new Label(shell, SWT.NONE);
va
label.setText(text);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
/**
* Add the descriptor panel to the shell.
* @param shell
ja
*/
private void createDescriptorPanel(final Shell shell, String deploymentDescriptor) {
Composite descriptorGroup = new Composite(shell, SWT.NONE);
descriptorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout gridLayout = new GridLayout();
w.
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.numColumns = 2;
descriptorGroup.setLayout(gridLayout);
descriptorText = new Text(descriptorGroup, SWT.SINGLE | SWT.BORDER);
descriptorText.setText(deploymentDescriptor);
ww
descriptorText.setTextLimit(150);
descriptorText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button selectButton = new Button(descriptorGroup, SWT.PUSH);
selectButton.setText("Select...");
selectButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
selectDescriptor(shell);
});
27
}
/**
* Display a FileDialog to get a selected deployment descriptor.
m
* @param shell
*/
private void selectDescriptor(Shell shell) {
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
fileDialog.setFileName(descriptorText.getText());
o
fileDialog.setText("Open a Deployment Descriptor");
fileDialog.setFilterExtensions(filterExtensions);
fileDialog.setFilterNames(filterNames);
String result = fileDialog.open();
i.c
if (result != null) {
descriptorText.setText(result);
}
}
/**
* Add the classes check panel to the shell
* @param shell
*/ dil
private void createClassesPanel(Shell shell) {
// Create a grouping panel
Group classesGroup = new Group(shell, SWT.NONE);
classesGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
RowLayout rowLayout = new RowLayout();
va
classesGroup.setLayout(rowLayout);
classesGroup.setText("Classes to generate");
recordCheck = new Button(classesGroup, SWT.CHECK);
recordCheck.setText("Record");
recordCheck.setSelection(true);
tableCheck = new Button(classesGroup, SWT.CHECK);
ja
tableCheck.setText("Table");
tableCheck.setSelection(true);
doimplCheck = new Button(classesGroup, SWT.CHECK);
doimplCheck.setText("DOImpl");
doimplCheck.setSelection(true);
w.
28
/**
* Add the output directory panel to the shell
* @param shell
m
*/
private void createOutputDirectoryPanel(final Shell shell, String baseDirectory) {
Composite outDirectoryGroup = new Composite(shell, SWT.NONE);
outDirectoryGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout gridLayout = new GridLayout();
o
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.numColumns = 2;
outDirectoryGroup.setLayout(gridLayout);
i.c
outputDirectoryText = new Text(outDirectoryGroup, SWT.SINGLE |
SWT.BORDER);
outputDirectoryText.setText(baseDirectory);
outputDirectoryText.setTextLimit(150);
outputDirectoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button selectButton = new Button(outDirectoryGroup, SWT.PUSH);
dil
selectButton.setText("Select...");
selectButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
}
selectOutputDirectory(shell);
});
}
va
/**
* Display a DirectoryDialog to get a selected directory.
* @param shell
*/
private void selectOutputDirectory(Shell shell) {
DirectoryDialog directoryDialog = new DirectoryDialog(shell, SWT.OPEN);
ja
directoryDialog.setFilterPath(outputDirectoryText.getText());
directoryDialog.setMessage("Choose the base directory for creating data
objects.");
directoryDialog.setText("Select an Output Directory");
String result = directoryDialog.open();
w.
if (result != null) {
outputDirectoryText.setText(result);
}
}
/**
* Add a button panel to the shell
ww
*/
private void createButtonPanel(final Shell shell) {
Composite buttonGroup = new Composite(shell, SWT.NONE);
buttonGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
buttonGroup.setLayout(gridLayout);
GridData okGridData = new GridData();
29
GridData cancelGridData = new GridData();
Label label = new Label(buttonGroup, SWT.NONE);
GridData labelGridData = new GridData();
m
labelGridData.horizontalAlignment = GridData.FILL;
labelGridData.grabExcessHorizontalSpace = true;
label.setLayoutData(labelGridData);
Button okButton = new Button(buttonGroup, SWT.PUSH);
okButton.setLayoutData(okGridData);
o
okButton.setText("OK");
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
startBuild();
i.c
}
});
Button cancelButton = new Button(buttonGroup, SWT.PUSH);
cancelButton.setLayoutData(cancelGridData);
cancelButton.setText("Cancel");
cancelButton.addSelectionListener(new SelectionAdapter() {
});
}
dil
public void widgetSelected(SelectionEvent e) {
shell.close();
shell.dispose();
}
/**
va
* Add a status bar to the panel.
* @param shell
*/
private void createStatusPanel(Shell shell) {
Composite statusGroup = new Composite(shell, SWT.NONE);
statusGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
ja
30
/**
* Start the build
*/
m
public void startBuild() {
LongRunningThread thread = new LongRunningThread(this);
thread.start();
}
/**
o
* This method is called by the thread to initialize the progress bar.
*/
public void startProgress(final int total) {
display.asyncExec(new Runnable() {
i.c
public void run() {
progressBar.setMinimum(0);
progressBar.setSelection(0);
progressBar.setMaximum(total);
}
});
}
/** dil
* This method is called by the thread to set the status text.
*/
public void setStatusText(final String text) {
display.asyncExec(new Runnable() {
public void run() {
va
statusLabel.setText(text);
}
});
}
/**
* This method is called by the thread to increment the progress bar.
ja
*/
public void incrementProgress() {
display.asyncExec(new Runnable() {
public void run() {
progressBar.setSelection(progressBar.getSelection()+1);
w.
}
});
}
/**
* This method is called by the thread when it has finished.
*/
ww
31
Sonra BuildAction s&n&f&m&z& plugin’i ça6&racak !ekilde kodlamal&y&z.
m
package com.amo.testswt.actions;
import org.eclipse.core.resources.*;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
o
import com.amo.testswt.*;
i.c
private IStructuredSelection fSelection = null;
public BuildAction() {
super();
}
/**
dil
* Run the plugin with the current selection
*/
public void run(IAction action) {
Object obj = fSelection.getFirstElement();
va
if (obj != null && obj instanceof IFile) {
IFile file = (IFile)obj;
String path = file.getLocation().toString();
TestSWTPlugin plugin = TestSWTPlugin.getDefault();
plugin.setDeploymentDescriptor(path);
// Open the plugin
plugin.open(Display.getCurrent());
}
ja
/**
* Save the selection
*/
public void selectionChanged(IAction action, ISelection selection) {
w.
32
Jar dosyas& yarat&ld&6&nda, plugin klasörünün yarat&lmas& gerekir. Bunu yapman&n kolay yolu
build.xml script’i ça&!t&rmak ve zip.plugin hedefini seçmektir. Bu do6ru klasör yap&s&na sahip
bir zip file’&n kurulmas&n& sa6lar.
m
Zip dosyas&n&n eclipse/plug-ins klasörüne ç&kart&lmas& jar dosyas&n& kuracakt&r. Plugin.xml ve
build.properties dosyalar&n&n da ayn& klasöre kopyalanmas& gerekecektir.
Eclipse tekrar ba!lat&ld&6&nda, yeni plug-in kaydedilecek ve kullan&ma uygun hale gelecektir.
o
Plug-in’i denemek için, .xml ile biten bir dosya seçin ve sa6 t&klay&n. Menu seçimlerinden biri
Data Object olacakt&r. Bu seçimin ‘Build...’ ad&nda bir eleman& vard&r. Bu t&klaman&zla plug-in
çal&!acakt&r.
i.c
dil
ja va
w.
ww
33
III. KAYNAKÇA
A. K&TAPLAR
m
1. Yazar&n ad& ve soyad& : Rob Warner with Robert Harris
Yay&n ad& : The Definite Guide to SWT and JFace
Yay&n Kurulu!u : Computer Science Press
o
Yay&n Tarihi : 2003
i.c
Yay&n Kurulu!u : Computer Science Press
Yay&n Tarihi : 2004
B. INTERNET S&TELER&
1.
2.
3.
4.
www.java.com
www.eclipse.org
dil
www.cs.umanitoba.ca/~eclipse/1-Install.pdf
www.apress.com/ApressCorporate/supplement/1/351/1590593251-1950.pdf
5. http://eclipsewiki.swiki.net/239
6. http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-ui-
va
home/accessibility/keys.html
C. E-BOOKS
34