use of org.eclipse.m2e.core.ui.internal.wizards.WidthGroup in project m2e-core by eclipse-m2e.
the class OverviewPage method createParentsection.
private void createParentsection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) {
parentSection = //
toolkit.createSection(//
composite, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE);
parentSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
parentSection.setText(Messages.OverviewPage_section_parent);
// $NON-NLS-1$ //$NON-NLS-2$
parentSection.setData("name", "parentSection");
parentSelectAction = new Action(Messages.OverviewPage_action_selectParent, MavenEditorImages.SELECT_ARTIFACT) {
@Override
public void run() {
// calculate current list of artifacts for the project - that's the current parent..
Set<ArtifactKey> current = new HashSet<>();
String parentGroup = parentGroupIdText.getText();
String parentArtifact = parentArtifactIdText.getText();
String parentVersion = parentVersionText.getText();
if (parentGroup != null && parentArtifact != null && parentVersion != null) {
current.add(new ArtifactKey(parentGroup, parentArtifact, parentVersion, null));
}
MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchParentDialog(getEditorSite().getShell(), Messages.OverviewPage_searchDialog_selectParent, getPomEditor().getMavenProject(), getProject());
if (parentGroup != null && parentGroup.trim().length() != 0) {
// chances are we will get good match by adding the groupid here..
dialog.setQuery(parentGroupIdText.getText());
} else if (artifactGroupIdText.getText() != null && artifactGroupIdText.getText().trim().length() != 0) {
// chances are we will get good match by adding the groupid here..
dialog.setQuery(artifactGroupIdText.getText());
}
if (dialog.open() == Window.OK) {
IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult();
if (af != null) {
String grid = nvl(af.group);
String ver = nvl(af.version);
parentGroupIdText.setText(grid);
parentArtifactIdText.setText(nvl(af.artifact));
parentVersionText.setText(ver);
// promote good practices ->
if (grid.equals(artifactGroupIdText.getText())) {
// if the groupId is the same, just remove it in child.
// $NON-NLS-1$
artifactGroupIdText.setText("");
}
if (ver.equals(artifactVersionText.getText())) {
// if the version is the same, just remove it in child.
// $NON-NLS-1$
artifactVersionText.setText("");
}
parentSection.setExpanded(true);
}
}
}
};
parentSelectAction.setEnabled(false);
parentOpenAction = new Action(Messages.OverviewPage_job_open, MavenEditorImages.PARENT_POM) {
@Override
public void run() {
final String groupId = parentGroupIdText.getText();
final String artifactId = parentArtifactIdText.getText();
final String version = parentVersionText.getText();
new Job(NLS.bind(Messages.OverviewPage_job, new Object[] { groupId, artifactId, version })) {
@Override
protected IStatus run(IProgressMonitor monitor) {
OpenPomAction.openEditor(groupId, artifactId, version, getPomEditor().getMavenProject(), monitor);
return Status.OK_STATUS;
}
}.schedule();
}
};
parentOpenAction.setEnabled(false);
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.add(parentOpenAction);
toolBarManager.add(parentSelectAction);
Composite toolbarComposite = toolkit.createComposite(parentSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
toolBarManager.createControl(toolbarComposite);
parentSection.setTextClient(toolbarComposite);
Composite parentComposite = toolkit.createComposite(parentSection, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginBottom = 5;
gridLayout.marginWidth = 1;
gridLayout.marginHeight = 2;
parentComposite.setLayout(gridLayout);
parentSection.setClient(parentComposite);
Label parentGroupIdLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblGroupId2, SWT.NONE);
parentGroupIdText = toolkit.createText(parentComposite, null, SWT.NONE);
GridData gd_parentGroupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd_parentGroupIdText.horizontalIndent = 4;
parentGroupIdText.setLayoutData(gd_parentGroupIdText);
// $NON-NLS-1$ //$NON-NLS-2$
parentGroupIdText.setData("name", "parentGroupId");
ProposalUtil.addGroupIdProposal(getProject(), parentGroupIdText, Packaging.POM);
M2EUIUtils.addRequiredDecoration(parentGroupIdText);
createEvaluatorInfo(parentGroupIdText);
setElementValueProvider(parentGroupIdText, new ElementValueProvider(PomEdits.PARENT, PomEdits.GROUP_ID));
setModifyListener(parentGroupIdText);
final Label parentArtifactIdLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblArtifactId, SWT.NONE);
parentArtifactIdText = toolkit.createText(parentComposite, null, SWT.NONE);
GridData gd_parentArtifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd_parentArtifactIdText.horizontalIndent = 4;
parentArtifactIdText.setLayoutData(gd_parentArtifactIdText);
// $NON-NLS-1$ //$NON-NLS-2$
parentArtifactIdText.setData("name", "parentArtifactId");
ProposalUtil.addArtifactIdProposal(getProject(), parentGroupIdText, parentArtifactIdText, Packaging.POM);
M2EUIUtils.addRequiredDecoration(parentArtifactIdText);
createEvaluatorInfo(parentArtifactIdText);
setElementValueProvider(parentArtifactIdText, new ElementValueProvider(PomEdits.PARENT, PomEdits.ARTIFACT_ID));
setModifyListener(parentArtifactIdText);
Label parentVersionLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblVersion2, SWT.NONE);
parentVersionLabel.setLayoutData(new GridData());
parentVersionText = toolkit.createText(parentComposite, null, SWT.NONE);
GridData parentVersionTextData = new GridData(SWT.LEFT, SWT.CENTER, true, false);
parentVersionTextData.horizontalIndent = 4;
parentVersionTextData.widthHint = 200;
parentVersionText.setLayoutData(parentVersionTextData);
// $NON-NLS-1$ //$NON-NLS-2$
parentVersionText.setData("name", "parentVersion");
ProposalUtil.addVersionProposal(getProject(), null, /**
* null because we don't want expressions from parent pom here
*/
parentGroupIdText, parentArtifactIdText, parentVersionText, Packaging.POM);
M2EUIUtils.addRequiredDecoration(parentVersionText);
createEvaluatorInfo(parentVersionText);
setElementValueProvider(parentVersionText, new ElementValueProvider(PomEdits.PARENT, PomEdits.VERSION));
setModifyListener(parentVersionText);
ModifyListener ml = e -> {
// apparently the loadParent() method also participates in the enablement logic from time to time..
String text1 = parentArtifactIdText.getText().trim();
String text2 = parentGroupIdText.getText().trim();
String text3 = parentVersionText.getText().trim();
if (text1.length() > 0 && text2.length() > 0 && text3.length() > 0) {
parentOpenAction.setEnabled(true);
} else {
parentOpenAction.setEnabled(false);
}
};
parentArtifactIdText.addModifyListener(ml);
parentVersionText.addModifyListener(ml);
parentGroupIdText.addModifyListener(ml);
Label parentRealtivePathLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblRelPath, SWT.NONE);
parentRelativePathText = toolkit.createText(parentComposite, null, SWT.NONE);
GridData gd_parentRelativePathText = new GridData(SWT.FILL, SWT.CENTER, true, false);
gd_parentRelativePathText.horizontalIndent = 4;
parentRelativePathText.setLayoutData(gd_parentRelativePathText);
// $NON-NLS-1$ //$NON-NLS-2$
parentRelativePathText.setData("name", "parentRelativePath");
createEvaluatorInfo(parentRelativePathText);
setElementValueProvider(parentRelativePathText, new ElementValueProvider(PomEdits.PARENT, PomEdits.RELATIVE_PATH));
setModifyListener(parentRelativePathText);
widthGroup.addControl(parentGroupIdLabel);
widthGroup.addControl(parentArtifactIdLabel);
widthGroup.addControl(parentVersionLabel);
widthGroup.addControl(parentRealtivePathLabel);
toolkit.paintBordersFor(parentComposite);
parentComposite.setTabList(new Control[] { parentGroupIdText, parentArtifactIdText, parentVersionText, parentRelativePathText });
}
use of org.eclipse.m2e.core.ui.internal.wizards.WidthGroup in project m2e-core by eclipse-m2e.
the class OverviewPage method createFormContent.
@Override
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
ScrolledForm form = managedForm.getForm();
form.setText(Messages.OverviewPage_form);
Composite body = form.getBody();
GridLayout gridLayout = new GridLayout(2, true);
gridLayout.horizontalSpacing = 7;
body.setLayout(gridLayout);
toolkit.paintBordersFor(body);
Composite leftComposite = toolkit.createComposite(body, SWT.NONE);
leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout leftCompositeLayout = new GridLayout();
leftCompositeLayout.marginWidth = 0;
leftCompositeLayout.marginHeight = 0;
leftComposite.setLayout(leftCompositeLayout);
WidthGroup leftWidthGroup = new WidthGroup();
leftComposite.addControlListener(leftWidthGroup);
createArtifactSection(toolkit, leftComposite, leftWidthGroup);
createParentsection(toolkit, leftComposite, leftWidthGroup);
createPropertiesSection(toolkit, leftComposite, leftWidthGroup);
createModulesSection(toolkit, leftComposite, leftWidthGroup);
Composite rightComposite = toolkit.createComposite(body, SWT.NONE);
rightComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
GridLayout rightCompositeLayout = new GridLayout();
rightCompositeLayout.marginWidth = 0;
rightCompositeLayout.marginHeight = 0;
rightComposite.setLayout(rightCompositeLayout);
WidthGroup rightWidthGroup = new WidthGroup();
rightComposite.addControlListener(rightWidthGroup);
createProjectSection(toolkit, rightComposite, rightWidthGroup);
createOrganizationSection(toolkit, rightComposite, rightWidthGroup);
createScmSection(toolkit, rightComposite, rightWidthGroup);
createIssueManagementSection(toolkit, rightComposite, rightWidthGroup);
createCiManagementSection(toolkit, rightComposite, rightWidthGroup);
toolkit.paintBordersFor(leftComposite);
toolkit.paintBordersFor(rightComposite);
super.createFormContent(managedForm);
}
use of org.eclipse.m2e.core.ui.internal.wizards.WidthGroup 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