Search in sources :

Example 1 with WizardPageInformation

use of net.sourceforge.usbdm.packageParser.WizardPageInformation in project usbdm-eclipse-plugins by podonoghue.

the class ProcessProjectActions method process.

public static void process(final Wizard wizard, final IProject projectHandle, final Device device, final ProjectActionList actionList, final Map<String, String> variableMap, final IProgressMonitor monitor) throws Exception {
    // System.err.println("ProcessProjectActions.process("+device.getName()+") =============================================");
    if (actionList == null) {
        return;
    }
    final ApplyOptions applyOptions = new ApplyOptions(projectHandle);
    class MyVisitor implements ProjectActionList.Visitor {

        @Override
        public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
            // System.err.println("ProjectCustomAction: "+action.toString());
            try {
                if (action instanceof FileAction) {
                    new AddTargetFiles().process(projectHandle, variableMap, (FileAction) action, monitor);
                } else if (action instanceof DeleteResourceAction) {
                    new DeleteResource().process(projectHandle, variableMap, (DeleteResourceAction) action, monitor);
                } else if (action instanceof CreateFolderAction) {
                    ProjectUtilities.createFolder(projectHandle, variableMap, (CreateFolderAction) action, monitor);
                } else if (action instanceof ProjectOption) {
                    applyOptions.process(variableMap, (ProjectOption) action, monitor);
                } else if (action instanceof ExcludeAction) {
                    ProjectUtilities.excludeItem(projectHandle, (ExcludeAction) action, monitor);
                } else if (action instanceof ProjectActionList) {
                    ProjectActionList projectActionList = (ProjectActionList) action;
                    return new Result(projectActionList.appliesTo(device, variableMap) ? Status.CONTINUE : Status.PRUNE);
                } else if (action instanceof ProjectCustomAction) {
                    ProjectCustomAction customAction = (ProjectCustomAction) action;
                    Class<?> actionClass = Class.forName(customAction.getclassName());
                    Object clsInstance = actionClass.newInstance();
                    if (!(clsInstance instanceof CustomAction)) {
                        throw new Exception("Custom action does not implement required interface");
                    }
                    ((CustomAction) clsInstance).action(projectHandle, variableMap, monitor, customAction.getValue());
                } else if (action instanceof ProjectConstant) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardGroup) {
                // Ignore as already added to paramMap
                } else if (action instanceof ProjectVariable) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardPageInformation) {
                // Ignore as only applicable to wizard dialogues
                } else {
                    throw new Exception("Unexpected action class: " + action.getClass());
                }
            } catch (Exception e) {
                // e.printStackTrace();
                StringBuffer sb = new StringBuffer();
                sb.append("Unable to process Action " + action.toString() + "\n");
                sb.append("Action id = " + action.getId() + "\n");
                sb.append("Action owned by = " + action.getOwnerId() + "\n");
                sb.append(e.getMessage());
                return new Result(new Exception(sb.toString()));
            }
            return new Result(Status.CONTINUE);
        }
    }
    ;
    MyVisitor visitor = new MyVisitor();
    Result res = actionList.visit(visitor, null, monitor);
    if (res.getStatus() == Status.EXCEPTION) {
        throw res.getException();
    }
}
Also used : AddTargetFiles(net.sourceforge.usbdm.cdt.utilties.AddTargetFiles) Result(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) CreateFolderAction(net.sourceforge.usbdm.packageParser.CreateFolderAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ProjectVariable(net.sourceforge.usbdm.packageParser.ProjectVariable) ProjectConstant(net.sourceforge.usbdm.packageParser.ProjectConstant) WizardGroup(net.sourceforge.usbdm.packageParser.WizardGroup) DeleteResourceAction(net.sourceforge.usbdm.packageParser.DeleteResourceAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ApplyOptions(net.sourceforge.usbdm.cdt.utilties.ApplyOptions) DeleteResource(net.sourceforge.usbdm.cdt.utilties.DeleteResource) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) ProjectOption(net.sourceforge.usbdm.packageParser.ProjectOption) ExcludeAction(net.sourceforge.usbdm.packageParser.ExcludeAction) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) FileAction(net.sourceforge.usbdm.packageParser.FileAction)

Example 2 with WizardPageInformation

use of net.sourceforge.usbdm.packageParser.WizardPageInformation in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmNewProjectWizard method updateDynamicWizardPageInformation.

/**
 * Collects information about dynamic wizard pages
 */
