use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class SelectImportedModulesDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
parent.getShell().setText(this.title);
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = (GridLayout) composite.getLayout();
layout.numColumns = 2;
SashForm form = new SashForm(composite, SWT.HORIZONTAL);
GridData data = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
data.widthHint = 400;
data.heightHint = 300;
form.setLayoutData(data);
entityViewer = createTableViewer(form, "Entities", entityprovider, new XSDTreeLabelProvider());
typeViewer = createTableViewer(form, "Types", typeprovider, new TypesLabelProvider());
form.setWeights(new int[] { 3, 5 });
Composite compositeBtn = new Composite(composite, SWT.FILL);
compositeBtn.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
compositeBtn.setLayout(new GridLayout(1, false));
Button addXSDFromLocal = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
addXSDFromLocal.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
addXSDFromLocal.setText(Messages.AddXsdFromlocal);
addXSDFromLocal.setToolTipText(Messages.AddXsdSchemaFromlocal);
addXSDFromLocal.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
@Override
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
FileDialog fd = new FileDialog(shell.getShell(), SWT.SAVE);
// $NON-NLS-1$
fd.setFilterExtensions(new String[] { "*.xsd" });
fd.setText(Messages.ImportXSDSchema);
String filename = fd.open();
if (filename == null) {
return;
}
URL url = getSourceURL("file:///" + filename);
addSchema(url, true);
}
});
if (exAdapter != null) {
exAdapter.createDialogArea(compositeBtn);
}
Button impXSDFromExchange = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
impXSDFromExchange.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
impXSDFromExchange.setText(Messages.ImportFromExchangeServer);
impXSDFromExchange.setToolTipText(Messages.ImportSchemaFromServer);
impXSDFromExchange.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
StringBuffer repository = new StringBuffer();
ImportExchangeOptionsDialog dlg = new ImportExchangeOptionsDialog(shell.getShell(), null, false, repository);
dlg.setBlockOnOpen(true);
int ret = dlg.open();
if (ret == Window.OK) {
File dir = new File(repository.toString());
File[] fs = dir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(".xsd");
}
});
if (null == fs || fs.length == 0) {
MessageDialog.openWarning(getShell(), Messages.import_schema_failed, Messages.no_schema_available);
return;
}
for (File file : fs) {
URL url = getSourceURL("file:///" + file.getPath());
addSchema(url, true);
}
}
}
});
Button addXSDFromInputDlg = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
addXSDFromInputDlg.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
addXSDFromInputDlg.setText(Messages.AddXsdFromOther);
addXSDFromInputDlg.setToolTipText(Messages.AddFromOtherSite);
addXSDFromInputDlg.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
}
@Override
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
InputDialog id = new InputDialog(shell.getShell(), Messages.AddXsdFromOther, Messages.EnterTextUrl, "", new // $NON-NLS-1$
IInputValidator() {
@Override
public String isValid(String newText) {
if ((newText == null) || "".equals(newText)) {
return Messages.NameNotEmpty;
}
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return;
}
URL url = getSourceURL(id.getValue());
addSchema(url, true);
}
});
entityViewer.setInput(addContent);
typeViewer.setInput(addContent);
return composite;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class TransformerMainPage method rename.
public void rename(Object arg) {
if (arg != null && (arg == stepsList || arg == stepWidget.inputViewer || arg == stepWidget.outputViewer)) {
int index = stepsList.getSelectionIndices()[0];
String stepName = stepsList.getItem(index);
InputDialog id = new InputDialog(this.getSite().getShell(), Messages.TransformerMainPage_Rename, Messages.TransformerMainPage_InputDialogTitle, stepName, new IInputValidator() {
public String isValid(String newText) {
if ((newText == null) || newText.length() == 0) {
return Messages.TransformerMainPage_NameCannotbeEmpty;
}
return null;
}
});
if (id.open() == Window.OK) {
transformer.getProcessSteps().get(stepsList.getSelectionIndex()).setDescription(id.getValue());
refreshData();
markDirtyWithoutCommit();
}
}
}
use of org.eclipse.jface.dialogs.IInputValidator in project eclipse.platform.ui by eclipse-platform.
the class CopyFilesAndFoldersOperation method getNewNameFor.
/**
* Returns a new name for a copy of the resource at the given path in the
* given workspace.
*
* @param originalName
* the full path of the resource
* @param workspace
* the workspace
* @return the new full path for the copy, or <code>null</code> if the
* resource should not be copied
*/
private IPath getNewNameFor(final IPath originalName, final IWorkspace workspace) {
final IResource resource = workspace.getRoot().findMember(originalName);
final IPath prefix = resource.getFullPath().removeLastSegments(1);
// $NON-NLS-1$
final String[] returnValue = { "" };
messageShell.getDisplay().syncExec(() -> {
IInputValidator validator = new IInputValidator() {
@Override
public String isValid(String string) {
if (resource.getName().equals(string)) {
return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameMustBeDifferent;
}
IStatus status = workspace.validateName(string, resource.getType());
if (!status.isOK()) {
return status.getMessage();
}
if (workspace.getRoot().exists(prefix.append(string))) {
return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameExists;
}
return null;
}
};
final String initial = getAutoNewNameFor(originalName, workspace).lastSegment();
InputDialog dialog = new InputDialog(messageShell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogTitle, NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogMessage, resource.getName()), initial, validator) {
@Override
protected Control createContents(Composite parent) {
Control contents = super.createContents(parent);
int lastIndexOfDot = initial.lastIndexOf('.');
if (resource instanceof IFile && lastIndexOfDot > 0) {
getText().setSelection(0, lastIndexOfDot);
}
return contents;
}
};
dialog.setBlockOnOpen(true);
dialog.open();
if (dialog.getReturnCode() == Window.CANCEL) {
returnValue[0] = null;
} else {
returnValue[0] = dialog.getValue();
}
});
if (returnValue[0] == null) {
throw new OperationCanceledException();
}
return prefix.append(returnValue[0]);
}
use of org.eclipse.jface.dialogs.IInputValidator in project cicada by aquariusStudio.
the class ParseMovieAction method run.
/**
* {@inheritDoc}}
*/
@Override
public void run() {
if (this.window != null) {
IInputValidator validator = new UrlInputValidator();
String content = ClipboardUtil.getStringFromClipboard();
if (StringUtils.isNotBlank(validator.isValid(content))) {
content = "";
}
DownloadExternalUrlDialog dialog = new DownloadExternalUrlDialog(this.window.getShell(), Messages.ParseMovieAction_DownloadDialogTitle, Messages.ParseMovieAction_DownloadDialogMessage, content, validator);
if (dialog.open() == Dialog.OK) {
String[] urlStrings = StringUtil.toLines(dialog.getValue());
List<String> urlStringList = CollectionUtil.removeDuplicated(urlStrings);
ParseMovieJob job = new ParseMovieJob(Messages.ParseMovieAction_ParseMovie, dialog.isDirectDownload(), urlStringList);
job.setUser(true);
job.schedule();
}
}
}
use of org.eclipse.jface.dialogs.IInputValidator in project portfolio by buchen.
the class QuotesContextMenu method menuAboutToShow.
public void menuAboutToShow(IMenuManager parent, final Security security) {
IMenuManager manager = new MenuManager(Messages.SecurityMenuQuotes);
parent.add(manager);
Action action = new Action(Messages.SecurityMenuUpdateQuotes) {
@Override
public void run() {
new UpdateQuotesJob(owner.getClient(), security).schedule();
}
};
// enable only if online updates are configured
action.setEnabled(!QuoteFeed.MANUAL.equals(security.getFeed()) || (security.getLatestFeed() != null && !QuoteFeed.MANUAL.equals(security.getLatestFeed())));
manager.add(action);
action = new SimpleAction(Messages.SecurityMenuDebugGetHistoricalQuotes, a -> {
try {
new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, true, m -> {
if (QuoteFeed.MANUAL.equals(security.getFeed()))
return;
QuoteFeed feed = Factory.getQuoteFeedProvider(security.getFeed());
if (feed == null)
return;
QuoteFeedData data = feed.getHistoricalQuotes(security, true);
PortfolioPlugin.log(data.getErrors());
Display.getDefault().asyncExec(() -> {
if (!data.getResponses().isEmpty() || data.getErrors().isEmpty()) {
new RawResponsesDialog(Display.getDefault().getActiveShell(), data.getResponses()).open();
} else {
MultiStatus status = new MultiStatus(PortfolioPlugin.PLUGIN_ID, IStatus.ERROR, security.getName(), null);
data.getErrors().forEach(e -> status.add(new Status(IStatus.ERROR, PortfolioPlugin.PLUGIN_ID, e.getMessage())));
ErrorDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, security.getName(), status);
}
});
});
} catch (InvocationTargetException e) {
PortfolioPlugin.log(e);
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, e.getCause().getMessage());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
action.setEnabled(!QuoteFeed.MANUAL.equals(security.getFeed()));
manager.add(action);
manager.add(new Action(Messages.SecurityMenuConfigureOnlineUpdate) {
@Override
public void run() {
EditSecurityDialog dialog = owner.make(EditSecurityDialog.class, security);
dialog.setShowQuoteConfigurationInitially(true);
if (dialog.open() != Window.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Separator());
manager.add(new Action(Messages.SecurityMenuImportCSV) {
@Override
public void run() {
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
fileDialog.setFilterNames(new String[] { Messages.CSVImportLabelFileCSV, Messages.CSVImportLabelFileAll });
// $NON-NLS-1$ //$NON-NLS-2$
fileDialog.setFilterExtensions(new String[] { "*.csv", "*.*" });
String fileName = fileDialog.open();
if (fileName == null)
return;
CSVImportWizard wizard = new CSVImportWizard(owner.getClient(), owner.getPreferenceStore(), new File(fileName));
owner.inject(wizard);
wizard.setTarget(security);
Dialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
if (dialog.open() != Window.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Action(Messages.SecurityMenuImportHTML) {
@Override
public void run() {
Dialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), new ImportQuotesWizard(security));
if (dialog.open() != Window.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Action(Messages.SecurityMenuCreateManually) {
@Override
public void run() {
Dialog dialog = new SecurityPriceDialog(Display.getDefault().getActiveShell(), owner.getClient(), security);
if (dialog.open() != Window.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Separator());
manager.add(new Action(Messages.SecurityMenuExportCSV) {
@Override
public void run() {
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE);
// $NON-NLS-1$
fileDialog.setFileName(TextUtil.sanitizeFilename(security.getName() + ".csv"));
fileDialog.setOverwrite(true);
String fileName = fileDialog.open();
if (fileName == null)
return;
try {
new CSVExporter().exportSecurityPrices(new File(fileName), security);
} catch (IOException e) {
PortfolioPlugin.log(e);
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, e.getMessage());
}
}
});
manager.add(new Separator());
if (security.getCurrencyCode() != null) {
manager.add(new Action(Messages.SecurityMenuCreateQuotesFromTransactions) {
@Override
public void run() {
ExchangeRateProviderFactory factory = owner.getFromContext(ExchangeRateProviderFactory.class);
CurrencyConverter converter = new CurrencyConverterImpl(factory, security.getCurrencyCode());
QuoteFromTransactionExtractor qte = new QuoteFromTransactionExtractor(owner.getClient(), converter);
if (qte.extractQuotes(security)) {
owner.markDirty();
owner.notifyModelUpdated();
}
}
});
}
if (security.getLatest() != null) {
manager.add(new SimpleAction(Messages.SecurityMenuDeleteLatestQuote, a -> {
security.setLatest(null);
owner.markDirty();
owner.notifyModelUpdated();
}));
}
manager.add(new SimpleAction(Messages.SecurityMenuRoundToXDecimalPlaces, a -> {
IInputValidator validator = newText -> {
try {
int decimalPlaces = Integer.parseInt(newText);
if (decimalPlaces < 0 || decimalPlaces > Values.Quote.precision())
return MessageFormat.format(Messages.SecurityMenuErrorMessageRoundingMustBeBetween0AndX, Values.Quote.precision());
return null;
} catch (NumberFormatException e) {
return String.format(Messages.CellEditor_NotANumber, newText);
}
};
InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), Messages.SecurityMenuRoundToXDecimalPlaces, Messages.SecurityMenuLabelNumberOfDecimalPlaces, String.valueOf(4), validator);
if (dialog.open() != Window.OK)
return;
int newPrecision = Integer.parseInt(dialog.getValue());
boolean isDirty = false;
for (SecurityPrice price : security.getPrices()) {
final long oldValue = price.getValue();
final long newValue = BigDecimal.valueOf(oldValue).movePointLeft(Values.Quote.precision()).setScale(newPrecision, Values.MC.getRoundingMode()).movePointRight(Values.Quote.precision()).longValue();
if (oldValue != newValue) {
price.setValue(newValue);
isDirty = true;
}
}
if (isDirty) {
owner.markDirty();
owner.notifyModelUpdated();
}
}));
}
Aggregations