IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IViewReference viewReference = activePage.findViewReference(ContentTreeViewer.ID);

if (viewReference == null) {

try {

activePage.showView(ContentTreeViewer.ID);

} catch (PartInitException e) {

LOGGER.error("OpenSlipView Error : " , e);

}

} else {

activePage.hideView(viewReference);

}

public void processExcelExport(ExcelExportActionNotification object) {


Display.getDefault().syncExec(new Runnable() {

public void run() {

try {

FileDialog fd = new FileDialog(object.getTable().getControl().getShell(), SWT.SAVE);

fd.setText("Save");

fd.setFilterPath("C:/");

String[] filterExt = {"*.xls", "*.*" };

fd.setFilterExtensions(filterExt);

String path = fd.open();


if (path == null || path == "" || fd.getFileName() == null || fd.getFileName() == "") {

exceptionHandler.handleException(Message.ExportcancelMsg);

return;

}

FileContainer.getInstance().setFilePath(path);

new ProgressMonitorDialog(object.getTable().getControl().getShell()).run(false, false,

new LongRunningOperation(object, path));

} catch (Exception e) {

LOGGER.error("Export Error", e);

exceptionHandler.handleException(Message.errExportContent);

}

}

});

}


public class LongRunningOperation implements

IRunnableWithProgress {

ExcelExportActionNotification notification;

String path;


public LongRunningOperation(ExcelExportActionNotification object, String path) {

this.notification = object;

this.path = path;

}


@Override

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

try (FileOutputStream out = new FileOutputStream(FileContainer.getInstance().getCurrentFile())) {

//Create Data, 작업량 설정

monitor.beginTask("Export Data",

notification.getTable().getTable().getItemCount() * notification.getColumn_header().length);



//Create workbook and sheet

workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet();

sheet.setGridsPrinted(true);

sheet.setFitToPage(true);

sheet.setDisplayGuts(true);


//Header 설정

row = sheet.createRow(0);

for (int colIndex = 0; colIndex < notification.getColumn_header().length; colIndex++) {

cell = row.createCell(colIndex);

cell.setCellValue(notification.getColumn_header()[colIndex]);

}


//Data Input

for (int rowIndex = 0; rowIndex < notification.getTable().getTable().getItemCount(); rowIndex++) {

row = sheet.createRow(rowIndex + 1);

for (int colIndex = 0; colIndex < notification.getColumn_header().length; colIndex++) {

cell = row.createCell(colIndex);

cell.setCellValue(notification.getTable().getTable().getItem(rowIndex).getText(colIndex));

monitor.worked(1);

}

}


monitor.done();

workbook.write(out);


//내보내기가 완료된 엑셀파일 실행

if (MessageDialog.openConfirm(null, Message.successTitle, Message.msgExportSuccess)) {

Program program = Program.findProgram("xls");

program.execute(path);

}

} catch (IOException e) {

LOGGER.error("Export Error", e);

exceptionHandler.handleException(Message.errExportContent);

} finally {

workbook = null;

row = null;

cell = null;

}

}

}


결과 화면

 

글로벌 application 키, 마우스 이벤트를 감지하기 위해서는


워크벤치에서 activeWorkbenchWindow shell에서 getdisplay().addfilter 통해 등록을 해줘야 한다.


addFilter(swt.keydown, new listener() {

Public void handle(event e) {

 

}

}

 

Shell 있는 filter 있는 리스너는 다른 위젯 리스너에 도달하기전에 모든 이벤트를 먼저 필터한다.


그렇기 때문에


해당 이벤트 필터는 다른 이벤트를 못가게 막을 수도 있고 이벤트 사이에 필드를 지정할  있다



그래서 event 필터는 강력하지만 위험하다그래서  하지않는다.

shell에 리스너를 추가하여 


shell이 최소화 되었을 때, 다시 최대화 되었을 때, 활성화 됬을 때 종료됬을 때 등


shell 자체의 이벤트에 대한 리스너를 설정할 수 있다. 


  shell.addShellListener(new ShellListener() {


      public void shellActivated(ShellEvent event) {

        System.out.println("activate");

      }


      public void shellClosed(ShellEvent arg0) {

        System.out.println("close");

      }


      public void shellDeactivated(ShellEvent arg0) {

      }


      public void shellDeiconified(ShellEvent arg0) {

      }


      public void shellIconified(ShellEvent arg0) {

      }

    });

RCP ActivePage에 특정 View 열기


IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

IViewReference viewReference = activePage.findViewReference(SlipView.ID);

if (viewReference == null) {

try {

activePage.showView(SlipView.ID);

} catch (PartInitException e) {

LOGGER.error("OpenSlipView Error : " , e);

}

}

+ Recent posts