void updateDynamicWizardPageInformation() {
    // System.err.println("updateDynamicWizardPageInformation()");
    fWizardPageInformation = new ArrayList<WizardPageInformation>();
    Visitor visitor = new ProjectActionList.Visitor() {

        @Override
        public Result applyTo(ProjectAction action, ProjectActionList.Value result, IProgressMonitor monitor) {
            if (action instanceof WizardPageInformation) {
                WizardPageInformation page = (WizardPageInformation) action;
                // System.err.println("Adding dynamic page info " + page.getName());
                fWizardPageInformation.add(page);
            }
            return CONTINUE;
        }
    };
    fProjectActionList.visit(visitor, null);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Visitor(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation)

Example 3 with WizardPageInformation

use of net.sourceforge.usbdm.packageParser.WizardPageInformation in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmDynamicOptionPage_N method main.

// @Override
// public boolean canFlipToNextPage() {
// return isPageComplete();
// }
/**
 * Test main
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Packages Available");
    shell.setLayout(new FillLayout());
    Composite composite = new Composite(shell, SWT.NONE);
    composite.setLayout(new FillLayout());
    String deviceName = "FRDM_K22F";
    // String deviceName = "FRDM_KL27Z";
    // String deviceName = "MKL27Z64M4";
    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put("linkerFlashSize", "0x100");
    paramMap.put("linkerRamSize", "0x100");
    paramMap.put("outputType", "xxxxxProjectType.exe");
    paramMap.put("targetDevice", deviceName);
    // UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(deviceName, paramMap, "usbdm-project-options-page");
    // UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(deviceName, paramMap, "kinetis-CPP-abstraction-options-page");
    WizardPageInformation wizardPageInfo = new WizardPageInformation("kinetis-sdk-options-page", "Kinetis", "Kinetis description");
    DeviceDatabase deviceDatabase = new DeviceDatabase(TargetType.T_ARM);
    Device device = deviceDatabase.getDevice(deviceName);
    ProjectActionList projectActionList = device.getProjectActionList(paramMap);
    UsbdmDynamicOptionPage_N page = new UsbdmDynamicOptionPage_N(device, projectActionList, wizardPageInfo);
    page.createControl(composite);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    page.getPageData(paramMap);
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) DeviceDatabase(net.sourceforge.usbdm.deviceDatabase.DeviceDatabase) Device(net.sourceforge.usbdm.deviceDatabase.Device) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) FillLayout(org.eclipse.swt.layout.FillLayout) Display(org.eclipse.swt.widgets.Display) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation)

Example 4 with WizardPageInformation

use of net.sourceforge.usbdm.packageParser.WizardPageInformation in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmOptionsPanel method createOptionsControl.

/**
 *    Populate the Options controls
 *
 *    @param parent
 *
 *    @return Composite created
 *    @throws Exception
 */
private Composite createOptionsControl(Composite parent) {
    final Composite comp = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    // GridBagLayout layout = new GridBagLayout();
    comp.setLayout(layout);
    if (fProjectActionList == null) {
        // Should be impossible
        new Label(comp, SWT.NONE).setText("No device options");
        return comp;
    }
    /*
       * Collect variables for dialogue
       */
    fVariableMap = new HashMap<String, ProjectVariable>();
    final ArrayList<ProjectVariable> variableList = new ArrayList<ProjectVariable>();
    final HashMap<String, WizardGroup> wizardGroups = new HashMap<String, WizardGroup>();
    Visitor visitor = new ProjectActionList.Visitor() {

        @Override
        public Result applyTo(ProjectAction action, ProjectActionList.Value result, IProgressMonitor monitor) {
            if (action instanceof ProjectActionList) {
                ProjectActionList pal = (ProjectActionList) action;
                if (!pal.appliesTo(fDevice, fOptionMap)) {
                    return PRUNE;
                }
            } else if (action instanceof ProjectVariable) {
                ProjectVariable projectVariable = (ProjectVariable) action;
                fVariableMap.put(projectVariable.getId(), projectVariable);
                variableList.add(projectVariable);
            // System.err.println(String.format("Adding %s", projectVariable));
            } else if (action instanceof WizardPageInformation) {
                WizardPageInformation wizardPageInfo = (WizardPageInformation) action;
                // System.err.println("WizardPage found : " + wizardPageInfo);
                if (fWizardPageInfo.getId().equals(wizardPageInfo.getId())) {
                    ArrayList<WizardGroup> groups = wizardPageInfo.getGroups();
                    // System.err.println("Processing WizardPage : " + wizardPageInfo);
                    for (WizardGroup group : groups) {
                        wizardGroups.put(group.getId(), group);
                    // System.err.println("   WizardGroup found : " + group);
                    }
                }
            }
            return CONTINUE;
        }
    };
    fProjectActionList.visit(visitor, null);
    if (fVariableMap.size() == 0) {
        Group defaultGroup = new Group(comp, SWT.NONE);
        defaultGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        defaultGroup.setLayout(new GridLayout(2, false));
        Label label = new Label(defaultGroup, SWT.NONE);
        // $NON-NLS-1$
        label.setText("No Options");
    } else {
        SelectionListener listener = new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                fHasChanged = true;
                notifyListeners(SWT.CHANGED, null);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                notifyListeners(SWT.CHANGED, null);
            }
        };
        // Group created dynamically from XML
        HashMap<String, Group> groups = new HashMap<String, Group>();
        fGroupList = new ArrayList<Group>();
        // Create buttons
        fButtonMap = new HashMap<String, Button>();
        for (ProjectVariable variable : variableList) {
            if ((variable.getName() == null) || (variable.getName().length() == 0)) {
                throw new RuntimeException("Variable without name " + variable.getId());
            }
            String groupId = variable.getButtonGroupId();
            int buttonStyle = variable.getButtonStyle();
            Group group = groups.get(groupId);
            if (group == null) {
                WizardGroup wizardGroup = wizardGroups.get(groupId);
                if (wizardGroup == null) {
                    continue;
                }
                group = new Group(comp, SWT.NONE);
                fGroupList.add(group);
                String groupName = MacroSubstitute.substitute(wizardGroup.getName(), fOptionMap);
                group.setText(groupName);
                GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
                gd.horizontalSpan = wizardGroup.getSpan();
                group.setLayoutData(gd);
                group.setLayout(new GridLayout(wizardGroup.getWidth(), false));
                groups.put(groupId, group);
            }
            Button button = new Button(group, buttonStyle);
            fButtonMap.put(variable.getId(), button);
            button.setText("  " + variable.getName());
            boolean value = getSetting(variable.getId(), Boolean.valueOf(variable.getDefaultValue()));
            button.setSelection(value);
            button.setToolTipText(variable.getDescription().replaceAll("\\\\n", "\n"));
            button.setData(variable);
            button.addSelectionListener(listener);
        }
    }
    return comp;
}
Also used : WizardGroup(net.sourceforge.usbdm.packageParser.WizardGroup) Group(org.eclipse.swt.widgets.Group) Visitor(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor) HashMap(java.util.HashMap) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation) GridLayout(org.eclipse.swt.layout.GridLayout) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ProjectVariable(net.sourceforge.usbdm.packageParser.ProjectVariable) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) WizardGroup(net.sourceforge.usbdm.packageParser.WizardGroup) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) GridData(org.eclipse.swt.layout.GridData) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 5 with WizardPageInformation

