public Image getImage(Object element) {

    if (element instanceof KeyWrapper) {
      if (((KeyWrapper) element).getType().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL))
        return ImageCache.getCreatedImage(EImage.KEYS.getPath());
      return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
    }

    return null;
  }
  protected void createBtnArea() {

    final Composite compBtns = new Composite(this, SWT.NONE);
    compBtns.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 7;
    compBtns.setLayout(gridLayout);

    btnAdd = new Button(compBtns, SWT.NONE);
    btnAdd.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    btnAdd.setToolTipText(Messages._Add);

    btnRemove = new Button(compBtns, SWT.NONE);
    btnRemove.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    btnRemove.setToolTipText(Messages._Remove);

    btnRemoveAll = new Button(compBtns, SWT.NONE);
    btnRemoveAll.setImage(ImageCache.getCreatedImage(EImage.PROGRESS_REMALL.getPath()));
    btnRemoveAll.setToolTipText(Messages.ComplexAnnotaionXX_RemoveAll);

    btnMoveUp = new Button(compBtns, SWT.NONE);
    btnMoveUp.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath()));
    btnMoveUp.setToolTipText(Messages.ComplexAnnotaionXX_MoveUp);

    btnMoveDown = new Button(compBtns, SWT.NONE);
    btnMoveDown.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath()));
    btnMoveDown.setToolTipText(Messages.ComplexAnnotaionXX_MoveDown);

    btnCopy = new Button(compBtns, SWT.NONE);
    btnCopy.setImage(ImageCache.getCreatedImage(EImage.COPY.getPath()));
    btnCopy.setToolTipText(Messages._Copy);

    btnPaste = new Button(compBtns, SWT.NONE);
    btnPaste.setImage(ImageCache.getCreatedImage(EImage.PASTE.getPath()));
    btnPaste.setToolTipText(Messages._Paste);
  }
 public RefreshViewAction() {
   super(Messages.RefreshAction_Refresh_All);
   setImageDescriptor(ImageCache.getImage(EImage.REFRESH.getPath()));
   setToolTipText(Messages.RefreshAction_Refresh_All_tooltip);
 }
  @Override
  protected Control createDialogArea(final Composite parent) {
    setShellStyle(SWT.WRAP);
    // create composite
    composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.makeColumnsEqualWidth = false;
    layout.numColumns = 2;
    label = new Label(composite, SWT.NONE | SWT.WRAP);
    // create message
    if (message != null) {
      // label = new Label(composite, SWT.NONE);
      label.setText(message);
      label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
      label.setFont(parent.getFont());
    }

    text = new Text(composite, getInputTextStyle() | SWT.WRAP);
    text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

    text.addModifyListener(
        new ModifyListener() {

          public void modifyText(ModifyEvent e) {
            validateInput();
          }
        });
    // xpathwidget = new XpathWidget(site,"...",treeParent,null, composite, null,false,true);
    // XpathSelectDialog(Shell parentShell,TreeParent parent,String title,IWorkbenchPartSite
    // site,boolean
    // isMulti,String dataModelName)

    openDLG = new Button(composite, SWT.NONE);
    openDLG.setImage(ImageCache.getCreatedImage(EImage.DOTS_BUTTON.getPath()));
    openDLG.addSelectionListener(this);
    openDLG.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    openDLG.setVisible(isBtnShow);
    openDLG.setToolTipText(Messages.ProcessViewXX_SelectOneEntity);

    errorMessageText = new Text(composite, SWT.READ_ONLY | SWT.WRAP);
    errorMessageText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
    errorMessageText.setBackground(
        errorMessageText.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    // Set the error message text
    setErrorMessage(errorMessage);
    if (isTransfor) {
      Group radioGroup = new Group(parent, SWT.SHADOW_NONE);
      radioGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
      radioGroup.setLayout(new GridLayout(1, false));
      radioGroup.setText(Messages.ProcessViewXX_SelectOneType);

      transformeButton = new Button(radioGroup, SWT.RADIO);
      transformeButton.setText(Messages.ProcessViewXX_CreateNormalProcess);
      transformeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
      text.setText(""); // $NON-NLS-1$
      transformeButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(""); // $NON-NLS-1$
              label.setText(message);
              openDLG.setVisible(false);
              parent.layout(true);
              value = ""; // $NON-NLS-1$
            }
          });
      transformeButton.setSelection(true);
      smartViewButton = new Button(radioGroup, SWT.RADIO);
      smartViewButton.setText(Messages.ProcessViewXX_CreateSmartProcess);
      smartViewButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));

      // smartViewButton.setSelection(true);
      smartViewButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(Smart_view);
              label.setText(Messages.ProcessViewXX_LabelText);
              openDLG.setVisible(true);
              value = Smart_view;
            }
          });

      beforeSavingButton = new Button(radioGroup, SWT.RADIO);
      beforeSavingButton.setText(Messages.ProcessViewXX_CreateBeforeProcess);
      beforeSavingButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
      beforeSavingButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(beforeSaving);
              label.setText(Messages.ProcessViewXX_LabelEnterName);
              openDLG.setVisible(true);
              value = beforeSaving;
            }
          });

      beforeDeletingButton = new Button(radioGroup, SWT.RADIO);
      beforeDeletingButton.setText(Messages.ProcessViewXX_CreateBeforeDelProcess);
      beforeDeletingButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
      beforeDeletingButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(beforeDeleting);
              label.setText(Messages.ProcessViewXX_LabelEnterNameDel);
              openDLG.setVisible(true);
              value = beforeDeleting;
            }
          });

      runnableProcessButton = new Button(radioGroup, SWT.RADIO);
      runnableProcessButton.setText(Messages.ProcessViewXX_CreateRunnableProcess);
      runnableProcessButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
      runnableProcessButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(runnableProcess);
              label.setText(Messages.ProcessViewXX_LabelEnterNameRunnable);
              openDLG.setVisible(true);
              value = runnableProcess;
            }
          });

      standaloneProcessButton = new Button(radioGroup, SWT.RADIO);
      standaloneProcessButton.setText(Messages.ProcessViewXX_CreateStandloneProcess);
      standaloneProcessButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
      standaloneProcessButton.addSelectionListener(
          new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {}

            public void widgetSelected(SelectionEvent e) {
              text.setText(standaloneProcess);
              label.setText(Messages.ProcessViewXX_LabelEnterNameFlowRunnable);
              openDLG.setVisible(true);
              value = standaloneProcess;
            }
          });
    } else {
      if (value != null) {
        text.setText(value);
      }
    }

    applyDialogFont(composite);
    return composite;
  }
