IBM Korea Skip to main content
       IBM Ȩ    |  Á¦Ç° & ¼­ºñ½º  |  °í°´Áö¿ø & ´Ù¿î·Îµå  |  È¸¿ø°¡ÀÔ  

IBM developerWorks > ÀÚ¹Ù
developerWorks

Eclipse Workbench ¹Û¿¡¼­ Eclipse GUI »ç¿ëÇϱâ, Part 1 :
½ºÅĵå¾ó·Ð ¸ðµå¿¡¼­ JFace¿Í SWT »ç¿ëÇϱâ

°£´ÜÇÑ ÆÄÀÏ Å½»ö ¾ÖÇø®ÄÉÀÌ¼Ç ¸¸µé±â

Level: Intermediate

Adrian Van Emmenis
µ¶¸³ ÄÁ¼³ÅÏÆ®
2003³â 1¿ù 23ÀÏ

Eclipse GUI ÄÄÆ÷³ÍÆ®(JFace & SWT)°¡ Eclipse Workbench ³»ºÎ¿¡¼­ Á¾Á¾ »ç¿ëµÇ°í´Â ÀÖÁö¸¸, ¿ø·¡´Â µ¶¸³(self-contained) ÇÁ·¹ÀÓ¿÷À¸·Î¼­ ¼³°èµÇ¾ú´Ù. Eclipse Workbench ¿ÜºÎ¿¡¼­µµ, JFaceÀÇ Ç÷¯±× °¡´ÉÇÑ µðÀÚÀÎÀ¸·Î ³î¶øµµ·Ï ÀûÀº Äڵ带 »ç¿ëÇÏ¿© ¼¼·ÃµÈ GUI¸¦ ¸¸µé ¼ö ÀÖ´Ù. ÀÌ ½Ã¸®Á ÅëÇØ ½ºÅĵå¾ó·Ð ¾ÖÇø®ÄÉÀ̼ÇÀ» ±¸ÇöÇÏ´Â ¹æ¹ýÀ» Á¦½ÃÇÒ °ÍÀÌ´Ù. Part 1Àº "Hello, World" ¿¹Á¦·Î ½ÃÀÛÇÑ´Ù.

Introduction
¿ÀÇ ¼Ò½º Eclipse ÇÁ·ÎÁ§Æ®´Â ÀÚ¹Ù ºÐ¾ß¿¡ À־ ÃÖ±Ù °¡Àå Èï¹Ì·Î¿î °³¹ß ÇÁ·ÎÁ§Æ®Áß ÇϳªÀÌ´Ù. Eclipse´Â ±× ÀÚü·Î "ÀÏÁ¾ÀÇ ¹ü¿ë Åø Ç÷§Æû--°³¹æµÈ È®Àå°¡´ÉÇÑ IDE"·Î¼­ ¼³¸íµÈ´Ù. (Eclipse Platform ½ÃÀÛÇϱâ ÂüÁ¶).

EclipseÀÇ Áß¿ä ÄÄÆ÷³ÍÆ®µé Áß¿¡ SWT(±×·¡ÇÈ ¶óÀ̺귯¸®)¿Í JFace(¸ÅĪ À¯Æ¿¸®Æ¼ ÇÁ·¹ÀÓ¿÷)°¡ ÀÖ´Ù. ÀÌ µÎ °¡Áö ÄÄÆ÷³ÍÆ®¸¦ ÁýÁßÀûÀ¸·Î ´Ù·ç°Ú´Ù. Eclipse À¥ »çÀÌÆ®ÀÇ Eclipse ±â¼ú °³°ü¿¡´Â ´ÙÀ½°ú °°ÀÌ ¼³¸íÇÏ°í ÀÖ´Ù:

  • SWTÀº ¿ø½Ã À©µµ¿ì ½Ã½ºÅÛ¿¡ ÅëÇÕµÈ À§Á¬ ¼¼Æ®¿Í ±×·¡ÇÈ ¶óÀ̺귯¸®ÀÌ´Ù. ÇÏÁö¸¸ OS µ¶¸³ÀÇ API ÀÌ´Ù.
  • JFace´Â ÀϹÝÀûÀÎ UI ÇÁ·Î±×·¡¹Ö ŽºÅ©¸¦ °£´ÜÇÏ°ÔÇÏ´Â SWT¸¦ »ç¿ëÇÏ¿© ±¸ÇöµÈ UI ÅøŶÀÌ´Ù. JFace´Â API¿Í ±¸Çö¿¡ À־ À©µµ¿ì-½Ã½ºÅÛ µ¶¸³ÀûÀ̸ç À̸¦ ¼û±âÁö ¾Ê°í SWT¿Í ÀÛ¾÷ÇÒ ¼ö ÀÖµµ·Ï ¼³°èµÇ¾ú´Ù.

±×¸² 1Àº Eclipse, JFace, SWTÀÇ °ü°è¸¦ ³ªÅ¸³½ ±×¸²ÀÌ´Ù.

±×¸² 1. Eclipse Workbench, JFace, SWT
Figure 1. Eclipse Workbench, JFace, and SWT

Áö±Ý±îÁö JFace¿Í SWT¸¦ ´Ù·ç¾ú´ø ±Û ´ëºÎºÐÀº Å« Eclipse ÇÁ·¹ÀÓ¿÷¿¡¼­ À̵éÀ» »ç¿ëÇÏ´Â °üÁ¡¿¡¼­ ´Ù·ïÁö°í ÀÖ´Ù. ÀÌ ±Û¿¡¼­ ³ª´Â Á¶±Ý ´Ù¸¥ Á¢±Ù¹æ½ÄÀ» ÅÃÇÏ¿´´Ù. ½ºÅĵå¾ó·Ð ÀÚ¹Ù ÇÁ·Î±×·¥¿¡¼­ JFace¿Í SWT¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀ» ¼³¸íÇÒ °ÍÀÌ´Ù.

³»°¡ ¼±ÅÃÇÑ ¿¹Á¦´Â ÆÄÀÏ Å½»ö±âÀÌ´Ù. ½ÇÁ¦ ±â´ÉµéÀ» ¸¹ÀÌ ±¸ÇöÇÏÁö´Â ¾Ê°ÚÁö¸¸ ¿Ïº®ÇÑ ±â´ÉÀ» °®Ãá ÇÁ·Î±×·¥ÀÌ ¾î¶»°Ô ±¸ÇöµÇ´ÂÁö¸¦ ÀÌÇØÇÒ ¼ö ÀÖµµ·Ï ÃæºÐÇÑ GUI¸¦ º¸¿©ÁÙ °ÍÀÌ´Ù.

