Skip to content

Commit

Permalink
Issue eclipse-archived#188: Allow user to select project styles
Browse files Browse the repository at this point in the history
  • Loading branch information
eharris369 committed Aug 6, 2019
1 parent 0d2b3ad commit f15d7d2
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,16 @@ public String getMetricsRoot() {
return null;
}
}

public static String getDisplayName(String languageId) {
if (languageId == null) {
return ProjectLanguage.LANGUAGE_UNKNOWN.getDisplayName();
}
ProjectLanguage language = ProjectLanguage.getLanguage(languageId);
if (language != null && language != ProjectLanguage.LANGUAGE_UNKNOWN) {
return language.getDisplayName();
}
return languageId;
}

};
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,16 @@ public static ProjectType getTypeFromLanguage(String language) {
return null;
}
}

public static String getDisplayName(String typeId) {
if (typeId == null) {
return ProjectType.TYPE_UNKNOWN.getDisplayName();
}
ProjectType type = ProjectType.getType(typeId);
if (type != null && type != ProjectType.TYPE_UNKNOWN) {
return type.getDisplayName();
}
return typeId;
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class CodewindUIPlugin extends AbstractUIPlugin {
PYTHON_ICON = "obj16/python.png",
SPRING_ICON = "obj16/spring.png",
SWIFT_ICON = "obj16/swift.png",
PROJECTS_ICON = "obj16/projects.png";
PROJECTS_ICON = "obj16/projects.png",
MENU_DOWN_ICON = "obj16/menuDown.gif";

// The shared instance
private static CodewindUIPlugin plugin;
Expand Down Expand Up @@ -138,6 +139,7 @@ protected ImageRegistry createImageRegistry() {
registerImage(registry, SPRING_ICON, ICON_BASE_URL + SPRING_ICON);
registerImage(registry, SWIFT_ICON, ICON_BASE_URL + SWIFT_ICON);
registerImage(registry, PROJECTS_ICON, ICON_BASE_URL + PROJECTS_ICON);
registerImage(registry, MENU_DOWN_ICON, ICON_BASE_URL + MENU_DOWN_ICON);

return registry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public class Messages extends NLS {
public static String NewProjectPage_TemplateGroupLabel;
public static String NewProjectPage_ProjectTypeGroup;
public static String NewProjectPage_FilterMessage;
public static String NewProjectPage_TemplateColumn;
public static String NewProjectPage_TypeColumn;
public static String NewProjectPage_LanguageColumn;
public static String NewProjectPage_DescriptionLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ NewProjectPage_WizardTitle=Create a new Codewind project
NewProjectPage_TemplateGroupLabel=Select the template you want to use:
NewProjectPage_ProjectTypeGroup=Project Template
NewProjectPage_FilterMessage=Type filter text
NewProjectPage_TypeColumn=Template
NewProjectPage_TemplateColumn=Template
NewProjectPage_TypeColumn=Type
NewProjectPage_LanguageColumn=Language
NewProjectPage_DescriptionLabel=Description: {0}
NewProjectPage_DescriptionNone=<none>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeoutException;
Expand All @@ -25,6 +26,9 @@
import org.eclipse.codewind.core.internal.ProcessHelper.ProcessResult;
import org.eclipse.codewind.core.internal.connection.CodewindConnection;
import org.eclipse.codewind.core.internal.console.ProjectTemplateInfo;
import org.eclipse.codewind.core.internal.constants.ProjectLanguage;
import org.eclipse.codewind.core.internal.constants.ProjectType;
import org.eclipse.codewind.ui.CodewindUIPlugin;
import org.eclipse.codewind.ui.internal.messages.Messages;
import org.eclipse.codewind.ui.internal.views.ViewHelper;
import org.eclipse.core.resources.IProject;
Expand All @@ -41,13 +45,20 @@
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
Expand All @@ -65,6 +76,7 @@ public class NewCodewindProjectPage extends WizardPage {
private Table selectionTable;
private Text descriptionLabel;
private Text projectNameText;
private List<Integer> styleList = new ArrayList<Integer>();

protected NewCodewindProjectPage(CodewindConnection connection, List<ProjectTemplateInfo> templateList) {
super(Messages.NewProjectPage_ShellTitle);
Expand Down Expand Up @@ -137,12 +149,20 @@ private void createContents(Composite parent) {
layout.marginWidth = 8;
layout.horizontalSpacing = 7;
layout.verticalSpacing = 7;
layout.numColumns = 2;
templateGroup.setLayout(layout);
templateGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));

// Style selection button
final Button styleButton = new Button(templateGroup, SWT.PUSH | SWT.RIGHT_TO_LEFT);
styleButton.setText("Select Styles");
styleButton.setToolTipText("Select the styles to work with");
styleButton.setImage(CodewindUIPlugin.getImage(CodewindUIPlugin.MENU_DOWN_ICON));
styleButton.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));

// Filter text
filterText = new Text(templateGroup, SWT.BORDER);
filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
filterText.setMessage(Messages.NewProjectPage_FilterMessage);

// Table
Expand All @@ -152,29 +172,38 @@ private void createContents(Composite parent) {
selectionTable.setLayoutData(data);

// Columns
final TableColumn featureColumn = new TableColumn(selectionTable, SWT.NONE);
featureColumn.setText(Messages.NewProjectPage_TypeColumn);
featureColumn.setResizable(true);
featureColumn.addSelectionListener(new SelectionAdapter() {
final TableColumn templateColumn = new TableColumn(selectionTable, SWT.NONE);
templateColumn.setText(Messages.NewProjectPage_TemplateColumn);
templateColumn.setResizable(true);
templateColumn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
sortTable(selectionTable, templateColumn);
}
});
final TableColumn typeColumn = new TableColumn(selectionTable, SWT.NONE);
typeColumn.setText(Messages.NewProjectPage_TypeColumn);
typeColumn.setResizable(true);
typeColumn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
sortTable(selectionTable, featureColumn);
sortTable(selectionTable, typeColumn);
}
});
final TableColumn nameColumn = new TableColumn(selectionTable, SWT.NONE);
nameColumn.setText(Messages.NewProjectPage_LanguageColumn);
nameColumn.setResizable(true);
nameColumn.addSelectionListener(new SelectionAdapter() {
final TableColumn languageColumn = new TableColumn(selectionTable, SWT.NONE);
languageColumn.setText(Messages.NewProjectPage_LanguageColumn);
languageColumn.setResizable(true);
languageColumn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
sortTable(selectionTable, nameColumn);
sortTable(selectionTable, languageColumn);
}
});

