public void createControl(Composite parent) {
    viewer = new GalleryViewer();

    EditDomain editDomain = new EditDomain();
    editDomain.installTool(GEF.TOOL_SELECT, new TemplateGallerySelectTool());
    viewer.setEditDomain(editDomain);

    Properties properties = viewer.getProperties();
    properties.set(GalleryViewer.Horizontal, Boolean.TRUE);
    properties.set(GalleryViewer.Wrap, Boolean.TRUE);
    properties.set(GalleryViewer.TitlePlacement, GalleryViewer.TITLE_BOTTOM);
    properties.set(GalleryViewer.SingleClickToOpen, Boolean.TRUE);
    properties.set(GalleryViewer.SolidFrames, true);
    properties.set(GalleryViewer.FlatFrames, true);
    properties.set(GalleryViewer.ImageConstrained, true);
    properties.set(GalleryViewer.ImageStretched, true);
    properties.set(
        GalleryViewer.Layout,
        new GalleryLayout(
            GalleryLayout.ALIGN_CENTER,
            GalleryLayout.ALIGN_TOPLEFT,
            10,
            10,
            new Insets(5, 15, 5, 15)));
    properties.set(GalleryViewer.FrameContentSize, new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
    properties.set(GalleryViewer.ContentPaneBorderWidth, 1);
    properties.set(GalleryViewer.ContentPaneBorderColor, ColorUtils.getColor("#cccccc"));

    Control control = viewer.createControl(parent);
    control.setBackground(parent.getBackground());
    control.setForeground(parent.getForeground());

    viewer.setLabelProvider(new TemplateLabelProvider());

    viewer.setInput(getViewerInput());

    viewer.addOpenListener(
        new IOpenListener() {
          public void open(OpenEvent event) {
            if (normalOrEditMode) {
              if (!templateOpening) handleTemplateSelected(event.getSelection());
            }
          }
        });

    MindMapUI.getResourceManager().addResourceManagerListener(this);

    setControl(control);
  }
 public void userTemplateRemoved(ITemplate template) {
   if (template instanceof ITemplate) {
     if (viewer == null || viewer.getControl() == null || viewer.getControl().isDisposed()) return;
     viewer.setInput(getViewerInput());
   }
 }
 public void setFocus() {
   if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
     viewer.getControl().setFocus();
   }
 }
 public void addSelectionChangedListener(ISelectionChangedListener listener) {
   if (viewer != null) {
     viewer.addSelectionChangedListener(listener);
   }
 }