use of org.eclipse.m2e.editor.composites.ListEditorContentProvider in project m2e-core by eclipse-m2e.
the class PropertiesSection method createSection.
private Section createSection() {
propertiesSection = //
toolkit.createSection(//
composite, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE);
propertiesSectionData = new GridData(SWT.FILL, SWT.FILL, true, false);
propertiesSection.setLayoutData(propertiesSectionData);
propertiesSection.setText(Messages.PropertiesSection_section_properties);
// $NON-NLS-1$ //$NON-NLS-2$
propertiesSection.setData("name", "propertiesSection");
propertiesSection.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(ExpansionEvent e) {
setExpanded(e.getState());
}
});
toolkit.paintBordersFor(propertiesSection);
propertiesEditor = new ListEditorComposite<>(propertiesSection, SWT.NONE);
propertiesSection.setClient(propertiesEditor);
// $NON-NLS-1$ //$NON-NLS-2$
propertiesEditor.getViewer().getTable().setData("name", "properties");
propertiesEditor.setContentProvider(new ListEditorContentProvider<>());
propertiesEditor.setLabelProvider(new PropertyPairLabelProvider());
propertiesEditor.setCreateButtonListener(SelectionListener.widgetSelectedAdapter(e -> createNewProperty()));
propertiesEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> deleteProperties(propertiesEditor.getSelection())));
propertiesEditor.setDoubleClickListener(event -> editProperty(propertiesEditor.getSelection()));
toolkit.paintBordersFor(propertiesEditor);
toolkit.adapt(propertiesEditor);
return propertiesSection;
}
use of org.eclipse.m2e.editor.composites.ListEditorContentProvider in project m2e-core by eclipse-m2e.
the class OverviewPage method createModulesSection.
private void createModulesSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) {
// XXX should disable Modules actions based on artifact packaging and only add modules when packaging is "pom"
modulesSection = //
toolkit.createSection(//
composite, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE);
GridData moduleSectionData = new GridData(SWT.FILL, SWT.FILL, true, true);
modulesSection.setLayoutData(moduleSectionData);
modulesSection.setText(Messages.OverviewPage_section_modules);
// $NON-NLS-1$ //$NON-NLS-2$
modulesSection.setData("name", "modulesSection");
modulesSection.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(ExpansionEvent e) {
moduleSectionData.grabExcessVerticalSpace = e.getState();
modulesSection.getParent().layout();
}
});
modulesSectionComposite = toolkit.createComposite(modulesSection);
modulesStack = new StackLayout();
modulesSectionComposite.setLayout(modulesStack);
modulesSection.setClient(modulesSectionComposite);
noModules = toolkit.createComposite(modulesSectionComposite);
noModules.setLayout(new GridLayout(1, false));
Label label = toolkit.createLabel(noModules, Messages.OverviewPage_msg_not_pom_packaging);
GridData gd_label = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
gd_label.verticalIndent = 12;
gd_label.horizontalIndent = 12;
label.setLayoutData(gd_label);
modulesEditor = new ListEditorComposite<>(modulesSectionComposite, SWT.NONE, true);
// $NON-NLS-1$ //$NON-NLS-2$
modulesEditor.getViewer().getTable().setData("name", "modulesEditor");
toolkit.paintBordersFor(modulesEditor);
toolkit.adapt(modulesEditor);
modulesEditor.setContentProvider(new ListEditorContentProvider<>());
modulesEditor.setLabelProvider(new ModulesLabelProvider(this));
modulesEditor.setOpenListener(openevent -> {
final List<String> selection = modulesEditor.getSelection();
new Job(Messages.OverviewPage_opening_editors) {
@Override
protected IStatus run(IProgressMonitor monitor) {
for (String module : selection) {
IMavenProjectFacade projectFacade = findModuleProject(module);
if (projectFacade != null) {
ArtifactKey key = projectFacade.getArtifactKey();
OpenPomAction.openEditor(key.getGroupId(), key.getArtifactId(), key.getVersion(), getPomEditor().getMavenProject(), monitor);
} else {
IFile modulePom = findModuleFile(module);
if (modulePom != null && modulePom.isAccessible()) {
// $NON-NLS-1$
OpenPomAction.openEditor(new FileEditorInput(modulePom), "pom.xml");
}
}
}
return Status.OK_STATUS;
}
}.schedule();
});
modulesEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final Set<Object> moduleContainers = new HashSet<>();
final List<String> modules = new ArrayList<>();
try {
performOnDOMDocument(new OperationTuple(getPomEditor().getDocument(), document -> {
Element modsEl = findChild(document.getDocumentElement(), MODULES);
for (Element el : findChilds(modsEl, MODULE)) {
String m = getTextValue(el);
if (m != null) {
modules.add(m);
}
}
}, true));
} catch (Exception e1) {
LOG.error("Cannot load modules", e1);
}
for (String module : modules) {
IMavenProjectFacade facade = findModuleProject(module);
if (facade != null) {
moduleContainers.add(facade.getProject().getLocation());
}
IFile file = findModuleFile(module);
if (file != null) {
moduleContainers.add(file.getParent().getLocation());
}
}
moduleContainers.add(getProject().getLocation());
MavenModuleSelectionDialog dialog = new MavenModuleSelectionDialog(getSite().getShell(), moduleContainers);
if (dialog.open() == Window.OK) {
addSelectedModules(dialog.getResult(), dialog.isPomUpdateRequired());
}
}));
modulesEditor.setCreateButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
IEditorInput editorInput = OverviewPage.this.pomEditor.getEditorInput();
if (editorInput instanceof FileEditorInput) {
MavenModuleWizard wizard = new MavenModuleWizard(true);
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile()));
WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
int res = dialog.open();
if (res == Window.OK) {
createNewModule(wizard.getModuleName());
}
}
}));
modulesEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
try {
performEditOperation(document -> {
Element root = document.getDocumentElement();
Element modules = findChild(root, MODULES);
if (modules != null) {
for (String module : modulesEditor.getSelection()) {
Element modEl = findChild(modules, MODULE, textEquals(module));
if (modEl != null) {
modules.removeChild(modEl);
}
}
// now remove the <modules> element itself when there are no more elements left
removeIfNoChildElement(modules);
}
}, LOG, "error removing module entry");
} finally {
loadThis(RELOAD_MODULES);
}
}));
modulesEditor.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(Object element, String property) {
return true;
}
@Override
public Object getValue(Object element, String property) {
return element;
}
@Override
public void modify(Object element, String property, final Object value) {
final int n = modulesEditor.getViewer().getTable().getSelectionIndex();
try {
performEditOperation(document -> {
Element root = document.getDocumentElement();
Element module = findChild(findChild(root, MODULES), MODULE, childAt(n));
if (module != null && !value.equals(getTextValue(module))) {
setText(module, value.toString());
}
}, LOG, "error changing module entry");
} finally {
loadThis(RELOAD_MODULES);
}
}
});
modulesEditor.getViewer().addDropSupport(DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new DropTargetAdapter() {
@Override
public void dragEnter(DropTargetEvent event) {
event.detail = DND.DROP_LINK;
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
event.detail = DND.DROP_LINK;
}
@Override
public void drop(DropTargetEvent event) {
if (event.data instanceof Object[]) {
addSelectedModules((Object[]) event.data, true);
}
}
});
newModuleElementAction = new Action(Messages.OverviewPage_action_newModuleElement, MavenImages.NEW_POM) {
@Override
public void run() {
// $NON-NLS-1$
createNewModule("?");
}
};
// newModuleProjectAction = new Action(Messages.OverviewPage_action_new_module_project, MavenEditorImages.ADD_MODULE) {
// public void run() {
// IEditorInput editorInput = OverviewPage.this.pomEditor.getEditorInput();
// if(editorInput instanceof FileEditorInput) {
// MavenModuleWizard wizard = new MavenModuleWizard(true);
// wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile()));
// WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
// int res = dialog.open();
// if(res == Window.OK) {
// createNewModule(wizard.getModuleName());
// }
// }
// }
// };
ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT);
modulesToolBarManager.add(newModuleElementAction);
// modulesToolBarManager.add(newModuleProjectAction);
Composite toolbarComposite = toolkit.createComposite(modulesSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
modulesToolBarManager.createControl(toolbarComposite);
modulesSection.setTextClient(toolbarComposite);
modulesEditor.setReadOnly(pomEditor.isReadOnly());
newModuleElementAction.setEnabled(!pomEditor.isReadOnly());
// newModuleProjectAction.setEnabled(!pomEditor.isReadOnly());
}
Aggregations