public abstract class ComplexAnnotaionInfoComposite<T> extends Composite {

  protected TreeViewer tvInfos;

  protected Button btnAdd;

  protected Button btnRemove;

  protected Button btnRemoveAll;

  protected Button btnMoveUp;

  protected Button btnMoveDown;

  protected Button btnCopy;

  protected Button btnPaste;

  protected T copyedObj = null;

  protected Image nillableColImage = ImageCache.getCreatedImage(EImage.WILDCARD.getPath());

  protected List<T> infos;
  protected BasePropertySection section;

  public ComplexAnnotaionInfoComposite(
      Composite parent, int style, Object[] initParameters, BasePropertySection section) {
    super(parent, style);
    this.section = section;
    initParameters(initParameters);

    setLayout(new GridLayout());

    createTreeArea();

    createBtnArea();

    createExtentArea();

    initUIListeners();
  }

  protected void createTreeArea() {

    tvInfos = new TreeViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
    Tree tree = tvInfos.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    final GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_tree.heightHint = 120;
    gd_tree.minimumHeight = 80;
    tree.setLayoutData(gd_tree);
    tvInfos.setContentProvider(new ListContentProvider());
    tvInfos.setLabelProvider(getLabelProviderForViewer());
    tvInfos.setColumnProperties(getColumnProperties());
    tvInfos.setCellEditors(getCellEditors());
    tvInfos.setCellModifier(getCellModifier());

    tvInfos.setInput(getInfos());

    fillColumnsInTree(tree);
  }