selectionTable.setHeaderVisible(true);
selectionTable.setLinesVisible(false);
selectionTable.setSortDirection(SWT.DOWN);
selectionTable.setSortColumn(featureColumn);
selectionTable.setSortColumn(templateColumn);

createItems(selectionTable, "");

Expand All @@ -188,7 +217,7 @@ public void widgetSelected(SelectionEvent event) {
descriptionLabel.setForeground(templateGroup.getForeground());
descriptionScroll.setContent(descriptionLabel);

data = new GridData(GridData.FILL, GridData.FILL, true, false);
data = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1);
int lineHeight = filterText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
data.heightHint = lineHeight * 2;
data.horizontalSpan = 2;
Expand All @@ -199,6 +228,17 @@ public void widgetSelected(SelectionEvent event) {
descriptionScroll.setForeground(templateGroup.getForeground());

// Listeners
final Shell shell = getShell();
styleButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final Menu menu = new Menu(shell, SWT.POP_UP);
fillFilterMenu(menu);
displayDropdownMenu(styleButton, menu, true);
menu.dispose();
}
});

filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
Expand Down Expand Up @@ -303,18 +343,22 @@ private void createItems(Table table, String filter) {
// Create the items for the table.
table.removeAll();
pattern.setPattern("*" + filter + "*");
for (ProjectTemplateInfo template : templateList) {
String type = template.getLabel();
String language = template.getLanguage();
if (pattern.matches(type) || (language != null && pattern.matches(language))) {
for (ProjectTemplateInfo templateInfo : templateList) {
String template = templateInfo.getLabel();
String type = ProjectType.getDisplayName(templateInfo.getProjectType());
String language = ProjectLanguage.getDisplayName(templateInfo.getLanguage());
if (pattern.matches(template) || (type != null && pattern.matches(type)) || (language != null && pattern.matches(language))) {
TableItem item = new TableItem(table, SWT.NONE);
item.setForeground(table.getForeground());
item.setBackground(table.getBackground());
item.setText(0, type);
item.setText(0, template);
if (type != null) {
item.setText(1, type);
}
if (language != null) {
item.setText(1, language);
item.setText(2, language);
}
item.setData(template);
item.setData(templateInfo);
}
}
}
Expand Down Expand Up @@ -476,4 +520,53 @@ private void getTemplates() {
Logger.logError("An error occurred trying to get the list of templates", e); //$NON-NLS-1$
}
}

protected void fillFilterMenu(final Menu menu) {
final SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
MenuItem item = (MenuItem) event.getSource();
if (item.getSelection()) {
if (item.getData() == null) {
styleList.clear();
} else {
styleList.add((Integer)item.getData());
}
} else {
if (item.getData() != null) {
styleList.remove(item.getData());
}
}
// Update template list
}
};