use of net.sourceforge.usbdm.packageParser.WizardPageInformation in project usbdm-eclipse-plugins by podonoghue.

the class ProcessProjectActions method process.

/**
 * Process a project action list
 *
 * @param projectHandle Project being manipulated
 * @param actionList    Actions to do
 * @param variableMap   Variables that may be needed
 * @param monitor       Progress monitor
 *
 * @throws Exception
 */
public void process(final IProject projectHandle, final ProjectActionList actionList, final Map<String, String> variableMap, final IProgressMonitor monitor) throws Exception {
    if (actionList == null) {
        return;
    }
    System.err.println("ProcessProjectActions.process " + actionList.getId());
    final ApplyOptions applyOptions = new ApplyOptions(projectHandle);
    class MyVisitor implements ProjectActionList.Visitor {

        @Override
        public Result applyTo(ProjectAction action, Value result, IProgressMonitor monitor) {
            SubMonitor subMonitor = SubMonitor.convert(monitor);
            subMonitor.subTask(action.toString());
            // System.err.println("ProjectCustomAction: "+action.toString());
            try {
                if (action instanceof FileAction) {
                    new AddTargetFiles().process(projectHandle, variableMap, (FileAction) action, subMonitor);
                } else if (action instanceof DeleteResourceAction) {
                    new DeleteResource().process(projectHandle, variableMap, (DeleteResourceAction) action, subMonitor);
                } else if (action instanceof CreateFolderAction) {
                // ProjectUtilities.createFolder(projectHandle, variableMap, (CreateFolderAction)action, subMonitor);
                } else if (action instanceof ProjectOption) {
                    applyOptions.process(variableMap, (ProjectOption) action, subMonitor);
                } else if (action instanceof ExcludeAction) {
                    ProjectUtilities.excludeItem(projectHandle, (ExcludeAction) action, subMonitor);
                } else if (action instanceof ProjectActionList) {
                    ProjectActionList projectActionList = (ProjectActionList) action;
                    if (projectActionList.isDoOnceOnly()) {
                        if (previousActions.contains(projectActionList.getId())) {
                            // Don't repeat action
                            System.err.println("ProcessProjectActions.process - not repeating action " + projectActionList.getId());
                            return new Result(Status.PRUNE);
                        }
                        previousActions.add(projectActionList.getId());
                    }
                    return new Result(projectActionList.applies(variableMap) ? Status.CONTINUE : Status.PRUNE);
                } else if (action instanceof ProjectCustomAction) {
                    ProjectCustomAction customAction = (ProjectCustomAction) action;
                    Class<?> actionClass = Class.forName(customAction.getclassName());
                    Object clsInstance = actionClass.newInstance();
                    if (!(clsInstance instanceof CustomAction)) {
                        throw new Exception("Custom action does not implement required interface");
                    }
                    ((CustomAction) clsInstance).action(projectHandle, variableMap, subMonitor, customAction.getValue());
                } else if (action instanceof ProjectConstant) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardGroup) {
                // Ignore as already added to paramMap
                } else if (action instanceof ProjectVariable) {
                // Ignore as already added to paramMap
                } else if (action instanceof WizardPageInformation) {
                // Ignore as only applicable to wizard dialogues
                } else {
                    throw new Exception("Unexpected action class: " + action.getClass());
                }
            } catch (Exception e) {
                // e.printStackTrace();
                StringBuffer sb = new StringBuffer();
                sb.append("Unable to process Action " + action.toString() + "\n");
                sb.append("Action id = " + action.getId() + "\n");
                sb.append("Action owned by = " + action.getOwnerId() + "\n");
                sb.append(e.getMessage());
                return new Result(new Exception(sb.toString(), e));
            }
            return new Result(Status.CONTINUE);
        }
    }
    ;
    MyVisitor visitor = new MyVisitor();
    Result res = actionList.visit(visitor, null, monitor);
    if (res.getStatus() == Status.EXCEPTION) {
        throw res.getException();
    }
}
Also used : AddTargetFiles(net.sourceforge.usbdm.cdt.utilties.AddTargetFiles) Result(net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result) WizardPageInformation(net.sourceforge.usbdm.packageParser.WizardPageInformation) ProjectAction(net.sourceforge.usbdm.packageParser.ProjectAction) CreateFolderAction(net.sourceforge.usbdm.packageParser.CreateFolderAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ProjectVariable(net.sourceforge.usbdm.packageParser.ProjectVariable) ProjectConstant(net.sourceforge.usbdm.packageParser.ProjectConstant) WizardGroup(net.sourceforge.usbdm.packageParser.WizardGroup) DeleteResourceAction(net.sourceforge.usbdm.packageParser.DeleteResourceAction) CustomAction(net.sourceforge.usbdm.packageParser.CustomAction) ProjectCustomAction(net.sourceforge.usbdm.packageParser.ProjectCustomAction) ApplyOptions(net.sourceforge.usbdm.cdt.utilties.ApplyOptions) SubMonitor(org.eclipse.core.runtime.SubMonitor) DeleteResource(net.sourceforge.usbdm.cdt.utilties.DeleteResource) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Value(net.sourceforge.usbdm.packageParser.ProjectActionList.Value) ProjectOption(net.sourceforge.usbdm.packageParser.ProjectOption) ExcludeAction(net.sourceforge.usbdm.packageParser.ExcludeAction) ProjectActionList(net.sourceforge.usbdm.packageParser.ProjectActionList) FileAction(net.sourceforge.usbdm.packageParser.FileAction)

Aggregations

WizardPageInformation (net.sourceforge.usbdm.packageParser.WizardPageInformation)5 ProjectAction (net.sourceforge.usbdm.packageParser.ProjectAction)4 ProjectActionList (net.sourceforge.usbdm.packageParser.ProjectActionList)4 Value (net.sourceforge.usbdm.packageParser.ProjectActionList.Value)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ProjectVariable (net.sourceforge.usbdm.packageParser.ProjectVariable)3 WizardGroup (net.sourceforge.usbdm.packageParser.WizardGroup)3 HashMap (java.util.HashMap)2 AddTargetFiles (net.sourceforge.usbdm.cdt.utilties.AddTargetFiles)2 ApplyOptions (net.sourceforge.usbdm.cdt.utilties.ApplyOptions)2 DeleteResource (net.sourceforge.usbdm.cdt.utilties.DeleteResource)2 CreateFolderAction (net.sourceforge.usbdm.packageParser.CreateFolderAction)2 DeleteResourceAction (net.sourceforge.usbdm.packageParser.DeleteResourceAction)2 ExcludeAction (net.sourceforge.usbdm.packageParser.ExcludeAction)2 FileAction (net.sourceforge.usbdm.packageParser.FileAction)2 Visitor (net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor)2 Result (net.sourceforge.usbdm.packageParser.ProjectActionList.Visitor.Result)2 ProjectConstant (net.sourceforge.usbdm.packageParser.ProjectConstant)2 ProjectCustomAction (net.sourceforge.usbdm.packageParser.ProjectCustomAction)2 ProjectOption (net.sourceforge.usbdm.packageParser.ProjectOption)2