Skip to content

Commit

Permalink
Merge pull request #6344 from chrisrueger/improve-template-fragment-i…
Browse files Browse the repository at this point in the history
…cons

improve TemplateFragment icons
  • Loading branch information
chrisrueger authored Nov 1, 2024
2 parents 560a0b4 + cd40249 commit b4eac9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -57,6 +58,7 @@ public class FragmentTemplateEngine {
private static final String DESCRIPTION = "description";
private static final String WORKSPACE_TEMPLATES = "-workspace-templates";
private static final String NAME = "name";
private static final Pattern COMMIT_SHA = Pattern.compile("[a-f0-9]{40}$");

final static Logger log = LoggerFactory.getLogger(FragmentTemplateEngine.class);
final List<TemplateInfo> templates = new ArrayList<>();
Expand Down Expand Up @@ -90,9 +92,24 @@ public int compareTo(TemplateInfo o) {
* by us".
*/
public boolean isOfficial() {
return id.organisation()
.equals("bndtools");
return "bndtools".equals(id.organisation());
}

/**
* Check if the id points to a specific commit SHA e.g.
* githuborg/myrepo/subfolder/workspace-template#b96e0a8877bad1c68cdc050d5854829253ef63bb
* In this case b96e0a8877bad1c68cdc050d5854829253ef63bb would be the
* SHA.
*
* @return <code>true</code> if the repoUrl points to a specific commit
* SHA.
*/
public boolean isCommitSHA() {
String ref = id.ref();
return ref != null && COMMIT_SHA.matcher(ref)
.matches();
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
Expand Down Expand Up @@ -66,8 +67,8 @@ public class NewWorkspaceWizard extends Wizard implements IImportWizard, INewWiz
final FragmentTemplateEngine templates;
private ScrolledFormText txtDescription;

final static Image ok = Icons.image("icons/tick.png", false);
final static Image warn = Icons.image("icons/warning_obj.gif", false);
final static Image verified = Icons.image("icons/tick.png", false);
final static Image verifiedGreyedOut = new Image(Display.getDefault(), verified, SWT.IMAGE_DISABLE);

public NewWorkspaceWizard() throws Exception {
setWindowTitle("Create New bnd Workspace");
Expand Down Expand Up @@ -240,8 +241,8 @@ public String getText(Object element) {
@Override
public Image getImage(Object element) {
if (element instanceof TemplateInfo ti) {
return ti
.isOfficial() ? ok : warn;
boolean officialOrSHA = ti.isOfficial() || ti.isCommitSHA();
return officialOrSHA ? verified : verifiedGreyedOut;
}

return super.getImage(element);
Expand Down

0 comments on commit b4eac9d

Please sign in to comment.