Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand All @@ -32,10 +34,9 @@ public EspConfigParser()
}

@SuppressWarnings("unchecked")
public List<String> getTargets()
public Set<String> getTargets()
{

List<String> targets = new ArrayList<String>();
Set<String> targets = new LinkedHashSet<String>();
JSONParser jsonParser = new JSONParser();
try (FileReader reader = new FileReader(espConfigPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*******************************************************************************/
package com.espressif.idf.ui.templates;

import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import java.io.IOException;
import java.util.Iterator;

Expand All @@ -24,8 +26,9 @@
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.dialogs.PatternFilter;

Expand All @@ -43,6 +46,8 @@ public abstract class AbstractTemplatesSelectionPage extends BaseWizardSelection
protected ITemplateNode templateElements;
protected FilteredTree filteredTree;
private WizardSelectedAction doubleClickAction = new WizardSelectedAction();
private Group templateGroup;
private Button fUseTemplate;

private class WizardSelectedAction extends Action
{
Expand Down Expand Up @@ -85,12 +90,18 @@ public void createControl(Composite parent)
container.setLayoutData(new GridData(GridData.FILL_BOTH));

createAbove(container, 1);
Label label = new Label(container, SWT.NONE);
label.setText(getLabel());
GridData gd = new GridData();
label.setLayoutData(gd);
if (templateElements == null || templateElements.getChildren().isEmpty())
{
Dialog.applyDialogFont(container);
setControl(container);
return;
}

SashForm sashForm = new SashForm(container, SWT.HORIZONTAL);
GridData gd = new GridData();

templateGroup = new Group(container, SWT.NONE);
fUseTemplate = new Button(templateGroup, SWT.CHECK);
SashForm sashForm = new SashForm(templateGroup, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_BOTH);
// limit the width of the sash form to avoid the wizard
// opening very wide. This is just preferred size -
Expand All @@ -99,6 +110,33 @@ public void createControl(Composite parent)
gd.widthHint = 400;
gd.heightHint = 350;
sashForm.setLayoutData(gd);

templateGroup.setText(Messages.TemplateGroupHeader);
GridLayout groupLayout = new GridLayout();
templateGroup.setLayout(groupLayout);
GridData gridDataGp = new GridData(GridData.FILL_BOTH);
gridDataGp.widthHint = 400;
gridDataGp.heightHint = 350;
templateGroup.setLayoutData(gridDataGp);



fUseTemplate.setText(Messages.TemplateListSelectionPage_SelectTemplate_Desc);
GridData gridData = new GridData();
gridData.horizontalSpan = 1;
fUseTemplate.setLayoutData(gridData);
fUseTemplate.addSelectionListener(widgetSelectedAdapter(e -> {
templateViewer.getControl().setEnabled(fUseTemplate.getSelection());
filteredTree.setEnabled(fUseTemplate.getSelection());
if (!fUseTemplate.getSelection())
setDescription(""); //$NON-NLS-1$
else
setDescription(Messages.TemplateListSelectionPage_Template_Wizard_Desc);

setDescriptionEnabled(fUseTemplate.getSelection());
getContainer().updateButtons();
}));
fUseTemplate.setSelection(false);

templateViewer = createTreeViewer(sashForm);
templateViewer.setContentProvider(new TemplatesContentProvider());
Expand All @@ -107,7 +145,10 @@ public void createControl(Composite parent)
templateViewer.addDoubleClickListener(event -> doubleClickAction.run());
createDescriptionIn(sashForm);
createBelow(container, 1);
templateViewer.setInput(templateElements);
if (templateElements != null && !templateElements.getChildren().isEmpty())
{
templateViewer.setInput(templateElements);
}
initializeViewer();
templateViewer.addSelectionChangedListener(this);

Expand Down Expand Up @@ -230,4 +271,14 @@ public boolean canFlipToNextPage()
IStructuredSelection ssel = templateViewer.getStructuredSelection();
return ssel != null && !ssel.isEmpty();
}

public Button getfUseTemplate()
{
return fUseTemplate;
}

public void setfUseTemplate(Button fUseTemplate)
{
this.fUseTemplate = fUseTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.eclipse.ui.console.MessageConsoleStream;
import org.osgi.framework.Bundle;

import com.espressif.idf.core.IDFConstants;
Expand All @@ -37,12 +41,17 @@ public class IDFProjectGenerator extends CMakeProjectGenerator

private File sourceTemplatePath;
private boolean copyIntoWorkspace;
private String target;
protected MessageConsoleStream console;
private ILaunchBarManager launchBarManager;

public IDFProjectGenerator(String manifestFile, File source, boolean copyIntoWorkspace)
public IDFProjectGenerator(String manifestFile, File source, boolean copyIntoWorkspace, String target)
{
super(manifestFile);
this.sourceTemplatePath = source;
this.copyIntoWorkspace = copyIntoWorkspace;
this.target = target;
launchBarManager = UIPlugin.getService(ILaunchBarManager.class);
}

@Override
Expand All @@ -66,6 +75,9 @@ public void generate(Map<String, Object> model, IProgressMonitor monitor) throws
Logger.log("Source Template path:" + sourceTemplatePath); //$NON-NLS-1$
if (sourceTemplatePath == null)
{
setTarget();
// refresh to see the copied resources in the project explorer
getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
return; // let's go with the default generate
}

Expand All @@ -85,8 +97,37 @@ public void generate(Map<String, Object> model, IProgressMonitor monitor) throws
}
}

setTarget();

// refresh to see the copied resources in the project explorer
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);

}

private void setTarget() throws CoreException
{
ILaunchTarget launchTarget = findSuitableTargetForSelectedTargetString();
launchBarManager.setActiveLaunchTarget(launchTarget);
Logger.log("");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need empty logging here? Typo?

}

private ILaunchTarget findSuitableTargetForSelectedTargetString()
{
ILaunchTargetManager launchTargetManager = UIPlugin.getService(ILaunchTargetManager.class);
ILaunchTarget[] targets = launchTargetManager
.getLaunchTargetsOfType("com.espressif.idf.launch.serial.core.serialFlashTarget"); //$NON-NLS-1$
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a constant ESP_LAUNCH_TARGET_TYPE for this value in IDFLaunchConstants


for (ILaunchTarget iLaunchTarget : targets)
{
String idfTarget = iLaunchTarget.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", //$NON-NLS-1$
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a constant ATTR_IDF_TARGET for this value in IDFLaunchConstants

null);
if (idfTarget.contentEquals(target))
{
return iLaunchTarget;
}
}

return null;
}

@Override
Expand Down Expand Up @@ -130,4 +171,5 @@ protected void copyIDFTemplateToWorkspace(String projectName, File sourceTemplat
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ public class Messages extends NLS
public static String BaseWizardSelectionPage_No_Desc;
public static String TemplateListSelectionPage_SelectTemplate_Desc;
public static String TemplateListSelectionPage_Template_Wizard_Desc;
public static String TemplateListSelectionPage_Templates;
public static String TemplateListSelectionPage_Templates_Desc;
public static String NewProjectWizardPage_Header;
public static String NewProjectWizardPage_DescriptionString;
public static String TemplateSelectionToolTip;
public static String NewProjectWizardPage_NoTemplateFoundMessage;
public static String TemplateGroupHeader;
public static String NewProjectTargetSelection_Tooltip;
public static String NewProjectTargetSelection_Label;

static
{
// initialize resource bundle
Expand Down
Loading