use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY_MANAGEMENT in project m2e-core by eclipse-m2e.
the class DependenciesComposite method createDependencyManagementSection.
private void createDependencyManagementSection(SashForm verticalSash) {
Section dependencyManagementSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
dependencyManagementSection.marginWidth = 3;
dependencyManagementSection.setText(Messages.DependenciesComposite_sectionDependencyManagement);
dependencyManagementComparator = new DependenciesComparator<>();
dependencyManagementContentProvider.setComparator(dependencyManagementComparator);
dependencyManagementEditor = new PropertiesListComposite<>(dependencyManagementSection, SWT.NONE, true);
dependencyManagementEditor.setContentProvider(dependencyManagementContentProvider);
dependencyManagementEditor.setLabelProvider(dependencyManagementLabelProvider);
dependencyManagementSection.setClient(dependencyManagementEditor);
dependencyManagementEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final List<Dependency> dependencyList = dependencyManagementEditor.getSelection();
try {
editorPage.performEditOperation(document -> {
Element deps = findChild(findChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT), DEPENDENCIES);
if (deps == null) {
// TODO log
return;
}
for (Dependency dependency : dependencyList) {
Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, dependency.groupId), childEquals(ARTIFACT_ID, dependency.artifactId));
removeChild(deps, dep);
}
removeIfNoChildElement(deps);
}, log, "error removing managed dependencies");
} finally {
setDependencyManagementInput();
dependenciesEditor.refresh();
}
}));
dependencyManagementEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
Dependency dependency = dependencyManagementEditor.getSelection().get(0);
EditDependencyDialog d = new EditDependencyDialog(getShell(), true, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
d.setDependency(toApacheDependency(dependency));
if (d.open() == Window.OK) {
try {
editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
} finally {
setDependencyManagementInput();
dependencyManagementEditor.setSelection(Collections.singletonList(dependency));
// refresh this one to update decorations..
dependenciesEditor.refresh();
}
}
}));
dependencyManagementEditor.addSelectionListener(event -> {
List<Dependency> selection = dependencyManagementEditor.getSelection();
if (!selection.isEmpty()) {
dependenciesEditor.setSelection(Collections.<Object>emptyList());
}
});
toolkit.adapt(dependencyManagementEditor);
toolkit.paintBordersFor(dependencyManagementEditor);
dependencyManagementEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), true);
if (addDepDialog.open() == Window.OK) {
final IndexedArtifactFile dep = (IndexedArtifactFile) addDepDialog.getFirstResult();
final String selectedScope = addDepDialog.getSelectedScope();
try {
editorPage.performEditOperation(document -> {
Element depsEl = getChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT, DEPENDENCIES);
PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, dep.version, dep.type, selectedScope, dep.classifier);
}, log, "errror adding dependency");
} finally {
setDependencyManagementInput();
List<Dependency> dlist = getManagedDependencies();
if (!dlist.isEmpty()) {
dependencyManagementEditor.setSelection(Collections.<Dependency>singletonList(dlist.get(dlist.size() - 1)));
}
// refresh this one to update decorations..
dependenciesEditor.refresh();
}
}
}));
ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT);
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) {
{
setChecked(false);
dependencyManagementContentProvider.setShouldSort(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyManagementContentProvider.setShouldSort(isChecked());
dependencyManagementEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, MavenEditorImages.SHOW_GROUP) {
{
setChecked(false);
dependencyManagementComparator.setSortByGroups(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyManagementLabelProvider.setShowGroupId(isChecked());
dependencyManagementComparator.setSortByGroups(isChecked());
dependencyManagementEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) {
{
setChecked(true);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
TableViewer viewer = dependencyManagementEditor.getViewer();
if (isChecked()) {
viewer.addFilter(searchFilter);
} else {
viewer.removeFilter(searchFilter);
}
viewer.refresh();
if (isChecked()) {
searchControl.getSearchText().setFocus();
}
}
});
Composite toolbarComposite = toolkit.createComposite(dependencyManagementSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
modulesToolBarManager.createControl(toolbarComposite);
dependencyManagementSection.setTextClient(toolbarComposite);
}
Aggregations