You are on page 1of 34

o m

i.c
dil
Hacettepe Üniversitesi
Bilgisayar Mühendisli i Bölümü
Bil447 Yaz l m Mühendisli i
ja va

Ad Soyad : Tahir Murat A IN


w.

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.III. SWT’N&N TEK BA3INA B&R PROGRAM OLARAK

i.c
ÇALI3TIRILMASI.................................................................................................4

II. PLUG-IN GEL&3T&RME

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.

I.II. AVANTAJLARI / DEZAVANTAJLARI


dil
SWT’yi çal&!t&rmak için tüm i!letim sistemlerinin kendine özgü kodlar& yükleme
zorunluluklar&, SWT’nin dezavantaj&d&r. Her platform kendine ait bir swt.jar versiyonuna
sahiptir. Windows’ta bu .dll , Linux’ta ise .so dur. E6er bu temel kodlar i!letim sisteminde yer
va
almazsa, o i!letim sisteminde SWT kullan&lamaz. Bu durumda tek iyi olan ise temel
bile!enlerin tüm i!letim sistemler için yaz&lm&! olmas&d&r.
SWT’nin en büyük avantaj& h&zl& olmas&d&r. IDE’lerle basit bir kar!&la!t&rmas& olarak,
Eclipse’teki grafiksel i!lemler Swingteki IDE’lerden daha h&zl& oldu6u aç&kt&r. Swing’in
yakla!&m&, altta çal&!an i!letim sistemine ait ilkel bir kayna6& (pencere gibi) almak ve kendi
çizim i!levlerini kullanmakt&r. Di6er taraftan SWT direk olarak i!letim siteminin UI
ja

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.

seçilen ö6eleri gösteremez.


Swing bunlar&n d&!&nda bellek kullan&m& yönünden de ele!tirilir. SWT gözle görülür
bir farkla daha az bellek alan& kullan&r. Bu da yakla!&k Swing’in kulland&6&n&n yar&s&d&r.
Swing bunlara ra6men, JTables, JTrees ve JLists kullan&mlar&nda Model-View-
Controller paterni için kar!&la!t&r&lamaz bir deste6e sahiptir. Bu SWT’ye kurulmam&!t&r onun
yerine SWT katman&n üstünde yer alan JFace katman&na kurulmu!tur.JFace bile!enleri tek
ww

ba!&na uygulamay& biraz daha fazla içermektedir.

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

Eclipse IDE’mizi çal&!t&r&r&z.


ja

Alk SWT örne6i


• SWT uygulamalar& Display ve Shell classlar&n& kullan&l&rlar.
• Swingteki gibi SWT’de de birçok component vard&r. Button, ComboBox, Label...
w.

Simdi Label componentine Selam yazd&ran bir örnek program yazal&m.


ww

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

Proje ad& belirlenir ve Next seçilir.


ja
w.
ww

8
o m
i.c
dil
va

Projeye klasör eklemek için Add Folder seçilir.


ja
w.

Yarataca6&m&z uzant&lar&m&z& bar&nd&raca6&m&z src klasörü yarat&l&r.


ww

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

Olu!turulan Selam Class’&n&n içine kod yaz&l&r.


ja
w.

System.out.println(“Selam”); kodumuzu main k&sm&m&za ekleriz.


ww

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.

C:\ Documents and Settings


\tahir\Desktop\eclipse\plugins\org.eclipse.swt.win32_2.1.0\os\win32\x86
Dizinin içindeki swt-win32-3007.dll dosyas&n& projemizin oldu6u dizinin içine kopyalar&z.
ww

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

Tebrikler ilk SWT uygulamam&z&da çal&!t&rd&k.


Görüldü6ü gibi SWT Swing kütüphanesine göre çok güçlü ve verimli çal&!maktad&r.
ja
w.
ww

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.

II.II. ECLIPSE PLUG-IN YAZMA ÖRNE@&

Verilecek plug-in örne6i bir popup menu arac&l&6&yla Eclipse’e ba6lanacakt&r.

Plug-in Proje Sihirbaz’ n n Kullan m dil


Plug-in yazman&n en kolay yollar&ndan biri sihirbaz& kullanmakt&r. Uzun
basamaklar&na ra6men bu bizi te!fik edici yöndedir.
Plug-in yaratmak için, ilk olarak bir plug-in projesi yaratmam&z gerekir.
File New... Project ile proje sihirbaz& ba!lat&l&r.
ja va
w.
ww

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