  protected void createBtnArea() {

    final Composite compBtns = new Composite(this, SWT.NONE);
    compBtns.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 7;
    compBtns.setLayout(gridLayout);

    btnAdd = new Button(compBtns, SWT.NONE);
    btnAdd.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    btnAdd.setToolTipText(Messages._Add);

    btnRemove = new Button(compBtns, SWT.NONE);
    btnRemove.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    btnRemove.setToolTipText(Messages._Remove);

    btnRemoveAll = new Button(compBtns, SWT.NONE);
    btnRemoveAll.setImage(ImageCache.getCreatedImage(EImage.PROGRESS_REMALL.getPath()));
    btnRemoveAll.setToolTipText(Messages.ComplexAnnotaionXX_RemoveAll);

    btnMoveUp = new Button(compBtns, SWT.NONE);
    btnMoveUp.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath()));
    btnMoveUp.setToolTipText(Messages.ComplexAnnotaionXX_MoveUp);

    btnMoveDown = new Button(compBtns, SWT.NONE);
    btnMoveDown.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath()));
    btnMoveDown.setToolTipText(Messages.ComplexAnnotaionXX_MoveDown);

    btnCopy = new Button(compBtns, SWT.NONE);
    btnCopy.setImage(ImageCache.getCreatedImage(EImage.COPY.getPath()));
    btnCopy.setToolTipText(Messages._Copy);

    btnPaste = new Button(compBtns, SWT.NONE);
    btnPaste.setImage(ImageCache.getCreatedImage(EImage.PASTE.getPath()));
    btnPaste.setToolTipText(Messages._Paste);
  }

  protected void initUIListeners() {

    initUIListnerForAddBtn();

    initUIListenersForRemoveBtn();

    initUIListenerForRemoveAllBtn();

    initUIListenerForMoveUpBtn();

    initUIListenerForMoveDownBtn();

    initUIListenerForCopyBtn();

    initUIListenerForPasteBtn();
  }

  private void initUIListnerForAddBtn() {

    btnAdd.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            T createdDefaultObj = createDefaultInfoObj();

            if (createdDefaultObj == null) {
              return;
            }

            getInfos().add(createdDefaultObj);

            tvInfos.refresh();
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private void initUIListenersForRemoveBtn() {
    btnRemove.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            if (!hasSelection()) {
              return;
            }

            getInfos().remove(getSelection());

            tvInfos.refresh();
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private void initUIListenerForRemoveAllBtn() {

    btnRemoveAll.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            getInfos().clear();

            tvInfos.refresh();
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private void initUIListenerForMoveUpBtn() {
    btnMoveUp.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            if (!hasSelection()) {
              return;
            }

            moveInfoUp(getSelection());
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private void initUIListenerForMoveDownBtn() {

    btnMoveDown.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            if (!hasSelection()) {
              return;
            }

            moveInfoDown(getSelection());
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private void initUIListenerForCopyBtn() {
    btnCopy.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            if (!hasSelection()) {
              return;
            }

            copyedObj = getSelection();
          }
        });
  }

  private void initUIListenerForPasteBtn() {

    btnPaste.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            if (copyedObj == null) {
              return;
            }

            if (!validateBeforePaste(copyedObj)) {
              return;
            }

            getInfos().add(cloneCopyedObj(copyedObj));

            tvInfos.refresh();
            if (section != null) {
              section.autoCommit();
            }
          }
        });
  }

  private boolean hasSelection() {
    return getSelection() != null;
  }

  @SuppressWarnings("unchecked")
  private T getSelection() {

    if (!(tvInfos.getSelection() instanceof IStructuredSelection)
        || ((IStructuredSelection) tvInfos.getSelection()).isEmpty()) {
      return null;
    }

    return (T) ((IStructuredSelection) tvInfos.getSelection()).getFirstElement();
  }

  private void moveInfoUp(T movedObj) {
    doMove(
        movedObj, (getInfos().indexOf(movedObj) - 1) < 0 ? 0 : (getInfos().indexOf(movedObj) - 1));
  }

  private void moveInfoDown(T movedObj) {
    doMove(
        movedObj,
        (getInfos().indexOf(movedObj) == getInfos().size() - 1)
            ? (getInfos().size() - 1)
            : (getInfos().indexOf(movedObj) + 1));
  }

  private void doMove(T movedObj, int newIndex) {
    getInfos().remove(movedObj);
    getInfos().add(newIndex, movedObj);
    tvInfos.refresh();
  }

  public Viewer getViewer() {
    return tvInfos;
  }

  public void setInfos(List<T> objs) {

    if (objs == null) {
      return;
    }

    infos = objs;
    tvInfos.setInput(infos);
  }

  public void setInfos(T[] objs) {

    infos.clear();

    for (T eachInputedObj : objs) {

      if (eachInputedObj == null) {
        continue;
      }

      infos.add(eachInputedObj);
    }

    tvInfos.setInput(infos);
    tvInfos.refresh();
  }

  @Override
  public void dispose() {
    super.dispose();

    nillableColImage.dispose();
  }

  protected List<T> getInfos() {
    return infos;
  }

  protected abstract ITableLabelProvider getLabelProviderForViewer();

  protected abstract void createTopExtentArea();

  protected abstract void createExtentArea();

  protected abstract void fillColumnsInTree(Tree tree);

  protected abstract T createDefaultInfoObj();

  protected abstract boolean validateBeforePaste(T copyedObj);

  protected abstract T cloneCopyedObj(T copyedObj);

  protected abstract String[] getColumnProperties();

  protected abstract CellEditor[] getCellEditors();

  protected abstract ICellModifier getCellModifier();

  protected abstract void initParameters(Object[] parameters);
}