org.eclipse.vorto.perspective.view.GeneratorDialog.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.vorto.perspective.view.GeneratorDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 *   
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * The Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *   
 * Contributors:
 * Bosch Software Innovations GmbH - Please refer to git log
 *******************************************************************************/
package org.eclipse.vorto.perspective.view;

import java.util.List;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.vorto.core.api.repository.GeneratorResource;
import org.eclipse.vorto.core.api.repository.ModelResource;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;

public class GeneratorDialog extends TitleAreaDialog {

    private ModelResource model;
    private List<GeneratorResource> codegens;

    public GeneratorDialog(Shell parentShell, ModelResource model, List<GeneratorResource> codegens) {
        super(parentShell);
        this.model = model;
        this.codegens = codegens;
    }

    @Override
    public void create() {
        super.create();
        setTitle("Generator Overview");
        setMessage(
                "Choose the generator and click generate button, and the code will be automatically downloaded in the current workspace folder.",
                IMessageProvider.INFORMATION);
        // getButton(IDialogConstants.OK_ID).setText("Generate");
        getButton(IDialogConstants.OK_ID).setVisible(false);
        getButton(IDialogConstants.CANCEL_ID).setText("Close");
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        Composite area = (Composite) super.createDialogArea(parent);

        ScrolledComposite scrolledComposite = new ScrolledComposite(area, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
        scrolledComposite.setExpandHorizontal(true);
        scrolledComposite.setExpandVertical(true);
        GridData gd_scrolledComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
        gd_scrolledComposite.heightHint = 300;
        scrolledComposite.setLayoutData(gd_scrolledComposite);

        Composite composite = new Composite(scrolledComposite, SWT.NONE);
        composite.setLayout(new GridLayout(1, false));

        for (GeneratorResource gen : codegens) {
            new GeneratorItem(composite, SWT.NONE, model, gen);
        }

        scrolledComposite.setContent(composite);
        scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

        return area;
    }

    @Override
    protected void okPressed() {
        super.okPressed();
    }

}