MenuItem item;
item = new MenuItem(menu, SWT.CHECK);
item.setText("All Styles");
item.setSelection(styleList.isEmpty());
item.addSelectionListener(listener);
for (int i = 1; i < 5; i++) {
item = new MenuItem(menu, SWT.CHECK);
item.setText("Style" + i);
item.setToolTipText("Description of style " + i + "\nSource of style " + i);
item.setData(new Integer(i));
item.setSelection(styleList.contains(item.getData()));
item.addSelectionListener(listener);
}
}

protected void displayDropdownMenu(Control anchor, Menu menu, boolean subtractWidth) {
Point size = anchor.getSize();
Point point = anchor.toDisplay(0, size.y);
menu.setLocation(point.x - (subtractWidth ? size.x : 0), point.y);
menu.setVisible(true);

while (!menu.isDisposed() && menu.isVisible()) {
Display display = menu.getShell().getDisplay();
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private String[] getProjectTypeArray() {
Arrays.sort(types, new Comparator<String>() {
@Override
public int compare(String t1, String t2) {
return getTypeDisplayName(t1).compareToIgnoreCase(getTypeDisplayName(t2));
return ProjectType.getDisplayName(t1).compareToIgnoreCase(ProjectType.getDisplayName(t2));
}
});
return types;
Expand All @@ -180,7 +180,7 @@ private String[] getLanguageArray(String type) {
Arrays.sort(languages, new Comparator<String>() {
@Override
public int compare(String l1, String l2) {
return getLanguageDisplayName(l1).compareToIgnoreCase(getLanguageDisplayName(l2));
return ProjectLanguage.getDisplayName(l1).compareToIgnoreCase(ProjectLanguage.getDisplayName(l2));
}
});
return languages;
Expand All @@ -195,19 +195,11 @@ public Image getImage(Object element) {

@Override
public String getText(Object element) {
return getTypeDisplayName((String)element);
return ProjectType.getDisplayName((String)element);
}

}

private String getTypeDisplayName(String typeId) {
ProjectType type = ProjectType.getType(typeId);
if (type != null && type != ProjectType.TYPE_UNKNOWN) {
return type.getDisplayName();
}
return typeId;
}

private class LanguageLabelProvider extends LabelProvider {

@Override
Expand All @@ -217,18 +209,10 @@ public Image getImage(Object element) {

@Override
public String getText(Object element) {
return getLanguageDisplayName((String)element);
}
}

private String getLanguageDisplayName(String languageId) {
ProjectLanguage language = ProjectLanguage.getLanguage(languageId);
if (language != null && language != ProjectLanguage.LANGUAGE_UNKNOWN) {
return language.getDisplayName();
return ProjectLanguage.getDisplayName((String)element);
}
return languageId;
}

public void setProject(IProject project) {
this.project = project;
updateTables();
Expand Down

0 comments on commit f15d7d2

Please sign in to comment.