use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project mdw-designer by CenturyLinkCloud.
the class JavaSourceHyperlink method getJavaElement.
/**
* find the source element in the project
*
* @param type
* @return the source element
* @throws JavaModelException
* @throws CoreException
*/
protected Object getJavaElement(String type) throws JavaModelException, CoreException {
Object element = null;
if (project == null) {
cantFindSourceWarning();
return null;
}
if (element == null) {
QualifiedName qName = new QualifiedName(MdwPlugin.getPluginId(), "MdwSourceLookupAllJavaProjects");
String setting = project.getProject().getPersistentProperty(qName);
boolean check = (setting != null && Boolean.valueOf(setting));
if (!check) {
String msg = "Can't locate source code for:\n" + getTypeName() + (project == null ? "" : " in project " + project.getProject().getName());
String toggleMessage = "Look in all workspace Java projects for this deployment.";
MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(MdwPlugin.getShell(), "Java Source Lookup", msg, toggleMessage, false, null, null);
check = dialog.getToggleState();
project.getProject().setPersistentProperty(qName, String.valueOf(check));
}
if (check) {
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
for (IJavaProject javaProj : javaModel.getJavaProjects()) {
Object javaElem = getJavaElement(javaProj, type);
if (javaElem != null) {
element = javaElem;
break;
}
}
}
}
return element;
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project bndtools by bndtools.
the class RepositoryBundleSelectionPart method createSection.
void createSection(Section section, FormToolkit toolkit) {
// Toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(getLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ToolItem remove = getRemoveItemTool();
if (remove != null)
remove.setEnabled(isRemovable(event.getSelection()));
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (FileTransfer.getInstance().isSupportedType(transferType))
return true;
if (ResourceTransfer.getInstance().isSupportedType(transferType))
return true;
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
if (!selectionIsDroppable(iterator.next())) {
return false;
}
}
return true;
}
private boolean selectionIsDroppable(Object element) {
return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
}
@Override
public boolean performDrop(Object data) {
TransferData transfer = getCurrentEvent().currentDataType;
if (URLTransfer.getInstance().isSupportedType(transfer)) {
String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
return handleURLDrop(urlStr);
} else if (data instanceof String[]) {
return handleFileNameDrop((String[]) data);
} else if (data instanceof IResource[]) {
return handleResourceDrop((IResource[]) data);
} else {
return handleSelectionDrop();
}
}
private boolean handleResourceDrop(IResource[] resources) {
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
return handleFileDrop(files);
}
private boolean handleFileNameDrop(String[] paths) {
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
return handleFileDrop(files);
}
private boolean handleFileDrop(File[] files) {
if (files.length > 0) {
BndPreferences prefs = new BndPreferences();
boolean hideWarning = prefs.getHideWarningExternalFile();
if (!hideWarning) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
if (Window.CANCEL == dialog.getReturnCode())
return false;
if (dialog.getToggleState()) {
prefs.setHideWarningExternalFile(true);
}
}
AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
for (Pair<String, String> addingBundle : addingBundles) {
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
}
handleAdd(addingClauses);
}
return true;
}
return false;
}
private boolean handleSelectionDrop() {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
List<VersionedClause> adding = new LinkedList<VersionedClause>();
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
if (item instanceof RepositoryBundle) {
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
adding.add(newClause);
} else if (item instanceof RepositoryBundleVersion) {
RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
adding.add(newClause);
} else if (item instanceof RepositoryResourceElement) {
RepositoryResourceElement elt = (RepositoryResourceElement) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
adding.add(newClause);
}
}
handleAdd(adding);
return true;
}
private boolean handleURLDrop(String urlStr) {
try {
URI uri = new URI(sanitizeUrl(urlStr));
AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (dialog.open() == Window.OK) {
Set<ResourceDescriptor> resources = wizard.getResult();
List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
for (ResourceDescriptor resource : resources) {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
VersionedClause clause = new VersionedClause(resource.bsn, attrs);
newBundles.add(clause);
}
handleAdd(newBundles);
return true;
}
return false;
} catch (URISyntaxException e) {
MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
return false;
}
}
private String sanitizeUrl(String urlStr) {
int newline = urlStr.indexOf('\n');
if (newline > -1)
return urlStr.substring(0, newline).trim();
return urlStr;
}
private void handleAdd(Collection<VersionedClause> newClauses) {
if (newClauses == null || newClauses.isEmpty())
return;
List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
for (VersionedClause newClause : newClauses) {
boolean found = false;
for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
VersionedClause existing = iter.next();
if (newClause.getName().equals(existing.getName())) {
int index = iter.previousIndex();
iter.set(newClause);
viewer.replace(newClause, index);
found = true;
break;
}
}
if (!found)
toAdd.add(newClause);
}
bundles.addAll(toAdd);
viewer.add(toAdd.toArray());
markDirty();
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
// Layout
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 50;
gd.heightHint = getTableHeightHint();
table.setLayoutData(gd);
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.
the class GUIResource method messageDialogWithToggle.
/**
* Generic popup with a toggle option
*/
public Object[] messageDialogWithToggle(Shell shell, String dialogTitle, Image image, String message, int dialogImageType, String[] buttonLabels, int defaultIndex, String toggleMessage, boolean toggleState) {
int imageType = 0;
if (dialogImageType == Const.WARNING) {
imageType = MessageDialog.WARNING;
}
MessageDialogWithToggle md = new MessageDialogWithToggle(shell, dialogTitle, image, message, imageType, buttonLabels, defaultIndex, toggleMessage, toggleState);
int idx = md.open();
return new Object[] { idx, md.getToggleState() };
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.
the class GroupByDialog method ok.
private void ok() {
if (Utils.isEmpty(wStepname.getText())) {
return;
}
int sizegroup = wGroup.nrNonEmpty();
int nrfields = wAgg.nrNonEmpty();
input.setPrefix(wPrefix.getText());
input.setDirectory(wSortDir.getText());
input.setLineNrInGroupField(wLineNrField.getText());
input.setAlwaysGivingBackOneRow(wAlwaysAddResult.getSelection());
input.setPassAllRows(wAllRows.getSelection());
input.allocate(sizegroup, nrfields);
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < sizegroup; i++) {
TableItem item = wGroup.getNonEmpty(i);
input.getGroupField()[i] = item.getText(1);
}
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < nrfields; i++) {
TableItem item = wAgg.getNonEmpty(i);
input.getAggregateField()[i] = item.getText(1);
input.getSubjectField()[i] = item.getText(2);
input.getAggregateType()[i] = GroupByMeta.getType(item.getText(3));
input.getValueField()[i] = item.getText(4);
}
stepname = wStepname.getText();
if (sizegroup > 0 && "Y".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y"))) {
MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.DialogTitle"), null, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.DialogMessage", Const.CR) + Const.CR, MessageDialog.WARNING, new String[] { BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.Option1") }, 0, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.Option2"), "N".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y")));
MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
md.open();
props.setCustomParameter(STRING_SORT_WARNING_PARAMETER, md.getToggleState() ? "N" : "Y");
props.saveProps();
}
dispose();
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.
the class UniqueRowsDialog method ok.
private void ok() {
if (Utils.isEmpty(wStepname.getText())) {
return;
}
int nrfields = wFields.nrNonEmpty();
input.allocate(nrfields);
// CHECKSTYLE:Indentation:OFF
for (int i = 0; i < nrfields; i++) {
TableItem item = wFields.getNonEmpty(i);
input.getCompareFields()[i] = item.getText(1);
input.getCaseInsensitive()[i] = "Y".equalsIgnoreCase(item.getText(2));
}
input.setCountField(wCountField.getText());
input.setCountRows(wCount.getSelection());
input.setRejectDuplicateRow(wRejectDuplicateRow.getSelection());
input.setErrorDescription(wErrorDesc.getText());
// return value
stepname = wStepname.getText();
if ("Y".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y"))) {
MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.DialogTitle"), null, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.DialogMessage", Const.CR) + Const.CR, MessageDialog.WARNING, new String[] { BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.Option1") }, 0, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.Option2"), "N".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y")));
MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
md.open();
props.setCustomParameter(STRING_SORT_WARNING_PARAMETER, md.getToggleState() ? "N" : "Y");
props.saveProps();
}
// Remove any error hops coming out of UniqueRows when Reject Duplicate Rows checkbox is unselected.
if (wRejectDuplicateRow.getSelection() == false) {
List<TransHopMeta> hops = this.transMeta.getTransHops();
IntStream.range(0, hops.size()).filter(hopInd -> {
TransHopMeta hop = hops.get(hopInd);
return (hop.isErrorHop() && hop.getFromStep().getName().equals(this.input.getParentStepMeta().getName()));
}).forEach(hopInd -> this.transMeta.removeTransHop(hopInd));
}
dispose();
}
Aggregations