package com.arm.cmsis.pack.project.ui; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.PropertyPage; import com.arm.cmsis.pack.common.CmsisConstants; import com.arm.cmsis.pack.data.ICpComponent; import com.arm.cmsis.pack.info.ICpComponentInfo; import com.arm.cmsis.pack.info.ICpFileInfo; import com.arm.cmsis.pack.info.ICpPackInfo; import com.arm.cmsis.pack.project.IHelpContextIds; import com.arm.cmsis.pack.project.Messages; import com.arm.cmsis.pack.project.utils.ProjectUtils; import com.arm.cmsis.pack.ui.CpPlugInUI; import com.arm.cmsis.pack.ui.OpenURL; public class RtePropertyPage extends PropertyPage { private IFile file = null; private ICpFileInfo fi = null; private ICpComponentInfo ci = null; /** * Constructor for SamplePropertyPage. */ public RtePropertyPage() { super(); } @Override public void dispose() { super.dispose(); file = null; fi = null; ci = null; } private void addFileSection(Composite parent) { Composite composite = createSectionComposite(parent, 2); if(file == null) { return; } //Label for path field Label label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Path); IPath fullPath = file.getFullPath(); // Path text field Text projectPathText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); projectPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); projectPathText.setText(fullPath.toString()); label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Location); // Path text field Text locationText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); IPath absPath = file.getRawLocation(); if(absPath != null) { locationText.setText(absPath.toString()); } label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Type); Text typeText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); String type = null; String version = null; if(fi != null) { type = fi.getAttribute(CmsisConstants.ATTR); if(!type.isEmpty()) { type += " "; //$NON-NLS-1$ } type += fi.getAttribute(CmsisConstants.CATEGORY); version = fi.getVersion(); } else if(file.getProjectRelativePath().toString().equals(CmsisConstants.RTE_RTE_Components_h)) { type = "generated by RTE Configuration"; //$NON-NLS-1$ } if(type != null) { typeText.setText(type); } if(version != null) { label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Version); Text verText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); verText.setText(version); } } private void addSeparator(Composite parent) { Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; separator.setLayoutData(gridData); } private void addComponentSection(Composite parent) { if(ci == null) { return; } ICpComponent c = ci.getComponent(); addSeparator(parent); Composite composite = createSectionComposite(parent, 3); //Label for path field Label label = new Label(composite, SWT.NONE); label.setImage(CpPlugInUI.getImage(CpPlugInUI.ICON_COMPONENT)); label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Component); // Path text field Text nameText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); nameText.setText(ci.getName()); label = new Label(composite, SWT.NONE); // dummy label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Version); Text verText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); verText.setText(ci.getVersion()); label = new Label(composite, SWT.NONE); // dummy label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_ResolvedVersion); verText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); if(c != null) { verText.setText(c.getVersion()); } label = new Label(composite, SWT.NONE); // dummy label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_Description); final String url; String descr = null; if(c != null) { url = c.getUrl(); descr = c.getDescription(); } else { descr = Messages.RtePropertyPage_ComponentNotFound; url = null; } if(url != null) { createLink(composite, url, descr); } else { // Path text field Text descrText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); descrText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); if(descr != null) { descrText.setText(descr); } } } private void addPackSection(Composite parent) { if(ci == null) { return; } ICpPackInfo pi = ci.getPackInfo(); if(pi == null) { return; } addSeparator(parent); Composite composite = createSectionComposite(parent, 3); //Label for path field Label label = new Label(composite, SWT.NONE); label.setImage(CpPlugInUI.getImage(CpPlugInUI.ICON_PACKAGE)); label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_SoftwarePack); // Path text field Text nameText = new Text(composite, SWT.WRAP | SWT.READ_ONLY); nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); nameText.setText(pi.getId()); label = new Label(composite, SWT.NONE); // dummy label = new Label(composite, SWT.NONE); label.setText(Messages.RtePropertyPage_URL); final String url = pi.getUrl(); createLink(composite, url, null); } private Link createLink( Composite parent, final String url, String descr){ if(descr == null || descr.isEmpty()) { descr = url; } if(url != null) { descr = "<a href=\"" + url + "\">" + descr + "</a>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } Link link = new Link(parent, SWT.NONE); if(descr != null) { link.setText(descr); } link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); link.addSelectionListener(new SelectionAdapter(){ @Override public void widgetSelected(SelectionEvent e) { OpenURL.open(url, getShell()); } }); return link; } @Override protected Control createContents(Composite parent) { initFieldVariables(); Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); composite.setLayout(layout); GridData data = new GridData(GridData.FILL); data.grabExcessHorizontalSpace = true; composite.setLayoutData(data); addFileSection(composite); addComponentSection(composite); addPackSection(composite); PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IHelpContextIds.RTE_PROPERTY_PAGE); return composite; } private void initFieldVariables() { file = ProjectUtils.getRteFileResource(getElement()); if(file == null) { return; } fi = ProjectUtils.getCpFileInfo(file); if(fi != null) { ci = fi.getComponentInfo(); } } private Composite createSectionComposite(Composite parent, int numColumns) { Composite composite = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); layout.numColumns = numColumns; composite.setLayout(layout); GridData data = new GridData(); data.verticalAlignment = GridData.FILL; data.horizontalAlignment = GridData.FILL; composite.setLayoutData(data); return composite; } }