¼³Ä¡ note
¿¹Á¦¿ë ¼Ò½ºÄڵ带 ´Ù¿î·Îµå ÇÒ ¼ö ÀÖ´Ù. ´ÙÀ½Àº ³ªÀÇ ½Ã½ºÅÛ ¼³Á¤ »çÇ×ÀÌ´Ù:

  • Windows 2000
  • Eclipse, stable build M3 (November 15, 2002)
  • Eclipse installed in C:\eclipse-2.1.0

¿©·¯ºÐÀÇ ½Ã½ºÅÛ¿¡¼­ ÇÁ·Î±×·¥ÀÌ Á¤È®È÷ ÀÛµ¿ÇÒ ¼ö ÀÖµµ·Ï ¸¶À½²¯ Ä¿½ºÅ͸¶ÀÌ¡ Çصµ ÁÁ´Ù.

±¸Çö/½ÇÇà Áöħ
Ŭ·¡½º °æ·Î¿¡ ´ÙÀ½°ú °°Àº jar ÆÄÀÏÀÌ ÇÊ¿äÇÏ´Ù:

C:\eclipse-2.1.0\plugins\org.eclipse.jface_2.1.0\jface.jar
C:\eclipse-2.1.0\plugins\org.eclipse.runtime_2.1.0\runtime.jar
C:\eclipse-2.1.0\plugins\org.eclipse.swt.win32_2.1.0\ws\win32\swt.jar
C:\eclipse-2.1.0\plugins\org.eclipse.ui.workbench_2.1.0\workbench.jar
C:\eclipse-2.1.0\plugins\org.eclipse.core.runtime_2.1.0\runtime.jar

´ÙÀ½ ÀÎÀÚ·Î Java VMÀ» ½ÇÇàÇÏ¿© Java VMÀÌ ·±Å¸Àӽà »ç¿ëÇÒ GUI¿¡ ¸Â´Â °øÀ¯ ¶óÀ̺귯¸®¸¦ ¼±ÅÃÇß´ÂÁö È®ÀÎÇÑ´Ù:

-Djava.library.path=C:\eclipse-2.1.0\plugins\org.eclipse.swt.win32_2.1.0\os\win32\x86\

¸¶Áö¸·À¸·Î ¿¹Á¦°¡ ¾ÆÀÌÄÜÀ» Æ÷ÇÔÇÏ°í ÀÖ´Â gif ÆÄÀÏÀ» ãÀ» ¼ö ÀÖµµ·Ï icons Æú´õ¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Â Æú´õ¿¡¼­ ÇÁ·Î±×·¥À» ½ÇÇàÇÑ´Ù.

Hello, World
³»°¡ »ý°¢ÇÒ ¼ö ÀÖ´Â °¡Àå °£´ÜÇÑ JFace ÇÁ·Î±×·¥À¸·Î ½ÃÀÛÇغ¸ÀÚ. "Hello, World" ÇÁ·Î±×·¥ÀÌ´Ù.

Listing 1. Hello (version 1)

		
import org.eclipse.jface.window.*;
import org.eclipse.swt.widgets.*;

