Search in sources :

Example 1 with SampleProject

use of org.eclipse.titan.designer.samples.SampleProject in project titan.EclipsePlug-ins by eclipse.

the class NewTITANProjectWizard method createNewProject.

/**
 * Creating a new project.
 *
 * @return the new project created.
 */
private IProject createNewProject() {
    final IProject tempProjectHandle = mainPage.getProjectHandle();
    URI location = null;
    if (!mainPage.useDefaults()) {
        location = mainPage.getLocationURI();
    }
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final String tempExecutableName = tempProjectHandle.getName();
    final IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(tempExecutableName);
    final IProjectDescription description = workspace.newProjectDescription(tempExecutableName);
    description.setLocationURI(location);
    TITANNature.addTITANNatureToProject(description);
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(final IProgressMonitor monitor) throws CoreException {
            createProject(description, newProjectHandle, monitor);
            String sourceFolder = optionsPage.getSourceFolder();
            if (!"".equals(sourceFolder)) {
                IFolder folder = newProjectHandle.getFolder(sourceFolder);
                if (!folder.exists()) {
                    try {
                        folder.create(true, true, null);
                    } catch (CoreException e) {
                        ErrorReporter.logExceptionStackTrace(e);
                    }
                }
                final SampleProject sample = contentPage.getSampleProject();
                if (sample != null) {
                    sample.setupProject(newProjectHandle.getProject(), folder);
                    ProjectFileHandler pfHandler = new ProjectFileHandler(newProjectHandle.getProject());
                    pfHandler.saveProjectSettings();
                }
                if (optionsPage.isExcludeFromBuildSelected()) {
                    folder.setPersistentProperty(new QualifiedName(FolderBuildPropertyData.QUALIFIER, FolderBuildPropertyData.EXCLUDE_FROM_BUILD_PROPERTY), TRUE);
                }
            }
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, ProjectBuildPropertyData.GENERATE_MAKEFILE_PROPERTY), TRUE);
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, TTCN3PreprocessorOptionsData.TTCN3_PREPROCESSOR_PROPERTY), "cpp");
            newProjectHandle.setPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, CCompilerOptionsData.CXX_COMPILER_PROPERTY), "g++");
        }
    };
    try {
        getContainer().run(true, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (final InvocationTargetException e) {
        final Throwable t = e.getTargetException();
        if (t != null) {
            ErrorReporter.parallelErrorDisplayInMessageDialog(CREATION_FAILED, t.getMessage());
        }
        return null;
    }
    newProject = newProjectHandle;
    return newProject;
}
Also used : SampleProject(org.eclipse.titan.designer.samples.SampleProject) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) QualifiedName(org.eclipse.core.runtime.QualifiedName) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with SampleProject

use of org.eclipse.titan.designer.samples.SampleProject in project titan.EclipsePlug-ins by eclipse.

the class NewTITANProjectContentPage method createSampleProjectsGroup.

/**
 * Creates the sample project selection part of the window
 *
 * @param parent
 *                the parent composite
 */
private void createSampleProjectsGroup(final Composite parent) {
    final Group projectAndDescription = new Group(parent, SWT.NONE);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    projectAndDescription.setLayout(gridLayout);
    projectAndDescription.setLayoutData(new GridData(GridData.FILL_BOTH));
    projectAndDescription.setText("Sample projects");
    final List samplesList = new List(projectAndDescription, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    samplesList.setLayoutData(new GridData(GridData.FILL_BOTH));
    int indexOfEmptyProject = 0;
    int i = 0;
    for (Map.Entry<String, SampleProject> entry : SampleProjects.getProjects().entrySet()) {
        samplesList.add(entry.getValue().getName());
        if ("Empty Project".equals(entry.getValue().getName())) {
            indexOfEmptyProject = i;
        }
        ++i;
    }
    samplesList.select(indexOfEmptyProject);
    sampleProject = SampleProjects.getProjects().get(samplesList.getSelection()[0]);
    final Label description = new Label(projectAndDescription, SWT.BORDER);
    description.setLayoutData(new GridData(GridData.FILL_BOTH));
    description.setText(sampleProject.getDescription());
    samplesList.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (samplesList.getSelectionCount() != 1) {
                return;
            }
            sampleProject = SampleProjects.getProjects().get(samplesList.getSelection()[0]);
            description.setText(sampleProject.getDescription());
        }

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // Do nothing
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) SampleProject(org.eclipse.titan.designer.samples.SampleProject) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) Map(java.util.Map) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SampleProject (org.eclipse.titan.designer.samples.SampleProject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 Map (java.util.Map)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 QualifiedName (org.eclipse.core.runtime.QualifiedName)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 List (org.eclipse.swt.widgets.List)1 ProjectFileHandler (org.eclipse.titan.designer.properties.data.ProjectFileHandler)1 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)1