Package de.innovationgate.eclipse.editors.design.pages

Source Code of de.innovationgate.eclipse.editors.design.pages.WGADesignExportSection

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.design.pages;

import org.eclipse.jface.action.ContributionManager;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ImageHyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.menus.IMenuService;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.utils.WorkbenchUtils;

/**
* creates the export section in WGADesign editor based on menu contributions
* menu ID example: "menu:de.innovationgate.eclipse.ids.editors.WGADesignEditor.export"
*
*
*
*/
public class WGADesignExportSection {

  private String _menuId;

  private WGADesignExportSection(String menuId) {
    _menuId = menuId;
  }
 
  private void init(ScrolledForm form, FormToolkit toolkit, IEditorPart editor) { 
    // exporting section
    Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
    section.setText("Exporting");   
       
    final Composite sectionClient = toolkit.createComposite(section);
        section.setClient(sectionClient);
        GridLayout sectionLayout = new GridLayout();                                     
        sectionLayout.numColumns = 1;
        sectionClient.setLayout(sectionLayout);
       
        final HyperlinkGroup group = new HyperlinkGroup(sectionClient.getDisplay());
       
        final IEditorPart fEditor = editor;
       
    IMenuService ms = (IMenuService)editor.getSite().getService(IMenuService.class);
    ContributionManager manager = new ContributionManager() {

      public void update(boolean force) {
        IContributionItem[] items = getItems();
        for (IContributionItem item : items) {
          if (item instanceof MenuManager) {
            final MenuManager menu = (MenuManager) item;
            ImageHyperlink link = new ImageHyperlink(sectionClient, SWT.None);
            link.setText(menu.getMenuText());           
            if (menu.getImageDescriptor() != null) {
              link.setImage(menu.getImageDescriptor().createImage());
            }
            link.addHyperlinkListener(new HyperlinkAdapter() {
              public void linkActivated(HyperlinkEvent e) {
                IHandlerService handlerService = (IHandlerService) fEditor.getSite().getService(IHandlerService.class);
                if (handlerService != null) {
                  try {
                    handlerService.executeCommand(menu.getId(), null);
                  } catch (Exception ex) {
                    WorkbenchUtils.showErrorDialog(Plugin.getDefault(), fEditor.getSite().getShell(), "Execution of hyperlink failed", "Unable to execute hyperlink command '" + menu.getId() + "'.", ex);
                  }
                }
              }
            });   
            group.add(link);
          }
        }           
      }

     
    };   
    ms.populateContributionManager(manager, _menuId);
    manager.update(true);
  }
 
  public static void create(ScrolledForm form, FormToolkit toolkit, IEditorPart editor, String menuId) {
    WGADesignExportSection section = new WGADesignExportSection(menuId);
    section.init(form, toolkit, editor);
  }
 
}
TOP

Related Classes of de.innovationgate.eclipse.editors.design.pages.WGADesignExportSection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.