Skip to content

Commit 7fca6de

Browse files
authored
Show lifecycle mappings on open (#1155)
Instead of waiting for a first selection use the current selection when opening the view. Also use more readable String joining with comma and blank for the entries.
1 parent 8d89efc commit 7fca6de

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LifecycleMappingsViewer.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727
import java.util.Set;
2828
import java.util.concurrent.atomic.AtomicReference;
29+
import java.util.stream.Collectors;
2930

3031
import org.osgi.framework.Bundle;
3132

@@ -428,22 +429,14 @@ boolean isIgnoreMapping(MojoExecutionKey execution, List<IPluginExecutionMetadat
428429
}
429430

430431
String toString(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) {
431-
StringBuilder sb = new StringBuilder();
432432
if(mappings != null && !mappings.isEmpty()) {
433-
for(IPluginExecutionMetadata mapping : mappings) {
434-
if(sb.length() > 0) {
435-
sb.append(',');
436-
}
437-
sb.append(mapping.getAction().toString());
438-
}
439-
} else {
440-
if(LifecycleMappingFactory.isInterestingPhase(execution.lifecyclePhase())) {
441-
sb.append(PluginExecutionAction.error.toString());
442-
} else {
443-
sb.append(PluginExecutionAction.ignore.toString());
444-
}
433+
return mappings.stream().map(IPluginExecutionMetadata::getAction).map(PluginExecutionAction::toString)
434+
.collect(Collectors.joining(", ")); //$NON-NLS-1$
445435
}
446-
return sb.toString();
436+
if(LifecycleMappingFactory.isInterestingPhase(execution.lifecyclePhase())) {
437+
return PluginExecutionAction.error.toString();
438+
}
439+
return PluginExecutionAction.ignore.toString();
447440
}
448441

449442
String getSourcelabel(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings, boolean detailed) {
@@ -471,14 +464,7 @@ String getSourcelabel(MojoExecutionKey execution, List<IPluginExecutionMetadata>
471464
sources.add("uninteresting"); //$NON-NLS-1$
472465
}
473466
}
474-
StringBuilder sb = new StringBuilder();
475-
for(String source : sources) {
476-
if(sb.length() > 0) {
477-
sb.append(',');
478-
}
479-
sb.append(source);
480-
}
481-
return sb.toString();
467+
return String.join(", ", sources);
482468
}
483469

484470
private String getSourceLabel(Bundle bundle, boolean detailed) {

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenLifecycleMappingsView.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public void createPartControl(Composite parent) {
4444
mappingsViewer = new LifecycleMappingsViewer();
4545
this.composite = mappingsViewer.createContents(parent);
4646

47+
// react to current selection when opening the view
48+
handleSelectionChanged(getSite().getPage().getSelection());
4749
}
4850

4951
/* (non-Javadoc)
@@ -56,18 +58,7 @@ public void init(IViewSite site) throws PartInitException {
5658

5759
@Override
5860
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
59-
Object element;
60-
if(selection instanceof IStructuredSelection structuredSelection) {
61-
element = structuredSelection.getFirstElement();
62-
} else {
63-
element = null;
64-
}
65-
IResource resource = Adapters.adapt(element, IResource.class);
66-
if(resource != null) {
67-
mappingsViewer.setTarget(resource.getProject());
68-
} else {
69-
mappingsViewer.setTarget(null);
70-
}
61+
handleSelectionChanged(selection);
7162
}
7263
});
7364
}
@@ -80,4 +71,19 @@ public void setFocus() {
8071
composite.setFocus();
8172
}
8273

74+
private void handleSelectionChanged(ISelection selection) {
75+
Object element;
76+
if(selection instanceof IStructuredSelection structuredSelection) {
77+
element = structuredSelection.getFirstElement();
78+
} else {
79+
element = null;
80+
}
81+
IResource resource = Adapters.adapt(element, IResource.class);
82+
if(resource != null) {
83+
mappingsViewer.setTarget(resource.getProject());
84+
} else {
85+
mappingsViewer.setTarget(null);
86+
}
87+
}
88+
8389
}

0 commit comments

Comments
 (0)