org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/WidgetProjectNature.java
author tasneems@symbian.org
Wed, 27 Jan 2010 15:05:37 -0800
changeset 50 0560e98b9bf6
child 54 5a2cfa9bc743
permissions -rw-r--r--
Added widget project nature and WRT validators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     1
/**
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     2
 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies).
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     3
 * All rights reserved.
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     8
 *
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
     9
 * Initial Contributors:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    10
 * Symbian Foundation - initial contribution.
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    11
 * Contributors:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    12
 * Description:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    13
 * Overview:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    14
 * Details:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    15
 * Platforms/Drives/Compatibility:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    17
 * Failures and causes:
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    18
 */
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    19
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    20
package org.symbian.tools.wrttools;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    21
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    22
import org.eclipse.core.resources.ICommand;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    23
import org.eclipse.core.resources.IProject;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    24
import org.eclipse.core.resources.IProjectDescription;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    25
import org.eclipse.core.resources.IProjectNature;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    26
import org.eclipse.core.runtime.CoreException;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    27
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    28
import org.symbian.tools.wrttools.core.validator.WidgetProjectValidator;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    29
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    30
public class WidgetProjectNature implements IProjectNature {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    31
	
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    32
	private IProject project;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    33
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    34
	public void configure() throws CoreException {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    35
		IProjectDescription desc = project.getDescription();
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    36
		ICommand[] commands = desc.getBuildSpec();
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    37
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    38
		for (int i = 0; i < commands.length; ++i) {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    39
			if (commands[i].getBuilderName().equals(WidgetProjectValidator.BUILDER_ID)) {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    40
				return;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    41
			}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    42
		}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    43
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    44
		ICommand[] newCommands = new ICommand[commands.length + 1];
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    45
		System.arraycopy(commands, 0, newCommands, 0, commands.length);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    46
		ICommand command = desc.newCommand();
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    47
		command.setBuilderName(WidgetProjectValidator.BUILDER_ID);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    48
		newCommands[newCommands.length - 1] = command;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    49
		desc.setBuildSpec(newCommands);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    50
		project.setDescription(desc, null);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    51
	}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    52
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    53
	public void deconfigure() throws CoreException {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    54
		IProjectDescription description = getProject().getDescription();
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    55
		ICommand[] commands = description.getBuildSpec();
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    56
		for (int i = 0; i < commands.length; ++i) {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    57
			if (commands[i].getBuilderName().equals(WidgetProjectValidator.BUILDER_ID)) {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    58
				ICommand[] newCommands = new ICommand[commands.length - 1];
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    59
				System.arraycopy(commands, 0, newCommands, 0, i);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    60
				System.arraycopy(commands, i + 1, newCommands, i,
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    61
						commands.length - i - 1);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    62
				description.setBuildSpec(newCommands);
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    63
				return;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    64
			}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    65
		}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    66
	}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    67
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    68
	public IProject getProject() {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    69
		return project;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    70
	}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    71
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    72
	public void setProject(IProject project) {
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    73
		this.project = project;
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    74
	}
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    75
0560e98b9bf6 Added widget project nature and WRT validators
tasneems@symbian.org
parents:
diff changeset
    76
}