use of org.eclipse.m2e.core.ui.internal.search.util.Packaging in project m2e-core by eclipse-m2e.
the class MavenRepositorySearchDialog method createGAVControls.
/**
* Sets the up group-artifact-version controls
*/
private Composite createGAVControls(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
GridLayout gridLayout = new GridLayout(showScope ? 4 : 2, false);
gridLayout.marginWidth = 0;
gridLayout.horizontalSpacing = 10;
composite.setLayout(gridLayout);
Label groupIDlabel = new Label(composite, SWT.NONE);
groupIDlabel.setText(Messages.AddDependencyDialog_groupId_label);
txtGroupId = new Text(composite, SWT.BORDER);
txtGroupId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
M2EUIUtils.addRequiredDecoration(txtGroupId);
if (showScope) {
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
}
Label artifactIDlabel = new Label(composite, SWT.NONE);
artifactIDlabel.setText(Messages.AddDependencyDialog_artifactId_label);
txtArtifactId = new Text(composite, SWT.BORDER);
txtArtifactId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
M2EUIUtils.addRequiredDecoration(txtArtifactId);
if (showScope) {
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
}
Label versionLabel = new Label(composite, SWT.NONE);
versionLabel.setText(Messages.AddDependencyDialog_version_label);
txtVersion = new Text(composite, SWT.BORDER);
txtVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
if (showScope) {
Label scopeLabel = new Label(composite, SWT.NONE);
scopeLabel.setText(Messages.AddDependencyDialog_scope_label);
comScope = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
comScope.setItems(SCOPES);
GridData scopeListData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
comScope.setLayoutData(scopeListData);
comScope.setText(SCOPES[0]);
}
if (showScope) {
/*
* Fix the tab order (group -> artifact -> version -> scope)
*/
composite.setTabList(new Control[] { txtGroupId, txtArtifactId, txtVersion, comScope });
} else {
composite.setTabList(new Control[] { txtGroupId, txtArtifactId, txtVersion });
}
Packaging pack;
if (IIndex.SEARCH_PARENTS.equals(queryType)) {
pack = Packaging.POM;
} else if (IIndex.SEARCH_PLUGIN.equals(queryType)) {
pack = Packaging.PLUGIN;
} else {
pack = Packaging.ALL;
}
ProposalUtil.addGroupIdProposal(project, txtGroupId, pack);
ProposalUtil.addArtifactIdProposal(project, txtGroupId, txtArtifactId, pack);
ProposalUtil.addVersionProposal(project, mavenproject, txtGroupId, txtArtifactId, txtVersion, pack);
txtArtifactId.addModifyListener(e -> {
updateStatus(validateArtifactEntries());
if (!ignoreTextChange && !hasDisposedTextField()) {
computeResultFromField(valueOrNull(txtGroupId.getText()), valueOrNull(txtArtifactId.getText()), valueOrNull(txtVersion.getText()));
}
});
txtGroupId.addModifyListener(e -> {
updateStatus(validateArtifactEntries());
if (!ignoreTextChange && !hasDisposedTextField()) {
computeResultFromField(valueOrNull(txtGroupId.getText()), valueOrNull(txtArtifactId.getText()), valueOrNull(txtVersion.getText()));
}
});
txtVersion.addModifyListener(e -> {
if (!ignoreTextChange && !hasDisposedTextField()) {
computeResultFromField(valueOrNull(txtGroupId.getText()), valueOrNull(txtArtifactId.getText()), valueOrNull(txtVersion.getText()));
}
});
updateStatus(validateArtifactEntries());
return composite;
}
use of org.eclipse.m2e.core.ui.internal.search.util.Packaging in project m2e-core by eclipse-m2e.
the class OverviewPage method loadThis.
private void loadThis(final int mask) {
Display.getDefault().asyncExec(() -> {
removeNotifyListener(parentGroupIdText);
removeNotifyListener(parentArtifactIdText);
removeNotifyListener(parentVersionText);
removeNotifyListener(parentRelativePathText);
removeNotifyListener(artifactGroupIdText);
removeNotifyListener(artifactIdText);
removeNotifyListener(artifactVersionText);
removeNotifyListener(artifactPackagingCombo);
removeNotifyListener(projectNameText);
removeNotifyListener(projectDescriptionText);
removeNotifyListener(projectUrlText);
removeNotifyListener(inceptionYearText);
removeNotifyListener(organizationNameText);
removeNotifyListener(organizationUrlText);
removeNotifyListener(scmUrlText);
removeNotifyListener(scmConnectionText);
removeNotifyListener(scmDevConnectionText);
removeNotifyListener(scmTagText);
removeNotifyListener(ciManagementUrlCombo);
removeNotifyListener(ciManagementSystemCombo);
removeNotifyListener(issueManagementUrlCombo);
removeNotifyListener(issueManagementSystemCombo);
try {
performOnDOMDocument(new OperationTuple(getPomEditor().getDocument(), document -> {
Element root = document.getDocumentElement();
String pack = nvl(getTextValue(findChild(root, PACKAGING)));
// $NON-NLS-1$ //$NON-NLS-2$
pack = "".equals(pack) ? "jar" : pack;
if ((mask & RELOAD_BASE) != 0) {
setText(artifactGroupIdText, nvl(getTextValue(findChild(root, GROUP_ID))));
setText(artifactIdText, nvl(getTextValue(findChild(root, ARTIFACT_ID))));
setText(artifactVersionText, nvl(getTextValue(findChild(root, VERSION))));
setText(artifactPackagingCombo, pack);
String name = getTextValue(findChild(root, NAME));
setText(projectNameText, nvl(name));
String desc = getTextValue(findChild(root, DESCRIPTION));
setText(projectDescriptionText, nvl(desc));
String url = getTextValue(findChild(root, URL));
setText(projectUrlText, nvl(url));
String incep = getTextValue(findChild(root, INCEPTION_YEAR));
setText(inceptionYearText, nvl(incep));
boolean expandProjectSection = name != null || desc != null || url != null || incep != null;
projectSectionData.grabExcessVerticalSpace = expandProjectSection;
projectSection.setExpanded(expandProjectSection);
}
if ((mask & RELOAD_PARENT) != 0) {
// parent section
Element parent = findChild(root, PARENT);
String parentGrId = getTextValue(findChild(parent, GROUP_ID));
String parentArtId = getTextValue(findChild(parent, ARTIFACT_ID));
String parentVers = getTextValue(findChild(parent, VERSION));
setText(parentGroupIdText, nvl(parentGrId));
setText(parentArtifactIdText, nvl(parentArtId));
setText(parentVersionText, nvl(parentVers));
setText(parentRelativePathText, nvl(getTextValue(findChild(parent, RELATIVE_PATH))));
parentSelectAction.setEnabled(!isReadOnly());
// only enable when all 3 coordinates are actually present.
parentOpenAction.setEnabled(root != null && parentGrId != null && parentArtId != null && parentVers != null);
parentSection.setExpanded(parent != null);
}
if ((mask & RELOAD_ORG) != 0) {
// organization section
Element org = findChild(root, ORGANIZATION);
setText(organizationNameText, nvl(getTextValue(findChild(org, NAME))));
setText(organizationUrlText, nvl(getTextValue(findChild(org, URL))));
organizationSection.setExpanded(org != null);
}
if ((mask & RELOAD_SCM) != 0) {
// scm section
Element scm = findChild(root, SCM);
setText(scmUrlText, nvl(getTextValue(findChild(scm, URL))));
setText(scmConnectionText, nvl(getTextValue(findChild(scm, CONNECTION))));
setText(scmDevConnectionText, nvl(getTextValue(findChild(scm, DEV_CONNECTION))));
setText(scmTagText, nvl(getTextValue(findChild(scm, TAG))));
scmSection.setExpanded(scm != null);
}
if ((mask & RELOAD_CI) != 0) {
// ci section
Element ci = findChild(root, CI_MANAGEMENT);
setText(ciManagementSystemCombo, nvl(getTextValue(findChild(ci, SYSTEM))));
setText(ciManagementUrlCombo, nvl(getTextValue(findChild(ci, URL))));
ciManagementSection.setExpanded(ci != null);
}
if ((mask & RELOAD_IM) != 0) {
// issue management
Element im = findChild(root, ISSUE_MANAGEMENT);
setText(issueManagementSystemCombo, nvl(getTextValue(findChild(im, SYSTEM))));
setText(issueManagementUrlCombo, nvl(getTextValue(findChild(im, URL))));
issueManagementSection.setExpanded(im != null);
}
if ((mask & RELOAD_MODULES) != 0) {
// modules section..
List<Element> moduleEls = findChilds(findChild(root, MODULES), MODULE);
List<String> modules = new ArrayList<>();
for (Element moduleEl : moduleEls) {
String text = getTextValue(moduleEl);
if (text != null) {
modules.add(text);
}
}
loadModules(modules, pack);
// #335337 no editing of packaging when there are modules, results in error anyway
artifactPackagingCombo.setEnabled(modules.isEmpty());
}
if ((mask & RELOAD_PROPERTIES) != 0) {
propertiesSection.refresh();
Element props = findChild(root, PROPERTIES);
propertiesSection.setExpanded(props != null);
// TODO used to check teh model's empty state as well, not done now..
}
}, true));
} catch (Exception e) {
LOG.error("Failed to populate overview panel", e);
}
addNotifyListener(artifactGroupIdText);
addNotifyListener(artifactIdText);
addNotifyListener(artifactVersionText);
addNotifyListener(artifactPackagingCombo);
addNotifyListener(projectNameText);
addNotifyListener(projectDescriptionText);
addNotifyListener(projectUrlText);
addNotifyListener(inceptionYearText);
addNotifyListener(parentGroupIdText);
addNotifyListener(parentArtifactIdText);
addNotifyListener(parentVersionText);
addNotifyListener(parentRelativePathText);
addNotifyListener(organizationNameText);
addNotifyListener(organizationUrlText);
addNotifyListener(scmUrlText);
addNotifyListener(scmConnectionText);
addNotifyListener(scmDevConnectionText);
addNotifyListener(scmTagText);
addNotifyListener(ciManagementUrlCombo);
addNotifyListener(ciManagementSystemCombo);
addNotifyListener(issueManagementUrlCombo);
addNotifyListener(issueManagementSystemCombo);
});
}
use of org.eclipse.m2e.core.ui.internal.search.util.Packaging 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