/**
  * @param resource
  * @return true if the fViewer has updated its input, false otherwise
  */
 protected boolean refreshComponents(IProject project) {
   IRteProject rteProject = CpProjectPlugIn.getRteProjectManager().getRteProject(project);
   if (rteProject != null) {
     ICpCodeTemplate codeTemplate = rteProject.getRteConfiguration().getCmsisCodeTemplate();
     fViewer.setInput(codeTemplate);
     fViewer.getControl().setFocus();
     return true;
   }
   return false;
 }
 /** Open the browser to select project */
 void handleProjectBrowse() {
   Set<IRteProject> rteProjects = new HashSet<IRteProject>();
   for (IRteProject p : CpProjectPlugIn.getRteProjectManager().getRteProjects()) {
     if (p.getProject().isOpen()) {
       rteProjects.add(p);
     }
   }
   ProjectSelectionDialog dialog = new ProjectSelectionDialog(getShell(), rteProjects);
   if (dialog.open() == Window.OK) {
     Object[] result = dialog.getResult();
     if (result != null && result.length == 1) {
       projectText.setText(((IRteProject) result[0]).getName());
     }
   }
 }
  @Override
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    // layout.verticalSpacing = 5;

    Label label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplateNewWizardPage_Project);
    projectText = new Text(container, SWT.BORDER | SWT.SINGLE);
    projectText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    projectText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            projectChanged();
          }
        });
    projectBrowse = new Button(container, SWT.PUSH);
    projectBrowse.setText(Messages.CmsisCodeTemplate_Browse);
    projectBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleProjectBrowse();
          }
        });

    fViewer =
        new TreeViewer(
            container, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Tree tree = fViewer.getTree();
    GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd_tree.heightHint = 300;
    tree.setLayoutData(gd_tree);
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Object obj = e.item.getData();
            if (obj instanceof ICpCodeTemplate) {
              selectedCodeTemplate = (ICpCodeTemplate) obj;
              String[] codeTemplates = selectedCodeTemplate.getCodeTemplates();
              if (codeTemplates.length == 0) {
                fileText.setEditable(false);
                fileText.setText(CmsisConstants.EMPTY_STRING);
                return;
              }
              fileText.setEditable(true);
              StringBuilder sb = new StringBuilder(Utils.extractFileName(codeTemplates[0]));
              for (int i = 1; i < codeTemplates.length; i++) {
                fileText.setEditable(false);
                sb.append(' ');
                sb.append(Utils.extractFileName(codeTemplates[i]));
              }
              fileText.setText(sb.toString());
            }
          }
        });

    TreeViewerColumn column0 = new TreeViewerColumn(fViewer, SWT.LEFT);
    column0.getColumn().setText(Messages.CmsisCodeTemplate_Component);
    column0.getColumn().setWidth(200);
    column0.setLabelProvider(new ComponentColumnLabelProvider());

    TreeViewerColumn column1 = new TreeViewerColumn(fViewer, SWT.LEFT);
    column1.getColumn().setText(Messages.CmsisCodeTemplate_Name);
    column1.getColumn().setWidth(320);
    column1.setLabelProvider(new NameColumnLabelProvider());

    fViewer.setContentProvider(new CodeTemplateContentProvider());

    IRteProject rteProject = getRteProject();
    if (rteProject != null) {
      ICpCodeTemplate codeTemplate = rteProject.getRteConfiguration().getCmsisCodeTemplate();
      fViewer.setInput(codeTemplate);
      fViewer.getControl().setFocus();
    }

    label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplate_Location);
    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    containerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    containerText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            dialogChanged();
          }
        });
    containerBrowse = new Button(container, SWT.PUSH);
    containerBrowse.setText(Messages.CmsisCodeTemplate_Browse);
    containerBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleContainerBrowse();
          }
        });

    label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplate_FileName);
    fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
    fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fileText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            dialogChanged();
          }
        });

    initialize();
    projectChanged();
    setControl(container);
    new Label(container, SWT.NONE);
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(parent.getParent(), IHelpContextIds.CODE_TEMPLATE_WIZARD);
  }