use of org.eclipse.jface.action.ToolBarManager 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.jface.action.ToolBarManager in project m2e-core by eclipse-m2e.
the class DependenciesComposite method createDependenciesSection.
private void createDependenciesSection(SashForm verticalSash) {
Section dependenciesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
dependenciesSection.marginWidth = 3;
dependenciesSection.setText(Messages.DependenciesComposite_sectionDependencies);
dependenciesComparator = new DependenciesComparator<>();
dependenciesContentProvider.setComparator(dependenciesComparator);
dependenciesEditor = new DependenciesListComposite<>(dependenciesSection, SWT.NONE, true);
dependenciesEditor.setCellLabelProvider(new DelegatingStyledCellLabelProvider(dependencyLabelProvider));
dependenciesEditor.setContentProvider(dependenciesContentProvider);
dependenciesEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final List<Object> dependencyList = dependenciesEditor.getSelection();
try {
editorPage.performEditOperation(document -> {
Element deps = findChild(document.getDocumentElement(), DEPENDENCIES);
if (deps == null) {
// TODO log
return;
}
for (Object dependency : dependencyList) {
if (dependency instanceof Dependency) {
Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, ((Dependency) dependency).groupId), childEquals(ARTIFACT_ID, ((Dependency) dependency).artifactId));
removeChild(deps, dep);
}
}
removeIfNoChildElement(deps);
}, log, "error removing dependencies");
} finally {
setDependenciesInput();
}
}));
dependenciesEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
Object selection = dependenciesEditor.getSelection().get(0);
if (selection instanceof Dependency) {
Dependency dependency = (Dependency) selection;
EditDependencyDialog d = new EditDependencyDialog(getShell(), false, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
d.setDependency(toApacheDependency(dependency));
if (d.open() == Window.OK) {
try {
editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
} finally {
setDependenciesInput();
dependenciesEditor.setSelection(Collections.singletonList((Object) dependency));
}
}
} else if (selection instanceof org.apache.maven.model.Dependency) {
/*
* TODO: Support editing or displaying of inherited/managed dependencies.
*/
}
}));
dependenciesSection.setClient(dependenciesEditor);
toolkit.adapt(dependenciesEditor);
toolkit.paintBordersFor(dependenciesEditor);
dependenciesEditor.setManageButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
try {
openManageDependenciesDialog();
} catch (InvocationTargetException e1) {
MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
} catch (InterruptedException e1) {
MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
}
}));
dependenciesEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), false);
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(), DEPENDENCIES);
PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, isManaged(dep.group, dep.artifact, dep.version) ? null : dep.version, dep.type, selectedScope, dep.classifier);
}, log, "errror adding dependency");
} finally {
setDependenciesInput();
List<Dependency> deps = getDependencies();
if (!deps.isEmpty()) {
dependenciesEditor.setSelection(Collections.<Object>singletonList(deps.get(deps.size() - 1)));
}
}
}
}));
ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT);
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) {
{
setChecked(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependenciesContentProvider.setShouldSort(isChecked());
dependenciesEditor.getViewer().refresh();
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showInheritedDependencies, MavenEditorImages.SHOW_INHERITED_DEPENDENCIES) {
{
setChecked(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
if (isChecked()) {
showInheritedDependencies = true;
} else {
showInheritedDependencies = false;
}
ISelection selection = dependenciesEditor.getViewer().getSelection();
setDependenciesInput();
dependenciesEditor.getViewer().refresh();
dependenciesEditor.getViewer().setSelection(selection, true);
}
});
modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, MavenEditorImages.SHOW_GROUP) {
{
setChecked(false);
dependenciesComparator.setSortByGroups(false);
}
@Override
public int getStyle() {
return AS_CHECK_BOX;
}
@Override
public void run() {
dependencyLabelProvider.setShowGroupId(isChecked());
dependenciesComparator.setSortByGroups(isChecked());
dependenciesEditor.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 = dependenciesEditor.getViewer();
if (isChecked()) {
viewer.addFilter(searchFilter);
} else {
viewer.removeFilter(searchFilter);
}
viewer.refresh();
if (isChecked()) {
searchControl.getSearchText().setFocus();
}
}
});
Composite toolbarComposite = toolkit.createComposite(dependenciesSection);
GridLayout toolbarLayout = new GridLayout(1, true);
toolbarLayout.marginHeight = 0;
toolbarLayout.marginWidth = 0;
toolbarComposite.setLayout(toolbarLayout);
toolbarComposite.setBackground(null);
modulesToolBarManager.createControl(toolbarComposite);
dependenciesSection.setTextClient(toolbarComposite);
}
use of org.eclipse.jface.action.ToolBarManager in project m2e-core by eclipse-m2e.
the class MarkerHoverControl method disposeDeferredCreatedContent.
protected void disposeDeferredCreatedContent() {
Control[] children = parent.getChildren();
for (Control child : children) {
child.dispose();
}
ToolBarManager toolBarManager = getToolBarManager();
if (toolBarManager != null)
toolBarManager.removeAll();
}
use of org.eclipse.jface.action.ToolBarManager in project tdi-studio-se by Talend.
the class AbstractSQLEditorComposite method createToolBar.
/**
* qzhang Comment method "createToolBar".
*/
protected void createToolBar() {
// create coolbar
coolBar = new CoolBar(this, SWT.NONE);
coolBarMgr = new CoolBarManager(coolBar);
GridData gid = new GridData();
gid.horizontalAlignment = GridData.FILL;
coolBar.setLayoutData(gid);
// initialize default actions
defaultToolBarMgr = new ToolBarManager(SWT.NONE);
execSQLAction = new ExecSQLAction(SQLResultComposite.getInstance(), this);
openFileAction = new OpenFileAction();
openFileAction.setEditor(this);
saveSQLAction = new SaveSQLAction(getRepositoryNode(), connParam);
saveSQLAction.setEditor(this);
saveAsSQLAction = new SaveAsSQLAction(getRepositoryNode(), connParam);
saveAsSQLAction.setEditor(this);
exportAction = new SaveFileAsAction();
exportAction.setEditor(this);
clearTextAction = new ClearTextAction();
clearTextAction.setEditor(this);
guiModificationQueryAction = new GUIModificationQueryAction(getRepositoryNode(), connParam, dialog);
guiModificationQueryAction.setEditor(this);
// initialize hyWang's ACTION
contextModeAction = new ContextModeAction(getRepositoryNode(), connParam);
addDefaultActions();
// initialize session actions
sessionToolBarMgr = new ToolBarManager(SWT.NONE);
sessionSwitcher = new SQLEditorSessionSwitcher(this);
sessionToolBarMgr.add(sessionSwitcher);
// initialize hyWang's BUTTON and TOOLBAR
contextToolBarMgr = new ToolBarManager(SWT.NONE);
contextmode = new ContextModeSessionSwitcher(this, contextModeAction);
contextToolBarMgr.add(contextmode);
// add all toolbars to parent coolbar
coolBar.setLocked(true);
coolBarMgr.add(new ToolBarContributionItem(defaultToolBarMgr));
coolBarMgr.add(new ToolBarContributionItem(sessionToolBarMgr));
// add hyWang's toolbar to coolbar
coolBarMgr.add(new ToolBarContributionItem(contextToolBarMgr));
coolBarMgr.update(true);
}
use of org.eclipse.jface.action.ToolBarManager in project tdi-studio-se by Talend.
the class DBStructureComposite method createToolbar.
/**
* create toobar.
*/
private void createToolbar() {
Label label = new Label(this, SWT.NONE);
//$NON-NLS-1$ //$NON-NLS-2$
label.setText(" " + Messages.getString("DBStructureComposite.DatabaseStructure"));
label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT);
toolBarMgr.createControl(this);
if (listAllConnectionsAction == null) {
listAllConnectionsAction = new ListAllConnectionAction(SWT.TOGGLE);
}
toolBarMgr.add(listAllConnectionsAction);
if (refreshAllConnectionsAction == null) {
refreshAllConnectionsAction = new RefreshAllConnectionAction();
}
toolBarMgr.add(refreshAllConnectionsAction);
toolBarMgr.update(true);
toolBarMgr.getControl().setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
}
Aggregations