/**
   * resource load
   *
   * @param input
   */
  private void loadDBRsource(IEditorInput input) {
    TadpoleRDBEditorInput erdInput = (TadpoleRDBEditorInput) input;
    userDB = erdInput.getUserDBDAO();
    isAllTable = erdInput.isAllTable();

    // 신규로드 인지 기존 파일 로드 인지 검사합니다.
    if (null != erdInput.getUserDBERD()) {
      userDBErd = erdInput.getUserDBERD();

      // load resouce
      try {
        String xmlString = TadpoleSystem_UserDBResource.getResourceData(userDBErd);

        // 처음 로드 할때 ResourceSet에 instance가 등록 되어 있어야 합니다.
        /** <code>TadpolePackage.eNS_URI</code> */
        ResourceSet resourceSet = new ResourceSetImpl();
        if (resourceSet.getPackageRegistry().get("http://com.hangum.tadpole.rdb.model.ERDInfo")
            == null) {
          resourceSet
              .getPackageRegistry()
              .put("http://com.hangum.tadpole.rdb.model.ERDInfo", RdbPackage.eINSTANCE.getClass());
        }

        //
        XMLResourceImpl resource = new XMLResourceImpl();
        resource.setEncoding("UTF-8");
        resource.load(new InputSource(new StringReader(xmlString)), null);
        db = (DB) resource.getContents().get(0);

      } catch (Exception e) {
        logger.error("Load ERD Resource", e); // $NON-NLS-1$

        Status errStatus =
            new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$
        ExceptionDetailsErrorDialog.openError(
            getSite().getShell(),
            "Error",
            Messages.get().TadpoleEditor_0,
            errStatus); //$NON-NLS-1$
      }

      setPartName(isAllTable ? "All " + userDBErd.getName() : userDBErd.getName());
      setTitleToolTip(userDB.getDisplay_name());
    } else {
      setPartName(isAllTable ? "All " + userDB.getDisplay_name() : userDB.getDisplay_name());
      setTitleToolTip(userDB.getDisplay_name());
    }

    // google analytic
    AnalyticCaller.track(TadpoleRDBEditor.ID, userDB.getDbms_type());
  }
  /**
   * user label text
   *
   * @param userDB
   * @return
   */
  public static String getDBText(UserDBDAO userDB) {
    String retText = "";
    if (PublicTadpoleDefine.DBOperationType.PRODUCTION
        .toString()
        .equals(userDB.getOperation_type())) {
      retText =
          String.format(
              "%s [%s] %s",
              PRODUCTION_SERVER_START_TAG,
              StringUtils.substring(userDB.getOperation_type(), 0, 1),
              END_TAG);
      //		} else {
      //			retText = String.format("%s [%s] %s", DEVELOPMENT_SERVER_START_TAG,
      // StringUtils.substring(userDB.getOperation_type(), 0, 1), END_TAG);
    }

    if (PermissionChecker.isDBAdminRole(userDB)) {
      retText +=
          String.format(
              "%s (%s@%s)",
              userDB.getDisplay_name(),
              userDB.getUsers(),
              userDB.getDb()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    } else {

      // 프러덕이나 백업디비이면디비 이름만보이면 됨.
      if (PermissionChecker.isProductBackup(userDB)) {
        retText += userDB.getDisplay_name();
        // 기타 디비 이면 다 보이면 됨.
      } else {
        retText +=
            String.format(
                "%s (%s@%s)",
                userDB.getDisplay_name(),
                userDB.getUsers(),
                userDB.getDb()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$		
      }
    }

    return retText;
  }
  @Override
  protected void initializeGraphicalViewer() {
    //		super.initializeGraphicalViewer();

    Job job =
        new Job("ERD Initialize") {
          @Override
          public IStatus run(IProgressMonitor monitor) {
            monitor.beginTask("Painting table object", IProgressMonitor.UNKNOWN);

            try {
              RdbFactory factory = RdbFactory.eINSTANCE;

              if (db == null) {

                // 모든 table 정보를 가져온다.
                if (isAllTable) {
                  db = TadpoleModelUtils.INSTANCE.getDBAllTable(monitor, userDB);
                  // 부분 테이블 정보를 처리한다.
                } else {
                  db = factory.createDB();
                }

                db.setDbType(userDB.getDbms_type() + " (" + userDB.getDisplay_name() + ")");
              }

              // 하위 호환을 위한 코드 .
              if (db.getStyle() == null) {
                Style style = RdbFactory.eINSTANCE.createStyle();
                style.setDb(db);
                db.setStyle(style);
              }

            } catch (Exception e) {
              logger.error("ERD Initialize excepiton", e);

              return new Status(Status.WARNING, Activator.PLUGIN_ID, e.getMessage());
            } finally {
              monitor.done();
            }

            /////////////////////////////////////////////////////////////////////////////////////////
            return Status.OK_STATUS;
          }
        };

    // job의 event를 처리해 줍니다.
    final TadpoleRDBEditor rdbEditor = this;
    job.addJobChangeListener(
        new JobChangeAdapter() {

          public void done(IJobChangeEvent event) {
            final IJobChangeEvent jobEvent = event;
            getSite()
                .getShell()
                .getDisplay()
                .asyncExec(
                    new Runnable() {
                      public void run() {
                        if (!jobEvent.getResult().isOK()) {

                          // 아래의 try문은 이슈 169의 오류를 검증하기 위한 코드입니다.
                          // https://github.com/hangum/TadpoleForDBTools/issues/169
                          //  근본적인 에러는 해결안됨.  그러나 프로그램에서 에러나고 죽는 그런 경우는 해결.
                          //
                          try {
                            Exception e = new Exception(jobEvent.getResult().getException());
                            Status errStatus =
                                new Status(
                                    IStatus.ERROR,
                                    Activator.PLUGIN_ID,
                                    e.getMessage(),
                                    e); //$NON-NLS-1$
                            ExceptionDetailsErrorDialog.openError(
                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                "Error",
                                Messages.get().TadpoleModelUtils_2,
                                errStatus); //$NON-NLS-1$
                          } catch (Exception e) {
                            logger.error(
                                "https://github.com/hangum/TadpoleForDBTools/issues/169 검증오류...",
                                e);
                          }

                          // 오류가 발생했을때는 기본 정보로
                          RdbFactory factory = RdbFactory.eINSTANCE;
                          db = factory.createDB();
                          db.setDbType(userDB.getDbms_type());
                          db.setId(userDB.getUsers());
                          db.setUrl(userDB.getHost());
                        }
                        getGraphicalViewer().setContents(db);

                        // dnd
                        getGraphicalViewer()
                            .addDropTargetListener(
                                new TableTransferDropTargetListener(
                                    rdbEditor, getGraphicalViewer(), userDB, db));
                      }
                    }); // end display.asyncExec
          } // end done
        }); // end job

    job.setName(userDB.getDisplay_name());
    job.setUser(true);
    job.schedule();
  }
  //	MapReduceOutput mrOutput = null;
  private void goMapReduce(
      final DBCollection dbCol,
      final BasicDBObject basicObj,
      final MapReduceCommand.OutputType mrOType) {
    Job job = new Job("MapReduce search job") { // $NON-NLS-1$
          @Override
          public IStatus run(IProgressMonitor monitor) {
            monitor.beginTask("Starting JSON query...", IProgressMonitor.UNKNOWN); // $NON-NLS-1$
            try {

              //					if(mrOType == MapReduceCommand.OutputType.INLINE) {
              //						cmdResult = dbCol.getDB().command(basicObj, dbCol.getOptions());
              //						cmdResult.throwOnError();
              //						mrOutput = new MapReduceOutput(dbCol, basicObj, cmdResult);
              //					} else {
              cmdResult = dbCol.getDB().command(basicObj);
              //						cmdResult.throwOnError();
              //						mrOutput = new MapReduceOutput(dbCol, basicObj, cmdResult);
              //					}
              if (!cmdResult.ok()) {
                throw cmdResult.getException();
              }

            } catch (Exception e) {
              logger.error("mapreduce exception", e); // $NON-NLS-1$
              return new Status(
                  Status.WARNING,
                  Activator.PLUGIN_ID,
                  "mapreduce " + e.getMessage()); // $NON-NLS-1$
            } finally {
              monitor.done();
            }

            return Status.OK_STATUS;
          }
        };

    // job의 event를 처리해 줍니다.
    job.addJobChangeListener(
        new JobChangeAdapter() {
          public void done(IJobChangeEvent event) {

            final IJobChangeEvent jobEvent = event;
            getSite()
                .getShell()
                .getDisplay()
                .asyncExec(
                    new Runnable() {
                      public void run() {
                        if (jobEvent.getResult().isOK()) {
                          try {
                            Iterable<DBObject> iteResult =
                                (Iterable<DBObject>) cmdResult.get("results");
                            compositeResult.refreshDBView(iteResult, 0);
                            compositeResult.setResult();
                          } catch (Exception e) {
                            logger.error("MapReduce Error", e); // $NON-NLS-1$
                            Status errStatus =
                                new Status(
                                    IStatus.ERROR,
                                    Activator.PLUGIN_ID,
                                    e.getMessage(),
                                    e); //$NON-NLS-1$
                            ExceptionDetailsErrorDialog.openError(
                                null,
                                "Error",
                                "MapReduce execute exception",
                                errStatus); //$NON-NLS-1$ //$NON-NLS-2$
                          }
                        } else {
                          //							compositeResult.errorView(jobEvent.getResult().getMessage());
                        }
                      }
                    }); // end display.asyncExec
          } // end done
        }); // end job

    job.setName(userDB.getDisplay_name());
    job.setUser(true);
    job.schedule();
  }