Skip to content

Commit

Permalink
Show lifecycle mappings on open (#1155)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bananeweizen committed Dec 29, 2022
1 parent 8d89efc commit 7fca6de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import org.osgi.framework.Bundle;

Expand Down Expand Up @@ -428,22 +429,14 @@ boolean isIgnoreMapping(MojoExecutionKey execution, List<IPluginExecutionMetadat
}

String toString(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings) {
StringBuilder sb = new StringBuilder();
if(mappings != null && !mappings.isEmpty()) {
for(IPluginExecutionMetadata mapping : mappings) {
if(sb.length() > 0) {
sb.append(',');
}
sb.append(mapping.getAction().toString());
}
} else {
if(LifecycleMappingFactory.isInterestingPhase(execution.lifecyclePhase())) {
sb.append(PluginExecutionAction.error.toString());
} else {
sb.append(PluginExecutionAction.ignore.toString());
}
return mappings.stream().map(IPluginExecutionMetadata::getAction).map(PluginExecutionAction::toString)
.collect(Collectors.joining(", ")); //$NON-NLS-1$
}
return sb.toString();
if(LifecycleMappingFactory.isInterestingPhase(execution.lifecyclePhase())) {
return PluginExecutionAction.error.toString();
}
return PluginExecutionAction.ignore.toString();
}

String getSourcelabel(MojoExecutionKey execution, List<IPluginExecutionMetadata> mappings, boolean detailed) {
Expand Down Expand Up @@ -471,14 +464,7 @@ String getSourcelabel(MojoExecutionKey execution, List<IPluginExecutionMetadata>
sources.add("uninteresting"); //$NON-NLS-1$
}
}
StringBuilder sb = new StringBuilder();
for(String source : sources) {
if(sb.length() > 0) {
sb.append(',');
}
sb.append(source);
}
return sb.toString();
return String.join(", ", sources);
}

private String getSourceLabel(Bundle bundle, boolean detailed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void createPartControl(Composite parent) {
mappingsViewer = new LifecycleMappingsViewer();
this.composite = mappingsViewer.createContents(parent);

// react to current selection when opening the view
handleSelectionChanged(getSite().getPage().getSelection());
}

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

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
Object element;
if(selection instanceof IStructuredSelection structuredSelection) {
element = structuredSelection.getFirstElement();
} else {
element = null;
}
IResource resource = Adapters.adapt(element, IResource.class);
if(resource != null) {
mappingsViewer.setTarget(resource.getProject());
} else {
mappingsViewer.setTarget(null);
}
handleSelectionChanged(selection);
}
});
}
Expand All @@ -80,4 +71,19 @@ public void setFocus() {
composite.setFocus();
}

private void handleSelectionChanged(ISelection selection) {
Object element;
if(selection instanceof IStructuredSelection structuredSelection) {
element = structuredSelection.getFirstElement();
} else {
element = null;
}
IResource resource = Adapters.adapt(element, IResource.class);
if(resource != null) {
mappingsViewer.setTarget(resource.getProject());
} else {
mappingsViewer.setTarget(null);
}
}

}

0 comments on commit 7fca6de

Please sign in to comment.