Kar!&n&za !öyle bir pencere ç&kacak:


w.
ww

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

Projeyi yaratmak için Finish’i t&klay&n.

Proje paket gezgininde görülecektir.

24
Aki s&n&f yarat&lacakt&r. Bunlar; BuildAction ve TestSWTPlugin’dir.

plugin.xml ve build.properties dosyalar& da yarat&lacakt&r. plugin.xml dosyas& plugin’in

m
platformu nas&l geni!letti6ini anlat&r.

TestSWTPlugin s&n&f&m&z&n içine a!a6&daki kodu kopyalar&z.

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

private final static String [] filterExtensions = {"*.xml", "*"};


private final static String [] filterNames = {"XML Files", "All Files"};
public static void main(String[] args) {
// Create the display
Display display = new Display();
w.

// Create the main interface class


TestSWT application = new TestSWT();
// Open the application using the main display class
Shell shell = application.open(display);
// Loop until the main shell is closed.
while(!shell.isDisposed()){
ww

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;

createLabel(shell, "Descriptor file:");


createDescriptorPanel(shell, "Test");
va
createSpacer(shell);
createClassesPanel(shell);
createSpacer(shell);
createLabel(shell, "Output directory:");
createOutputDirectoryPanel(shell, baseDirectory);
createSpacer(shell);
ja

createSeparator(shell);
createButtonPanel(shell);
createStatusPanel(shell);
// pack the widgets in the shell
shell.pack();
w.

// Center the shell on the display


centerOnScreen(display, shell);
// open the panel
shell.open();
return shell;
}
ww

/**
* 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.

doCheck = new Button(classesGroup, SWT.CHECK);


doCheck.setText("DO");
doCheck.setSelection(false);
finderCheck = new Button(classesGroup, SWT.CHECK);
finderCheck.setText("Finder");
finderCheck.setSelection(false);
ww

validatorCheck = new Button(classesGroup, SWT.CHECK);


validatorCheck.setText("Validator");
validatorCheck.setSelection(false);
}

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

GridLayout gridLayout = new GridLayout();


gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.numColumns = 3;
statusGroup.setLayout(gridLayout);
w.

progressBar = new ProgressBar(statusGroup, SWT.HORIZONTAL);


GridData progressGridData = new GridData();
progressGridData.heightHint = 15;
progressGridData.widthHint = 100;
progressGridData.horizontalAlignment = GridData.BEGINNING;
progressBar.setLayoutData(progressGridData);
ww

statusLabel = new Label(statusGroup, SWT.BORDER);


GridData labelGridData = new GridData();
labelGridData.heightHint = 15;
labelGridData.horizontalAlignment = GridData.FILL;
labelGridData.grabExcessHorizontalSpace = true;
labelGridData.horizontalSpan = 2;
statusLabel.setLayoutData(labelGridData);
}

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

public void stopProgress() {


display.asyncExec(new Runnable() {
public void run() {
progressBar.setSelection(progressBar.getMaximum());
}
});
}
}

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.*;

public class BuildAction implements IObjectActionDelegate {

i.c
private IStructuredSelection fSelection = null;

public BuildAction() {
super();
}

public void setActivePart(IAction action, IWorkbenchPart targetPart)


{
}

/**
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.

if (selection instanceof IStructuredSelection)


fSelection= (IStructuredSelection)selection;
else
fSelection= StructuredSelection.EMPTY;
}
}
ww

Plugin s&n&f& birkez tamamlan&nca ve action kodlan&nca jar dosyyas& olu!turulabilir.


plugin.xml’i sa6 t&klay&n ve Create Plug-in Jars’& seçin. Bu jar dosyas&n& yaratacak Ant
build.xml script’i yarat&r.

Jar dosyas&n& ve build.xml’i görmek için projeyi yenilemeniz gerekebilir.

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

2. Yazar&n ad& ve soyad& : Matthew Scarpino


Yay&n ad& : SWT/JFace in Action

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

1. "SWT: The Standard Widget Toolkit, Volume 1"


ja

2. "Eclipse in Action: A Guide for the Java Developer"


w.
ww

34

You might also like