public class Hello
{
  public static void main(String[] args)
  {
    ApplicationWindow w = new ApplicationWindow(null);
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

¸ÞÀÎ ¸Þ¼Òµå°¡ ApplicationWindow¸¦ ¸¸µç °÷¿¡ Hello¶ó´Â Ŭ·¡½º°¡ »ý°å´Ù. ÀÌ°ÍÀ» ¿¬´Ù. setBlockOnOpen()Àº À©µµ¿ì°¡ ´ÝÈú ¶§±îÁö open()À» ¸·´Â´Ù.

À©µµ¿ì°¡ ´ÝÈ÷¸é ÇöÀç µð½ºÇ÷¹ÀÌ°¡ »ý±â°í À̸¦ ÀûÀýÈ÷ ¹èÄ¡ÇÑ´Ù. ÀÌ°ÍÀº OS¿¡ »ç¿ëµÈ ¸®¼Ò½º¸¦ ³»º¸³½´Ù.

ÇÁ·Î±×·¥À» ½ÇÇàÇÏ¸é ±×¸² 2 °°Àº À©µµ¿ì¸¦ º¸°ÔµÈ´Ù:

±×¸² 2. Hello (version 2)
Figure 2. Hello (version 2)

º¸ÀÌ´Â °ÍÀÌ ÀüºÎ´Ù. "Hello, World"¶ó´Â °Í Á¶Â÷ ¾ø´Ù. À̸¦ ÇȽºÇϱâ Àü¿¡ Àá½Ã ÁÖÁ¦¿¡¼­ ¹þ¾î³ª JFace À©µµ¿ì·Î °¡º¸ÀÚ.

JFace ¾ÖÇø®ÄÉÀÌ¼Ç À©µµ¿ì
À©µµ¿ì´Â »óÀ§ ·¹º§ À©µµ¿ì¿ë JFace Ŭ·¡½ºÀÌ´Ù. ´Ù½Ã¸»Çϸé OS À©µµ¿ì ¸Å´ÏÀú·Î °ü¸®µÈ´Ù. JFace À©µµ¿ì´Â »óÀ§ ·¹º§ À©µµ¿ì¿ë GUI °´Ã¼´Â ¾Æ´Ï´Ù. ´ë½Å JFace À©µµ¿ì´Â »óÀÀÇÏ´Â SWT ½© °´Ã¼¸¦ ¾Ë°íÀÖ°í À̸¦ ±¸Çö ¹× ÆíÁýÀ» µ½´Â Äڵ带 Á¦°øÇϸç À̺¥Æ®¸¦ µè´Â ¿ªÇÒÀ» ÇÏ´Â ÇïÆÛ °´Ã¼ÀÌ´Ù. ±×¸² 3Àº ÄÚµå, JFace, SWTÀÇ °ü°èÀÌ´Ù.

±×¸² 3. ÄÚµå, JFace Window, SWT Shell °ü°è
The relationship between your code, a JFace Window and an SWT Shell

»ç½Ç ÀÌ ¸ðµ¨Àº JFaceÀÇ ÀÛµ¿¹æ¹ýÀ» ÀÌÇØÇÒ ¼ö ÀÖ´Â ¿­¼èÀÌ´Ù. ÀÌ°ÍÀº SWTÀÇ »ó´Ü¿¡ ÀÖ´Â ·¹À̾ ¾Æ´Ï¸ç SWTÀ» ¼û±â·Á´Â ½Ãµµµµ ÇÏÁö ¾Ê´Â´Ù. ´ë½Å JFace´Â SWTÀÇ ´Ù¾çÇÑ »ç¿ë ÆÐÅÏÀ» ÀνÄÇÏ°í ÀÖÀ¸¸ç ÀÌ ÆÐÅÏÀ» ½±°Ô ÇÁ·Î±×·¡¹ÖÇÒ ¼ö ÀÖ´Â À¯Æ¿¸®Æ¼ Äڵ带 Á¦°øÇÑ´Ù.

À̸¦ À§ÇØ JFace´Â »ç¿ëÇÏ°í ÀÖ´Â °´Ã¼³ª ÇÏÀ§Å¬·¡½º·Î ³ª´­ ¼ö Àִ Ŭ·¡½º¸¦ Á¦°øÇÑ´Ù.

ApplicationWindow¸¦ Á÷Á¢ »ç¿ëÇßÁö¸¸ ±×µéÀº ½ÇÁ¦·Î ƯÁ¤ ÀÛµ¿À» ÇÏÀ§Å¬·¡½º·Î ³ª´©°í ƯÁ¤ ÀÛµ¿À¸·Î ä¿ìµµ·Ï ¼³°èµÇ¾ú´Ù. ¸Þ´º ¹Ù, Åø¹Ù, ¾ÖÇø®ÄÉÀÌ¼Ç ½ºÆÑÀÇ ÄÜÅÙÆ®¸¦ »ðÀÔÇÒ Àå¼Ò »óÅ ǥ½ÃÁÙ µîÀ» ¸¸µé ¼ö ÀÖ°Ô µÇ¾îÀÖ´Ù. ±×¸² 4´Â JFace File Explorer ÀÌ´Ù.

±×¸² 4. ¾ÖÇø®ÄÉÀÌ¼Ç À©µµ¿ìÀÇ ºÎºÐµé
Figure 4. The parts of an Application Window

Hello¸¦ ´Ùµë¾î¼­ ApplicationWindowÀÇ ÇÏÀ§Å¬·¡½º·Î ¸¸µç´Ù. º¯°æµÈ ¶óÀÎÀº Listing 2¿¡ Ç¥½ÃµÇ¾îÀÖ´Ù.

Listing 2. Hello (version 2)

		
import org.eclipse.jface.window.*;
import org.eclipse.swt.widgets.*;

public class Hello extends ApplicationWindow
{
  public Hello()
  {
    super(null);
  }

  public static void main(String[] args)
  {
    Hello w = new Hello();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

¿©·¯ºÐÀÌ ÀÛ¼ºÇÑ ±¸Á¶Ã¼´Â ÇÏÀ§Å¬·¡½º ±¸Á¶Ã¼¸¦ È£ÃâÇؾßÇÑ´Ù. ±× ±¸Á¶Ã¼¿¡ ´ëÇÑ ÀÎÀÚ´Â Àá½Ã ¹«½ÃÇÏÀÚ.

À̸¦ ½ÇÇàÇÑ´Ù°í Çؼ­ ÀÌÀü ÇÁ·Î±×·¥°ú ´Þ¶óÁø °ÍÀº ¾Æ¹«°Íµµ ¾ø´Ù. µðÆúÆ®´Â µ¥ÄÚ·¹À̼ÇÀÌ ¾ø´Ù.

¿ì¸® ÇÁ·Î±×·¥¿¡¼­´Â "Hello, World" ÅؽºÆ®°¡ µé¾îÀÖ´Â ¹öÆ°À» ¸¸µé°ÍÀÌ´Ù. ÀÌ ¹öÆ°Àº ÄÜÅÙÆ® ºÎºÐ¿¡ ³ªÅ¸³­´Ù. À̸¦ À§ÇØ Control createContents(Composite parent) ¸Þ¼Òµå¸¦ ¸¸µé¾î¾ßÇÑ´Ù.

ApplicationWindow´Â ¸ðµç ´Ù¸¥ À§Á¬ÀÌ ¸¸µé¾îÁø ÈÄ¿¡ À̸¦ È£ÃâÇÒ °ÍÀÌ´Ù. ÇÏÁö¸¸ ½ºÅ©¸°¿¡ À©µµ¿ì°¡ µð½ºÇ÷¹À̵DZâ Àü¿¡ È£ÃâÇÑ´Ù.

ÀÎÀÚ ºÎ¸ð´Â ÇöÁ¦ ¿µ¿ªÀ» ³ªÅ¸³»´Â º¹ÇÕ À§Á¬ÀÌ´Ù.

º¹ÇÕ À§Á¬À» ¸¸µé°í À̸¦ ºÎ¸ð¿¡ Ãß°¡ÇÏ°í ±×·± ´ÙÀ½ ÀÚ½ÅÀÇ À§Á¬¿¡ Ãß°¡ÇÏ°í ¿©·¯ºÐÀÌ ¸¸µç º¹ÇÕ À§Á¬À» ¸®ÅÏÇÏ´Â °³³äÀÌ´Ù. ±×¸² 5´Â ÀνºÅϽº °èÃþÀÌ´Ù.

±×¸² 5. Application WindowÀÇ ÀνºÅϽº °èÃþ
Figure 5. The instance hierarchy of an Application Window

ÄÜÅÙÆ®´Â ¸Å¿ì °£´ÜÇÏ´Ù. ºÎ¸ð ¹Ø¿¡ ÇϳªÀÇ ¹öÆ°ÀÌ ÀÖ´Ù. (Listing 3)

Listing 3. Hello (version 3)

		
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Hello extends ApplicationWindow
{
  public Hello()
  {
    super(null);
  }

  protected Control createContents(Composite parent)
  {
    Button b = new Button(parent, SWT.PUSH);
    b.setText("Hello World");
    return b;
  }

  public static void main(String[] args)
  {
    Hello w = new Hello();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

°á°ú´Â ±×¸² 6 ÀÌ´Ù.

±×¸² 6. Hello (version 3)
Figure 6. Hello (version 3)

JFace¿¡ ÀÖ´Â ¿ì¸®ÀÇ Ã¹ ¹ø° "Hello, World" ÇÁ·Î±×·¥ÀÌ´Ù: À©µµ¿ì¿¡´Â ÇϳªÀÇ ¹öÆ°ÀÌ Æ÷ÇԵǾî ÀÖ´Ù.

ÀÌÁ¦ ÆÄÀÏ Å½»ö±â·Î °¡º¸ÀÚ. ¿ì¼± Æú´õ °èÃþÀ» µð½ºÇ÷¹ÀÌÇÒ Æ®¸® ºä¾î¸¦ ¸¸µé°ÍÀÌ´Ù.

TreeViewer »ç¿ëÇϱâ
ApplicationWindow¿Í ¸¶Âù°¡Áö·Î TreeViewerµµ ½ÇÁ¦ SWT À§Á¬ÀÌ ¾Æ´Ï´Ù. ¶ÇÇÑ SWT À§Á¬À» ¼û±âÁöµµ ¾Ê´Â´Ù. SWT À§Á¬À» »ç¿ëÇÏ¿© ¾ÆÀÌÅÛÀ» µð½ºÇ÷¹ÀÌÇÏ°í À̸¦ µµ¿ï ¸¹Àº °´Ã¼µéÀ» »ç¿ëÇÑ´Ù.

ApplicationWindow¿Í´Â ´Ù¸£°Ô, JFace TreeViewer´Â ÇÏÀ§ Ŭ·¡½º·Î ³ª´µµµ·Ï µÇ¾îÀÖÁö ¾Ê´Ù.

TreeViewer´Â µð½ºÇ÷¹ÀÌÇÒ Æ®¸®ÀÇ »Ñ¸®(root) ¿¤¸®¸ÕÆ®¸¦ ¾Ë°í ÀÖ´Ù. ±× °´Ã¼´Â ¹°·Ð TreeViewer: void setInput(Object rootElement)ÀÌ´Ù.

½ÃÀÛÇϱâ À§Çؼ­ »Ñ¸® ¿¤¸®¸ÕÆ®¿¡ ÀÚ½ÄÀ» ¿äûÇÏ°í ±×·± ´ÙÀ½ ±×°ÍÀ» µð½ºÇ÷¹ÀÌÇÑ´Ù. ±×·± ´ÙÀ½ »ç¿ëÀÚ°¡ ÀÚ½Ä Áß Çϳª¸¦ È®ÀåÇÒ ¶§, TreeViewer´Â ÀÚ½Ä ¿ë ³ëµå¸¦ ¿äûÇÏ´Â ½ÄÀ¸·Î ³ª°£´Ù. ½ÇÁ¦·Î ÀÌ´Â »ç½ÇÀÌ ¾Æ´Ï´Ù. Æ®¸® ºä¾î´Â µµ¸ÞÀÎ °´Ã¼¿¡°Ô Á÷Á¢ ¸»ÇÏÁö ¾Ê´Â´Ù. ´ë½Å ContentProvider¶ó´Â ¶Ç ´Ù¸¥ °´Ã¼¸¦ »ç¿ëÇÏ°í ÀÌ °´Ã¼´Â ´ç½ÅÀÇ µµ¸ÞÀÎ °´Ã¼¸¦ »ç¿ëÇÑ´Ù. (±×¸² 7).

±×¸² 7. TreeViewer, ContentProvider, µµ¸ÞÀÎ °´Ã¼
Figure 7. TreeViewer, ContentProvider and domain objects

¹°·Ð ContentProvider¸¦ ±¸ÇöÇØ¾ß ÇÑ´Ù. TreeViewerÀÇ °æ¿ì Ŭ·¡½º´Â ITreeContentProvider ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇØ¾ß ÇÑ´Ù.

TreeContentProvider ±¸ÇöÇϱâ
±¸ÇöÇØ¾ß ÇÒ ¸Þ¼Òµå´Â ¿©¼¸ °³´Ù. ÀÌÁß ¼¼ °³´Â ±¸ÇöÇÏÁö ¾Ê¾Æµµ µÈ´Ù.

´ÙÀ½Àº Æ®¸® ºä¾î°¡ ÄÜÅÙÆ® Á¦°øÀÚ¿¡°Ô »Ñ¸® ¿¤¸®¸ÕÆ® ¹Ø¿¡ ÀÖ´Â »óÀ§ ·¹º§ ¿¤¸®¸ÕÆ®¸¦ ¿äûÇÏ´Â ¹æ¹ýÀÌ´Ù:

ITreeContentProvider: public Object[] getElements(Object element)

±×¸®°í ƯÁ¤ ¿¤¸®¸ÕÆ®ÀÇ ÀÚ½ÄÀÌ ÇÊ¿äÇÒ ¶§ ¸¶´Ù ´ÙÀ½À» »ç¿ëÇÑ´Ù:

ITreeContentProvider: public Object[] getChildren(Object element)

³ëµå°¡ ÀڽĵéÀ» °®°í ÀÖ´ÂÁö¸¦ È®ÀÎÇÏ·Á¸é Æ®¸® ºä¾î´Â ³ëµåÀÇ ÀڽĵéÀ» ¿äûÇÒ ¼ö ÀÖ°í ±×°ÍÀÌ ¸î °³ ÀÎÁö¸¦ ¹°À» ¼ö ÀÖ´Ù. Äڵ尡 À̸¦ ºü¸£°Ô ¼öÇàÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀ» ¾Æ´Â °æ¿ì¿¡´Â ±¸ÇöÇؾßÇÒ ¶Ç ´Ù¸¥ ¸Þ¼Òµå°¡ ÀÖ´Ù:

public boolean hasChildren(Object element)

º¸½Ã´Ù½ÃÇÇ ÄÜÅÙÆ® Á¦°øÀÚ´Â µµ¸ÞÀÎ °´Ã¼¿¡ ´ëÇÑ ·¹ÆÛ·±½º¸¦ °®°í ÀÖÁö ¾Ê´Ù. ÀÌ°ÍÀ» °®°í ÀÖ´Â °ÍÀº Æ®¸® ºä¾îÀÌ¸ç ±×µéÀ» ÀÎÀڷμ­ ÄÜÅÙÆ® Á¦°øÀÚ¿¡ ÀÖ´Â °¢°¢ÀÇ ¸Þ¼Òµå¿¡ Àü´ÞÇÑ´Ù.

¿ì¸® °°Àº °æ¿ì ³ëµå´Â File °´Ã¼ÀÌ´Ù. ÀÚ½ÄÀ» ¾ò±â À§Çؼ­´Â listFiles()¸¦ »ç¿ëÇÑ´Ù. listFiles()°¡ nullÀ» ¸®ÅÏÇÏ´ÂÁö¸¦ °Ë»çÇÏ°í ±×°ÍÀ» ºó(empty) ¾î·¹ÀÌ·Î ÀüȯÇؾßÇÑ´Ù.

»Ñ¸® ¿¤¸®¸ÕÆ® ¹Ù·Î ¹Ø¿¡ ÀÖ´Â »óÀ§ ·¹º§ ¿¤¸®¸ÕÆ®¸¦ ¾ò±â À§Çؼ­´Â getChildren() ¸Þ¼Òµå¸¦ Àç»ç¿ëÇÒ ¼ö ÀÖ´Ù.

getParent() ¸Þ¼Òµå´Â reveal(Object element) ¸Þ¼Òµå¸¦ ±¸ÇöÇϴµ¥ »ç¿ëµÇ´Âµ¥, ÀÌ°ÍÀº Æ®¸® ºä¾î°¡ Æ®¸® ¾ÈÀÇ Æ¯Á¤ ³ëµå¸¦ µð½ºÇ÷¹ÀÌÇϱâ À§ÇØ SWT Æ®¸® À§Á¬À» ½ºÅ©·ÑÇϵµ·Ï ÇÑ´Ù. ±× ³ëµå°¡ ±× »óȲ¿¡¼­ ½ÇÁ¦·Î µð½ºÇ÷¹À̵ÇÁö ¾Ê´Â´Ù¸é ¾îµð¿¡ µð½ºÇ÷¹ÀÌ µÇ´ÂÁö°¡ ¹®Á¦ÀÌ´Ù. JFace´Â ³ëµå°¡ µð½ºÇ÷¹ÀÌµÉ ¶§ ±îÁö ÀÌ°ÍÀÇ ºÎ¸ð¸¦ °Ë»öÇÏ°í ±×·± ´ÙÀ½ ºÎ¸ðÀÇ ºÎ¸ð¸¦ °Ë»öÇÏ´Â ½ÄÀ¸·Î ¼öÇàÇÏ°í Ÿ°Ù ³ëµå°¡ µð½ºÇ÷¹ÀÌµÉ ¶§±îÁö ¹Ýº¹ÀûÀ¸·Î Æ®·¡Å·ÇÑ´Ù.

hasChildren() ¸Þ¼Òµå´Â ºÐ¸íÇÑ ¾î¶² °ÍÀ» ¼öÇàÇÏ°í Listing 4ÀÇ ÄÚµå·Î ³¡À» ¸Î´Â´Ù.

Listing 4. FileTreeContentProvider (version 1)

		
import java.io.*;
import java.util.*;
import org.eclipse.jface.viewers.*;

public class FileTreeContentProvider implements ITreeContentProvider
{
  public Object[] getChildren(Object element)
  {
    Object[] kids = ((File) element).listFiles();
    return kids == null ? new Object[0] : kids;
  }

  public Object[] getElements(Object element)
  {
    return getChildren(element);
  }

  public boolean hasChildren(Object element)
  {
    return getChildren(element).length > 0;
  }

  public Object getParent(Object element)
  {
    return ((File)element).getParent();
  }
  
  public void dispose()
  {
  }

  public void inputChanged(Viewer viewer, Object old_input, Object new_input)
  {
  }
}

»óÀ§·¹º§ÀÇ Explorer Ŭ·¡½º ±¸ÇöÇϱâ
Hello, World ÇÁ·Î±×·¥À» °¡Á®´Ù°¡ ÀÌ°ÍÀÇ À̸§À» ¹Ù²Ù°í createContents() ¸Þ¼Òµå¿¡ ¹öÆ°À» ¸¸µå´Â ´ë½Å TreeViewer¸¦ ¸¸µé°í ÀÌ°ÍÀÇ ÄÜÅÙÆ® Á¦°øÀÚ¸¦ ÆÄÀÏ Æ®¸® ÄÜÅÙÆ® Á¦°øÀÚ·Î ¼³Á¤ÇÏ°í Æú´õ¿¡ ÀÎDzÀ» ¼³Á¤ÇÑ´Ù. ÀÌ °æ¿ì ³»°¡ ¼±ÅÃÇÑ Æú´õ´Â C: µå¶óÀ̺꿡 ÀÖ´Â »óÀ§ ·¹º§ Æú´õÀÌ´Ù.

createContents()·Î ºÎÅÍ SWT À§Á¬À» ¸®ÅÏÇÒ °ÍÀ» ¿äû¹Þ¾Ò´Ù´Â °Í¿¡ ÁÖ¸ñÇÏÀÚ. ¾Õ¼­ ¾ð±ÞÇßµíÀÌ JFace Tree Viewer´Â SWT À§Á¬ÀÌ ¾Æ´Ï´Ù. µû¶ó¼­ ÀÌ°ÍÀ» ¸®ÅÏÇÒ ¼ö ¾ø´Ù. Æ®¸® ºä¾î¿¡¼­ ½ÇÁ¦ À§Á¬À» ¾ò¾î¾ßÇÑ´Ù. getTree()¸¦ »ç¿ëÇÏ¿© À̸¦ ¼öÇàÇÑ´Ù.

¸ÞÀÎ À©µµ¿ì Ŭ·¡½º´Â ´ÙÀ½°ú °°´Ù:

Listing 5. Explorer (version 1)

		
import java.io.*;

import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Explorer extends ApplicationWindow
{
  public Explorer()
  {
    super(null);
  }

  protected Control createContents(Composite parent)
  {
    TreeViewer tv = new TreeViewer(parent);
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setInput(new File("C:\\"));
    return tv.getTree();
  }

  public static void main(String[] args)
  {
    Explorer w = new Explorer();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

ÀÌ ÇÁ·Î±×·¥À» ½ÇÇàÇÏ¸é ±×¸² 8°ú °°ÀÌ µÈ´Ù.

±×¸² 8. Explorer (version 1)
Figure 8. Explorer (version 1)

´Ù¸¥ ÄÚµåµéÀº Á¦ÃÄ µÎ°í ÀÏ´Ü 9 ¹ø° ¶óÀÎÀÇ Äڵ带 Hello, World ÇÁ·Î±×·¥¿¡ Ãß°¡Çß¾î¾ß Çß´Ù.

¿©·¯ºÐµµ °°Àº »ý°¢ÀÌ°ÚÁö¸¸ File¿¡ ÀÖ´Â toString() ¸Þ¼Òµå¸¦ »ç¿ëÇÏ¿© µð½ºÇ÷¹À̵ȴÙ. ÀÌ°ÍÀº ¿ì¸®°¡ ¿øÇÏ´ø °ÍÀÌ ¾Æ´Ï´Ù. À̸¦ º¯°æÇÏ·Á¸é ·¹À̺í(lable) Á¦°øÀÚ°¡ ÇÊ¿äÇÏ´Ùr.

·¹À̺í Á¦°øÀÚ ±¸ÇöÇϱâ
Æ®¸® ³ëµåÀÇ ÀڽĵéÀ» ¾ò´Â ÄÜÅÙÆ® Á¦°øÀÚ °´Ã¼°¡ ÀÖµíÀÌ ½ÇÁ¦·Î ³ëµå¸¦ µð½ºÇ÷¹ÀÌ ÇÒ ¶§ Æ®¸® ºä¾î´Â ¶Ç ´Ù¸¥ ÇïÆÛ °´Ã¼¸¦ °®°íÀÖ´Ù. ¹Ù·Î ·¹À̺í Á¦°øÀÚ(label provider)ÀÌ´Ù. Àü°ú °°ÀÌ À̸¦ ¼³Á¤ÇؾßÇÑ´Ù:

public void setLabelProvider(IBaseLabelProvider labelProvider)

°¢ ¿¤¸®¸ÕÆ®¸¦ À§ÇØ µð½ºÇ÷¹ÀÌ ÇÒ ÅؽºÆ®¸¦ ¸®ÅÏÇϱâ À§ÇØ ¸Þ¼Òµå¸¦ ±¸ÇöÇØ¾ß ÇÑ´Ù:

public String getText(Object element)

Æ®¸® ºä¾î¸¦ À§ÇØ ´ÙÀ̾î±×·¥¿¡ ·¹À̺í Á¦°øÀÚ¸¦ Ãß°¡ÇÏ¸é ±×¸² 9¿Í °°ÀÌ µÈ´Ù.

±×¸² 9. ÄÜÅÙÆ® Á¦°øÀÚ¿Í ·¹À̺í Á¦°øÀÚ¸¦ º¸¿©ÁÖ´Â Tree Viewer
Figure 9. Tree Viewer showing content provider and label provider

¿ì¸®°¡ ±¸ÇöÇÒ ¼ö ÀÖ´Â ÀÎÅÍÆäÀ̽º(ILabelProvider)°¡ ÀÖÁö¸¸ ±âº» ±¸Çö(LabelProvider)À» ÇÏÀ§·Î ³ª´©´Â°Ô ´õ ½±´Ù.

getText()¿¡¼­ ½ÇÇàÇÏ·Á´Â °ÍÀº ÆÄÀÏ À̸§ÀÇ ¸¶Áö¸· ºÎºÐÀ» ¸®ÅÏÇÏ´Â °ÍÀÌ´Ù. Listing 6Àº ±× ÄÚµåÀÌ´Ù.

Listing 6. FileTreeLabelProvider (version 1)

		
import java.io.*;
import org.eclipse.jface.viewers.*;

public class FileTreeLabelProvider extends LabelProvider
{
  public String getText(Object element)
  {
    return ((File) element).getName();
  }
}

Listing 7 ó·³ ÀÌ ·¹À̺í Á¦°øÀÚ¸¦ Æ®¸® ºä¾î°¡ »ç¿ëÇϵµ·Ï ÇؾßÇÑ´Ù.

Listing 7. Explorer (version 2)

		
import java.io.*;

import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Explorer extends ApplicationWindow
{
  public Explorer()
  {
    super(null);
  }

  protected Control createContents(Composite parent)
  {
    TreeViewer tv = new TreeViewer(parent);
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput(new File("C:\\"));
    return tv.getTree();
  }

  public static void main(String[] args)
  {
    Explorer w = new Explorer();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

ÀÌ ÇÁ·Î±×·¥À» ½ÇÇàÇϸé Á»´õ ±ú²ýÇÑ °á°ú¸¦ ¾ò°ÔµÈ´Ù. (±×¸² 10).

±×¸² 10. Explorer (version 2)
Figure 10. Explorer (version 2)

ÀÌÁ¦´Â Æ®¸® ºä¾î¸¦ ¿ÞÂÊÀ¸·Î ¿Å±â°í ¿À¸¥ÂÊ¿¡ Å×ÀÌºí ºä¸¦ ³õ¾Æ Æ®¸® ºä¾î¿¡¼­ ¼±ÅÃÇÑ Æú´õ¿¡ ÀÖ´Â ÆÄÀÏ ¸®½ºÆ®¸¦ º¸À̵µ·Ï ÇÑ´Ù.

Å×ÀÌºí ºä¾î(table viewer) »ç¿ëÇϱâ
JFace´Â Å×À̺íÀ» ÇÚµéÇÒ ¼ö ÀÖ´Â TableViewer¸¦ °®°íÀÖ´Ù. TreeViewer¿Í ¸¶Âù°¡Áö·Î ÀÎDz(·çÆ® °´Ã¼), ÄÜÅÙÆ® Á¦°øÀÚ, ·¹À̺í Á¦°øÀÚ¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Ù. Æ®¸®¸¦ ´Ù·ê ÇÊ¿ä°¡ ¾ø±â ¶§¹®¿¡ Æ®¸® ºä¾îº¸´Ù °£´ÜÇÏ´Ù. ±×¸² 11Àº ÄÜÅÙÆ® Á¦°øÀÚ¿Í ·¹À̺í Á¦°øÀÚÀÌ´Ù.

±×¸² 11. ÄÜÅÙÆ® Á¦°øÀÚ¿Í ·¹À̺í Á¦°øÀÚ¸¦ º¸¿©ÁÖ´Â Å×ÀÌºí ºä¾î
Figure 11. Table Viewer showing content provider and label provider

ÀÎDz °´Ã¼¸¦ ¼³Á¤ÇÏ´Â ¸Þ¼Òµå´Â Àü°ú °°´Ù:

TableViewer: void setInput(Object rootElement)

ÆÄÀÏ Å×ÀÌºí ºä¾î ÄÜÅÙÆ® Á¦°øÀÚ ±¸ÇöÇϱâ
ÄÜÅÙÆ® Á¦°øÀÚ¸¦ º¸ÀÚ. ·çÆ® ¿¤¸®¸ÕÆ®´Â Æ®¸® ºä¾î ·çÆ® ¿¤¸®¸ÕÆ® º¸´Ù °£´ÜÇÏ´Ù. Å×ÀÌºí ºä¾î´Â ·çÆ® °´Ã¼°¡ ¸¹Àº ÀڽĵéÀ» °®°íÀÖÀ» °ÍÀ̶ó°í ±â´ëÇÒ »ÓÀÌ´Ù. µû¶ó¼­ ±¸ÇöÇÒ Àç¹ÌÀÖ´Â ¸Þ¼Òµå´Â ÀڽĵéÀ» ¾ò´Â ¸Þ¼ÒµåÀÌ´Ù:

public Object[] getElements(Object rootElement)

±¸ÇöÇØ¾ß ÇÏ´Â ÀÎÅÍÆäÀ̽º´Â IStructuredContentProvider ÀÌ´Ù.

·çÆ® °´Ã¼´Â Æú´õ°¡ µÈ´Ù. ÀÌ°ÍÀÇ ÀڽĵéÀº ±× Æú´õ°¡ Æ÷ÇÔÇÏ°í ÀÖ´Â ÆÄÀÏ/Æú´õµéÀÌ µÉ °ÍÀÌ´Ù. µû¶ó¼­ ¿ì¸®ÀÇ ÆÄÀÏ Å×À̺í ÄÜÅÙÆ® Á¦°øÀÚ Å¬·¡½º´Â ´ÙÀ½°ú °°´Ù.(Listing 8)

Listing 8. FileTableContentProvider (version 1)

		
import java.io.*;

import org.eclipse.jface.viewers.*;

public class FileTableContentProvider implements IStructuredContentProvider
{
  public Object[] getElements(Object element)
  {
    Object[] kids = null;
    kids = ((File) element).listFiles();
    return kids == null ? new Object[0] : kids;
  }

  public void dispose()
  {
  }

  public void inputChanged(Viewer viewer, Object old_object, Object new_object)
  {
  }
}

ÀÌÁ¦ µÎ °³ÀÇ ºä¾î(Æ®¸® ºä¾î¿Í Å×ÀÌºí ºä¾î)°¡ »ý°å´Ù. ¼­·Î¼­·Î ¿·À¸·Î ³ª¶õÈ÷ Á¤·ÄÇϱâ À§ÇØ SWT SashForm À§Á¬À» ¸¸µç´Ù. ÀÌ À§Á¬Àº »ç¿ëÀÚ°¡ Á¶Á¤ÇÒ ¼ö ÀÖ´Â °æ°è(border)·Î ÀÌ ÀڽĵéÀ» ³ª´«´Ù. ±×·± ´ÙÀ½ Æ®¸®¿Í Å×À̺íÀ» sash form¿¡ Ãß°¡ÇÑ´Ù. (±×¸² 12).

±×¸² 12. Æ®¸® ºä¾î¿Í Å×ÀÌºí ºä¾î¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Â sash form
Figure 12. The sash form contains the tree viewer and the table viewer

´ÙÀ½¿¡ ÇØ¾ß ÇÒ ÀÏÀº Å×ÀÌºí ºä¾î°¡ »ç¿ëÀÚ°¡ Æ®¸® ºä¾î¿¡¼­ ¼±ÅÃÇÑ °¢°¢ÀÇ Æú´õ¸¦ º¼ ¼ö ÀÖµµ·Ï ¸¸µå´Â °ÍÀÌ´Ù. À̸¦ À§Çؼ­´Â À̺¥Æ® µè±â¸¦ ÇؾßÇÑ´Ù.

À̺¥Æ® µè±â
»ç¿ëÀÚ°¡ Æ®¸® ºä¾î¿¡¼­ ÇÑ ¾ÆÀÌÅÛÀ» ¼±ÅÃÇÒ ¶§ Æ®¸® ºä¾î´Â À̺¥Æ®(SelectionChangedEvent)¸¦ ¹ß»ý½ÃŲ´Ù. ¿ì¸®´Â ±× À̺¥Æ®¸¦ µé¾î¾ßÇϸç À̺¥Æ®°¡ ¹ß»ýÇÒ ¶§ Å×À̺í¿ë ÀÎDzÀÌ Æ®¸® ºä¾î¿¡¼­ ÇöÀç ¼±ÅÃµÈ ÆÄÀÏÀÌ µÇµµ·Ï ¼³Á¤ÇؾßÇÑ´Ù.

Æ®¸® ºä¿¡¾î¼­ ¹ß»ýÇÑ ¼±Åà º¯°æµÈ À̺¥Æ®¸¦ µè±â À§Çؼ­ ´ÙÀ½À» »ç¿ëÇÑ´Ù:

public void addSelectionChangedListener(ISelectionChangedListener?listener)

»ç¿ëÀÚ°¡ Æ®¸® ºä¾î¿¡¼­ ³ëµå¸¦ ¼±ÅÃ/¼±ÅÃÇØÁ¦ ÇÒ ¶§, º¯°æµÈ ¼±Åà ¸®½º³Ê´Â ´ÙÀ½À» »ç¿ëÇÏ¿© È£ÃâµÈ´Ù:

public void selectionChanged(SelectionChangedEvent event)

ÀÌ ¸®½º³Ê Ŭ·¡½º¸¦ ±¸ÇöÇÏ·Á¸é ¸ÞÀÎ Explorer Window¿¡ ¸¹Àº Ŭ·¡½º¸¦ ÄÚµùÇØ¾ß ÇÑ´Ù. selectionChanged() ¸Þ¼Òµå¿¡¼­ ¼±ÅÃµÈ °´Ã¼¸¦ °®°í ÀÖ¾î¾ß Çϸç ÀÌ°ÍÀ» Å×ÀÌºí ºä¾î¿ë ÀÎDzÀ¸·Î ¸¸µé¾î¾ßÇÑ´Ù. À̸¦ ¸ðµÎ ¸ðÀ¸¸é Listing 9°¡ µÈ´Ù.

Listing 9. Explorer (version 3)

		
import java.io.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.widgets.*;

public class Explorer extends ApplicationWindow
{
  public Explorer()
  {
    super(null);
  }

  protected Control createContents(Composite parent)
  {
    SashForm sash_form = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL);

    TreeViewer tv = new TreeViewer(sash_form);
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput(new File("C:\\"));

    final TableViewer tbv = new TableViewer(sash_form, SWT.BORDER);
    tbv.setContentProvider(new FileTableContentProvider());

    tv.addSelectionChangedListener(new ISelectionChangedListener()
    {
      public void selectionChanged(SelectionChangedEvent event)
      {
        IStructuredSelection selection =
          (IStructuredSelection) event.getSelection();

        Object selected_file = selection.getFirstElement();
        tbv.setInput(selected_file);
      }
    });
    
    return sash_form;
  }

  public static void main(String[] args)
  {
    Explorer w = new Explorer();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

ÀÌ ÇÁ·Î±×·¥À» ½ÇÇàÇÏ¸é ±×¸² 13ÀÌ µÈ´Ù.

±×¸² 13. Explorer (version 3)
Figure 13. Explorer (version 3)

Æ®¸® ºä¾î¿Í ¸¶Âù°¡Áö·Î Å×ÀÌºí ºä¾îÀ§¿¡ ·¹À̺í Á¦°øÀÚ¸¦ ¼³Á¤ÇÏÁö ¾Ê´Â´Ù¸é µðÆúÆ® ·¹À̺í Á¦°øÀÚ¸¦ »ç¿ëÇϰԵȴÙ. ±âº» ÀÛµ¿Àº ¿¤¸®¸ÕÆ®ÀÇ toString() ¸Þ¼Òµå¿¡ ÀÇÇØ ¸®ÅÏµÈ ½ºÆ®¸µÀ» µð½ºÇ÷¹ÀÌÇÑ´Ù. Àý´ëÀû ÆÄÀÏ À̸§À¸·Î µð½ºÇ÷¹À̵ȴÙ.

ÀÌÁ¦ Å×ÀÌºí ·¹À̺í Á¦°øÀÚ¸¦ ¸¸µé¾îº¸ÀÚ.

Å×ÀÌºí ·¹À̺í Á¦°øÀÚ ±¸ÇöÇϱâ
Áö±Ý ÇöÀç ¸Þ¼Òµå Çϳª¸¦ À¯ÀÇÇØ¾ß ÇÑ´Ù:

public String getColumnText(Object element, int column)

µÎ °³ÀÇ ÀÎÀÚ°¡ ÀÖ´Ù: ·¹À̺íÀ» ¾ò´Â ¿¤¸®¸ÕÆ®¿Í (0À¸·Î ½ÃÀÛÇÏ´Â) Ä®·³ À妽º .

±¸ÇöÀº °£´ÜÇÏ´Ù. Ä®·³ À妽º ÀÎÀÚ¸¦ ¹«½ÃÇÑ´Ù¸é ´ÙÀ½°ú °°´Ù. (Listing 10).

Listing 10. FileTableLabelProvider (version 1)

		
import java.io.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.*;

public class FileTableLabelProvider implements ITableLabelProvider
{
  public String getColumnText(Object obj, int i)
  {
    return ((File) obj).getName();
  }

  public void addListener(ILabelProviderListener ilabelproviderlistener)
  {
  }

  public void dispose()
  {
  }

  public boolean isLabelProperty(Object obj, String s)
  {
    return false;
  }

  public void removeListener(ILabelProviderListener ilabelproviderlistener)
  {
  }
  
  public Image getColumnImage(Object arg0, int arg1)
  {
    return null;
  }
}

Å×À̺íÀÌ "Name" À̶ó´Â ·¹À̺íÀÌ ÀÖ´Â Çì´õ¸¦ °¡Áø ÇϳªÀÇ Ä®·³À» °®Ãßµµ·Ï ¼³Á¤ÇÏ·Á¸é Å×ÀÌºí ºä¾î¿¡¼­ Å×À̺í À§Á¬À» ÃßÃâÇÏ¿© Å×À̺íÀÇ ÀÚ½ÄÀ¸·Î¼­ Å×À̺í Ä®·³ À§Á¬À» ¸¸µé°í ÀÌ¿¡ ´ëÇÑ ¸î °¡Áö ¼Ó¼ºÀ» ¼³Á¤ÇؾßÇÑ´Ù.(Listing 11).

Listing 11. Explorer (version 4)

		
import java.io.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.widgets.*;

public class Explorer extends ApplicationWindow
{
  public Explorer()
  {
    super(null);
  }

  protected Control createContents(Composite parent)
  {
    SashForm sash_form = new SashForm(parent, SWT.HORIZONTAL | SWT.NULL);

    TreeViewer tv = new TreeViewer(sash_form);
    tv.setContentProvider(new FileTreeContentProvider());
    tv.setLabelProvider(new FileTreeLabelProvider());
    tv.setInput(new File("C:\\"));

    final TableViewer tbv = new TableViewer(sash_form, SWT.BORDER);
    tbv.setContentProvider(new FileTableContentProvider());
    tbv.setLabelProvider(new FileTableLabelProvider());

    TableColumn column = new TableColumn(tbv.getTable(), SWT.LEFT);
    column.setText("Name");
    column.setWidth(200);
    tbv.getTable().setHeaderVisible(true);

    tv.addSelectionChangedListener(new ISelectionChangedListener()
    {
      public void selectionChanged(SelectionChangedEvent event)
      {
        IStructuredSelection selection =
          (IStructuredSelection) event.getSelection();

        Object selected_file = selection.getFirstElement();
        tbv.setInput(selected_file);
      }
    });
    return sash_form;
  }

  public static void main(String[] args)
  {
    Explorer w = new Explorer();
    w.setBlockOnOpen(true);
    w.open();
    Display.getCurrent().dispose();
  }
}

ÀÌ ¸ðµç °ÍÀ» ¼öÇàÇÑ ÈÄ °á°ú´Â ±×¸² 14¿Í °°´Ù.

±×¸² 14. Explorer (version 4)
Figure 14. Explorer (version 4)

Âü°íÀÚ·á

¸ñ Â÷:
Introduction
Hello, World
JFace ¾ÖÇø®ÄÉÀÌ¼Ç À©µµ¿ì
TreeViewer »ç¿ëÇϱâ
TreeContentProvider ±¸ÇöÇϱâ
»óÀ§·¹º§ÀÇ Explorer Ŭ·¡½º ±¸ÇöÇϱâ
·¹À̺í Á¦°øÀÚ ±¸ÇöÇϱâ
Å×ÀÌºí ºä¾î(table viewer) »ç¿ëÇϱâ
ÆÄÀÏ Å×ÀÌºí ºä¾î ÄÜÅÙÆ® Á¦°øÀÚ ±¸ÇöÇϱâ
À̺¥Æ® µè±â
Å×ÀÌºí ·¹À̺í Á¦°øÀÚ ±¸ÇöÇϱâ
Âü°í ÀÚ·á
ÇÊÀÚ ¼Ò°³
±â»ç¿¡ ´ëÇÑ Æò°¡
°ü·Ã dW ¸µÅ©:
Part 2 of this series
Eclipse Platform ½ÃÀÛÇϱâ
Eclipse Ç÷¯±×ÀÎ °³¹ßÇϱâ
Subscribe to the developerWorks newsletter
US ¿ø¹® Àбâ
Also in the Java zone:
Tutorials
Tools and products
Code and components
Articles
ÇÊÀÚ¼Ò°³
Photo of authorA. O. Van Emmenis´Â µ¶¸³ ÄÁ¼³ÅÏÆ®·Î¼­ ¿µ±¹ Ä·ºê¸®Áö¿¡¼­ Java/J2EE Æ®·¹ÀÌ´× ¹× ÄÁ¼³ÆÃÀ» ´ã´çÇÏ°í ÀÖ´Ù.
ÀÌ ±â»ç¿¡ ´ëÇÏ¿© ¾î¶»°Ô »ý°¢ÇϽʴϱî?

Á¤¸» ÁÁ´Ù (5) ÁÁ´Ù (4) ±×Àú±×·¸´Ù (3) ¼öÁ¤º¸¿ÏÀÌ ÇÊ¿äÇÏ´Ù(2) ÇüÆí¾ø´Ù (1)

  È¸»ç¼Ò°³  |  °³ÀÎÁ¤º¸ º¸È£Á¤Ã¥  |  ¹ý·ü  |  ¹®ÀÇ