use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.
the class WorkflowEditor method getNewLocation.
/**
* For SaveAs...
* @param currentLocation
* @param allowRemoteLocation local and remote mount points are added to the selection dialog
* @return new (different!) URI or null if user canceled. Caller should create a snapshot if told so.
*/
private OverwriteAndMergeInfo getNewLocation(final URI currentLocation, final boolean allowRemoteLocation) {
final AbstractExplorerFileStore currentStore = getFileStore(currentLocation);
AbstractExplorerFileStore currentParent = null;
if (currentStore != null) {
currentParent = currentStore.getParent();
}
String currentName = new Path(currentLocation.getPath()).lastSegment();
List<String> selIDs = new LinkedList<String>();
for (String id : ExplorerMountTable.getAllVisibleMountIDs()) {
AbstractContentProvider provider = ExplorerMountTable.getMountPoint(id).getProvider();
if (!provider.isRemote() || (allowRemoteLocation && provider.isWritable())) {
selIDs.add(id);
}
}
ContentObject preSel = ContentObject.forFile(currentParent);
if (isTempRemoteWorkflowEditor()) {
AbstractExplorerFileStore remoteStore = null;
try {
remoteStore = ExplorerFileSystem.INSTANCE.getStore(m_origRemoteLocation);
} catch (IllegalArgumentException e) {
/* don't preselect on unknown original location */
}
if (remoteStore != null) {
preSel = ContentObject.forFile(remoteStore);
} else {
preSel = null;
}
}
OverwriteAndMergeInfo result = null;
while (result == null) {
// keep the selection dialog open until we get a useful result
final SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(getSite().getShell(), selIDs.toArray(new String[selIDs.size()]), preSel);
SaveAsValidator validator = new SaveAsValidator(dialog, currentStore);
String defName = currentName + " - Copy";
if (!isTempRemoteWorkflowEditor()) {
if (currentParent != null) {
try {
Set<String> childs = new HashSet<String>(Arrays.asList(currentParent.childNames(EFS.NONE, null)));
defName = guessNewWorkflowNameOnSaveAs(childs, currentName);
} catch (CoreException e1) {
// keep the simple default
}
}
} else {
defName = currentName;
if (defName.endsWith("." + KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION)) {
defName = defName.substring(0, defName.length() - KNIMEConstants.KNIME_WORKFLOW_FILE_EXTENSION.length() - 1);
}
}
dialog.setTitle("Save to new Location");
dialog.setDescription("Select the new destination workflow group for the workflow.");
dialog.setValidator(validator);
// Setup the name field of the dialog
dialog.setNameFieldEnabled(true);
dialog.setNameFieldDefaultValue(defName);
final AtomicBoolean proceed = new AtomicBoolean(false);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
proceed.set(dialog.open() == Window.OK);
}
});
if (!proceed.get()) {
return null;
}
AbstractExplorerFileStore newLocation = dialog.getSelection();
if (newLocation.fetchInfo().isWorkflowGroup()) {
newLocation = newLocation.getChild(dialog.getNameFieldValue());
} else {
// in case they have selected a flow but changed the name in the name field afterwards
newLocation = newLocation.getParent().getChild(dialog.getNameFieldValue());
}
assert !newLocation.fetchInfo().exists() || newLocation.fetchInfo().isWorkflow();
if (newLocation.fetchInfo().exists()) {
// confirm overwrite (with snapshot?)
final AtomicBoolean snapshotSupported = new AtomicBoolean(false);
final AtomicReference<SnapshotPanel> snapshotPanel = new AtomicReference<SnapshotPanel>(null);
if (newLocation.getContentProvider().supportsSnapshots() && (newLocation instanceof RemoteExplorerFileStore)) {
snapshotSupported.set(true);
}
MessageDialog dlg = new MessageDialog(getSite().getShell(), "Confirm SaveAs Overwrite", null, "The selected destination\n\n\t" + newLocation.getMountIDWithFullPath() + "\n\nalready exists. Do you want to overwrite?\n", MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 1) {
/**
* {@inheritDoc}
*/
@Override
protected Control createCustomArea(final Composite parent) {
if (snapshotSupported.get()) {
snapshotPanel.set(new SnapshotPanel(parent, SWT.NONE));
snapshotPanel.get().setEnabled(true);
return snapshotPanel.get();
} else {
return null;
}
}
};
int dlgResult = dlg.open();
if (dlgResult == 2) /* CANCEL */
{
return null;
}
if (dlgResult == 0) {
/* YES (= please overwrite) */
if (snapshotPanel.get() != null) {
SnapshotPanel snapPanel = snapshotPanel.get();
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, snapPanel.createSnapshot(), snapPanel.getComment());
} else {
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, true, false, "");
}
} else {
/* NO, don't overwrite: continue while loop asking for a different location */
preSel = ContentObject.forFile(newLocation);
currentName = newLocation.getName();
}
} else {
result = new OverwriteAndMergeInfo(newLocation.toURI().toASCIIString(), false, false, false, "");
}
}
/* end of while (result != null) keep the target selection dialog open */
return result;
}
use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.
the class WorkflowMoveDropListener method performDrop.
/**
* {@inheritDoc}
*/
@Override
public boolean performDrop(final Object data) {
Object t = getCurrentTarget();
IPath targetPath = null;
if ((t instanceof IResource) && !(t instanceof IWorkspaceRoot)) {
IResource r = (IResource) t;
if (!(r instanceof IFolder || r instanceof IProject)) {
return false;
} else {
// the target must not be a node
if (isNode(r)) {
return false;
}
}
targetPath = r.getFullPath();
} else if (t == null) {
// no drop target selected: drop it in the root.
targetPath = new Path("/");
}
if (data instanceof IResource[]) {
// move should only allow drops on groups
if (isWorkflow(ResourcesPlugin.getWorkspace().getRoot().findMember(targetPath))) {
return false;
}
// thats a move of workflows/groups inside the navigator
// (ResourceTransfer)
// elements to move are in a sorted map to move short paths first
TreeSet<IPath> moves = new TreeSet<IPath>(new Comparator<IPath>() {
public int compare(final IPath o1, final IPath o2) {
if (o1.segmentCount() < o2.segmentCount()) {
return -1;
}
if (o2.segmentCount() > o1.segmentCount()) {
return 1;
}
// returning 0 prevents items from being added!!!!
return o1.equals(o2) ? 0 : 1;
}
});
IResource[] selections = (IResource[]) data;
boolean showOpenFlowError = false;
for (IResource source : selections) {
// move only workflows and groups - ignore the rest.
if (source instanceof IFolder || source instanceof IProject) {
if (KnimeResourceUtil.isOpenedWorkflow(source)) {
// can't move currently open flows - fail
showOpenFlowError = true;
break;
}
if (isNode(source)) {
// ignore selected nodes
continue;
}
moves.add(source.getFullPath());
}
}
if (showOpenFlowError) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Open Workflow(s)", "Workflows currently opened in an editor can't " + "be moved\nPlease save and close the open " + "workflow editor(s) and try again.");
return false;
}
if (selections.length > 0 && moves.size() == 0) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Move Error", "Only workflows and workflow groups can be moved.");
return false;
}
for (IPath src : moves) {
// not existing paths (already moved ones) are ignored
new MoveWorkflowAction(src, targetPath).run();
}
getViewer().setSelection(new StructuredSelection(moves.iterator().next()), true);
}
if (data instanceof URI[]) {
// thats an import of a remote workflow in a zip archive file
// (RemoteFileTransfer)
URI[] uriData = (URI[]) data;
// we should accept drops on workflow groups only
IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(targetPath);
assert r != null;
assert (r instanceof IWorkspaceRoot) || KnimeResourceUtil.isWorkflowGroup(r) || KnimeResourceUtil.isWorkflow(r);
IPath newWF;
String wfSimplename = new Path(uriData[0].getPath()).lastSegment();
if (KnimeResourceUtil.isWorkflow(r)) {
// if dropped on a workflow we store it in the parent group
newWF = targetPath.removeLastSegments(1).append(wfSimplename);
} else {
// add the workflow name to the target path
newWF = targetPath.append(wfSimplename);
}
IResource newWFres = ResourcesPlugin.getWorkspace().getRoot().findMember(newWF);
if (newWFres != null) {
// ask if we are about to overwrite
String msg;
String[] labels;
int defaultIdx;
int dlgType;
assert KnimeResourceUtil.isWorkflow(newWFres);
IPath renamedFlow = createNewName(newWF);
if (!KnimeResourceUtil.isDirtyWorkflow(newWFres)) {
labels = new String[] { "Overwrite", "New Name", "Cancel" };
defaultIdx = 0;
msg = "The target workflow exists\n\t'" + newWF.toString() + "'.\n\nPlease select:\n" + "\n- \"Overwrite\" to replace the " + "existing with the downloaded flow\n" + "\n- \"New Name\" to save downloaded " + "flow with a new name '" + renamedFlow.lastSegment() + "'\n" + "\n- \"Cancel\" to abort the download of " + "the flow";
dlgType = MessageDialog.QUESTION;
} else {
labels = new String[] { "Discard and Overwrite", "New Name", "Cancel" };
defaultIdx = 1;
msg = "The target workflow exists\n\t'" + newWF.toString() + "'\n and is modified in an editor!\n\n" + "Please select:\n" + "\n- \"Discard and Overwrite\" to discard" + " your changes and replace the existing" + " flow with the downloaded one\n" + "\n- \"New Name\" to save downloaded " + "flow with a new name '" + renamedFlow.lastSegment() + "'\n" + "\n- \"Cancel\" to abort the download of " + "the flow";
dlgType = MessageDialog.WARNING;
}
MessageDialog md = new MessageDialog(Display.getDefault().getActiveShell(), "Confirm Overwrite", null, msg, dlgType, labels, defaultIdx);
int result = md.open();
if (result != 0 && result != 1) {
// do not overwrite and do not save with new name: Cancel.
return true;
}
if (result == 1) {
// save with new name
newWF = renamedFlow;
newWFres = ResourcesPlugin.getWorkspace().getRoot().findMember(newWF);
}
}
// let the target download the flow now
String[] fileNames = RemoteFileTransfer.getInstance().requestFileContent((URI[]) data);
if (fileNames.length != 1) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Drop Error", "Only one remote workflow can be dropped at a time.");
return false;
}
IResource wf = KnimeResourceUtil.importZipFileAsWorkflow(Display.getDefault().getActiveShell(), newWF, new File(fileNames[0]));
KnimeResourceUtil.revealInNavigator(wf, true);
return true;
}
// We support RemoteFileTransfer and ResourceTransfer only
return false;
}
use of org.eclipse.jface.dialogs.MessageDialog in project yamcs-studio by yamcs.
the class PreferencePage method warningApply.
private static void warningApply() {
MessageDialog dialog = new MessageDialog(null, "Apply changes", null, "To apply preference to the Event Log, close the Event Log view an re-open it (menu Window->Show View->Event Log)", MessageDialog.INFORMATION, new String[] { "OK" }, 0);
dialog.open();
}
use of org.eclipse.jface.dialogs.MessageDialog in project translationstudio8 by heartsome.
the class ExportExternal method openConfirmDialog.
public static int openConfirmDialog(final Shell shell, final String message) {
final int[] bools = new int[1];
bools[0] = 0;
if (shell != null) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog md = new MessageDialog(shell, Messages.getString("all.dialog.confirm"), null, message, 0, new String[] { Messages.getString("all.dialog.yes"), Messages.getString("all.dialog.yestoall"), Messages.getString("all.dialog.no"), Messages.getString("all.dialog.notoall") }, CONFIRM_NO);
bools[0] = md.open();
}
});
}
return bools[0];
}
use of org.eclipse.jface.dialogs.MessageDialog in project translationstudio8 by heartsome.
the class ImportProjectWizardPage method queryOverwrite.
/**
* The <code>WizardDataTransfer</code> implementation of this
* <code>IOverwriteQuery</code> method asks the user whether the existing
* resource at the given path should be overwritten.
*
* @param pathString
* @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
* <code>"ALL"</code>, or <code>"CANCEL"</code>
*/
public String queryOverwrite(String pathString) {
Path path = new Path(pathString);
String messageString;
// and there are at least 2 segments.
if (path.getFileExtension() == null || path.segmentCount() < 2) {
messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
} else {
messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString());
}
final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question, null, messageString, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0) {
protected int getShellStyle() {
return super.getShellStyle() | SWT.SHEET;
}
};
String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
// run in syncExec because callback is from an operation,
// which is probably not running in the UI thread.
getControl().getDisplay().syncExec(new Runnable() {
public void run() {
dialog.open();
}
});
return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}
Aggregations