use of org.eclipse.jface.dialogs.MessageDialog in project egit by eclipse.
the class CommandConfirmation method confirmHardReset.
/**
* Ask the user to confirm hard reset. Warns the user if a running launch
* could be affected by the reset.
*
* @param shell
* @param repo
* @return {@code true} if the user confirmed hard reset
*/
public static boolean confirmHardReset(Shell shell, final Repository repo) {
String question = UIText.ResetTargetSelectionDialog_ResetConfirmQuestion;
ILaunchConfiguration launch = LaunchFinder.getRunningLaunchConfiguration(Collections.singleton(repo), null);
if (launch != null) {
question = MessageFormat.format(question, "\n\n" + // $NON-NLS-1$
MessageFormat.format(UIText.LaunchFinder_RunningLaunchMessage, launch.getName()));
} else {
// $NON-NLS-1$
question = MessageFormat.format(question, "");
}
MessageDialog messageDialog = new MessageDialog(shell, UIText.ResetTargetSelectionDialog_ResetQuestion, null, question, MessageDialog.QUESTION, new String[] { UIText.CommandConfirmationHardResetDialog_resetButtonLabel, IDialogConstants.CANCEL_LABEL }, 0);
return messageDialog.open() == Window.OK;
}
use of org.eclipse.jface.dialogs.MessageDialog in project evosuite by EvoSuite.
the class TestGenerationJob method run.
@Override
protected IStatus run(final IProgressMonitor monitor) {
// && System.getProperty("evosuite.disable").equals("1")
Boolean disabled = System.getProperty("evosuite.disable") != null;
if (disabled) {
System.out.println("TestGenerationJob: The EvoSuite plugin is disabled :(");
return Status.OK_STATUS;
}
final String suiteFileName = getSuiteFileName(suiteClass);
final IFile fileSuite = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(suiteFileName));
if (fileSuite != null && fileSuite.exists()) {
// Open test suite in editor
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow iw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = iw.getActivePage();
try {
IDE.openEditor(page, fileSuite, true);
} catch (PartInitException e1) {
System.out.println("Could not open test suite");
e1.printStackTrace();
}
}
});
// Generated tests should be checked by tester?
Boolean checkMarkers = System.getProperty("evosuite.markers.enforce") != null;
if (checkMarkers) {
String fileContents = readFileToString(suiteFileName);
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setStatementsRecovery(true);
@SuppressWarnings("unchecked") Map<String, String> COMPILER_OPTIONS = new HashMap<String, String>(JavaCore.getOptions());
COMPILER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
COMPILER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
parser.setUnitName(suiteClass);
String[] encodings = { ENCODING };
String[] classpaths = { classPath };
String[] sources = { new File(suiteFileName).getParent() };
parser.setEnvironment(classpaths, sources, encodings, true);
parser.setSource(fileContents.toCharArray());
CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
final List<String> uncheckedMethods = new ArrayList<String>();
compilationUnit.accept(new ASTVisitor() {
@Override
public boolean visit(MemberValuePair node) {
if (node.getName().toString().equals("checked") && !((BooleanLiteral) node.getValue()).booleanValue()) {
NormalAnnotation ann = (NormalAnnotation) node.getParent();
MethodDeclaration method = (MethodDeclaration) ann.getParent();
uncheckedMethods.add(method.getName().toString());
return false;
}
return true;
}
});
if (uncheckedMethods.size() > 0) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog dialog = new MessageDialog(shell, "JUnit test suite contains unit tests that need to be checked", // image
null, "The JUnit test suite " + suiteClass + " contains test cases that need to be checked:\n" + uncheckedMethods.toString(), MessageDialog.OK, new String[] { "Ok" }, 0);
dialog.open();
}
});
return Status.OK_STATUS;
}
} else
System.out.println("Not checking markers.");
} else {
System.out.println("File " + suiteFileName + " does not exist");
// TODO: Dialog
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// MessageDialog dialog = new MessageDialog(
// shell,
// "Error during test generation",
// null, // image
// "EvoSuite failed to generate tests for class"
// + suiteClass,
// MessageDialog.OK, new String[] { "Ok" }, 0);
// dialog.open();
// }
// });
// return Status.CANCEL_STATUS;
}
setThread(new Thread());
running = true;
clearMarkersTarget();
String oldTgr = getOldTestGenerationResult();
lastTest = oldTgr;
ArrayList<TestGenerationResult> results = runEvoSuite(monitor);
writeMarkersTarget(results);
// uncomment after experiment
if (writeAllMarkers)
writeMarkersTestSuite();
try {
target.getProject().refreshLocal(IProject.DEPTH_INFINITE, null);
// if ("true".equals(target.getProject().getPersistentProperty(
// EvoSuitePropertyPage.REPORT_PROP_KEY))) {
// syncWithUi(target);
// };
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
final IFile generatedSuite = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(suiteFileName));
ICompilationUnit cu = JavaCore.createCompilationUnitFrom(generatedSuite);
IWorkbenchWindow iw = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = iw.getActivePage();
IEditorPart part = IDE.openEditor(page, generatedSuite, true);
if (Activator.organizeImports()) {
OrganizeImportsAction a = new OrganizeImportsAction(part.getSite());
a.run(cu);
cu.commitWorkingCopy(true, null);
cu.save(null, true);
}
} catch (PartInitException e1) {
System.out.println("Could not open test suite to organize imports");
e1.printStackTrace();
} catch (JavaModelException e) {
System.out.println("Something went wrong while saving test suite after organizing imports");
e.printStackTrace();
}
;
}
});
} catch (CoreException e) {
System.out.println("Dear me");
e.printStackTrace();
}
Activator.CURRENT_WRITING_FILE = null;
running = false;
monitor.done();
done(ASYNC_FINISH);
Activator.FILE_QUEUE.update();
return Status.OK_STATUS;
}
use of org.eclipse.jface.dialogs.MessageDialog in project evosuite by EvoSuite.
the class TestGenerationAction method addTestJob.
/**
* Add a new test generation job to the job queue
*
* @param target
*/
protected void addTestJob(final IResource target) {
IJavaElement element = JavaCore.create(target);
if (element == null) {
return;
}
IJavaElement packageElement = element.getParent();
String packageName = packageElement.getElementName();
final String targetClass = (!packageName.isEmpty() ? packageName + "." : "") + target.getName().replace(".java", "").replace(File.separator, ".");
System.out.println("* Scheduling new automated job for " + targetClass);
final String targetClassWithoutPackage = target.getName().replace(".java", "");
final String suiteClassName = targetClass + Properties.JUNIT_SUFFIX;
final String suiteFileName = target.getProject().getLocation() + "/evosuite-tests/" + suiteClassName.replace('.', File.separatorChar) + ".java";
System.out.println("Checking for " + suiteFileName);
File suiteFile = new File(suiteFileName);
Job job = null;
if (suiteFile.exists()) {
MessageDialog dialog = new MessageDialog(shell, "Existing test suite found", // image
null, "A test suite for class \"" + targetClass + "\" already exists. EvoSuite will overwrite this test suite. Do you really want to proceed?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Overwrite", "Extend", "Rename Original", "Cancel" }, 0);
int returnCode = dialog.open();
// 1 == extend
if (returnCode == 1) {
IWorkspaceRoot wroot = target.getWorkspace().getRoot();
IResource suiteResource = wroot.getFileForLocation(new Path(suiteFileName));
job = new TestExtensionJob(shell, suiteResource, targetClass, suiteClassName);
} else if (returnCode == 2) {
// 2 == Rename
renameSuite(target, packageName, targetClassWithoutPackage + Properties.JUNIT_SUFFIX + ".java");
} else if (returnCode > 2) {
// Cancel
return;
}
}
if (job == null)
job = new TestGenerationJob(shell, target, targetClass, suiteClassName);
job.setPriority(Job.SHORT);
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule = ruleFactory.createRule(target.getProject());
// IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
job.setRule(rule);
job.setUser(true);
// start as soon as possible
job.schedule();
}
use of org.eclipse.jface.dialogs.MessageDialog in project ecf by eclipse.
the class ScreenCaptureShareRosterEntryContributionItem method makeActions.
protected IAction[] makeActions() {
// Else check for Roster entry
final IRosterEntry entry = getSelectedRosterEntry();
final IContainer c = getContainerForRosterEntry(entry);
// If roster entry is selected and it has a container
if (entry != null && c != null) {
final IChannelContainerAdapter channelAdapter = (IChannelContainerAdapter) c.getAdapter(IChannelContainerAdapter.class);
// If the container has channel container adapter and is online/available
if (channelAdapter != null && isAvailable(entry)) {
final ScreenCaptureShare tmp = ScreenCaptureShare.getScreenCaptureShare(c.getID());
// If there is an URL share associated with this container
if (tmp != null) {
final ScreenCaptureShare screencaptureshare = tmp;
final IAction action = new Action() {
public void run() {
MessageDialog dialog = new MessageDialog(null, Messages.ScreenCaptureShareRosterEntryContributionItem_SCREEN_CAPTURE_MESSAGEBOX_TITLE, Window.getDefaultImage(), Messages.ScreenCaptureShareRosterEntryContributionItem_SCREEN_CAPTURE_MESSAGEBOX_MESSAGE, MessageDialog.QUESTION, new String[] { NLS.bind(Messages.ScreenCaptureShareRosterEntryContributionItem_VERIFY_SEND_BUTTON_TEXT, entry.getName()), Messages.ScreenCaptureShareRosterEntryContributionItem_VERIFY_CANCEL_BUTTON_TEXT }, 0);
if (dialog.open() == Window.OK) {
ScreenCaptureJob screenCaptureJob = new ScreenCaptureJob(Display.getCurrent(), entry.getUser().getID(), entry.getUser().getName(), new IImageSender() {
public void sendImage(ID targetID, ImageData imageData) {
screencaptureshare.sendImage(entry.getRoster().getUser().getID(), entry.getRoster().getUser().getName(), targetID, imageData);
}
});
screenCaptureJob.schedule(SCREEN_CAPTURE_DELAY);
}
}
};
action.setText(Messages.ScreenCaptureShareRosterEntryContributionItem_SCREEN_CAPTURE_MENU);
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEF_VIEW));
return new IAction[] { action };
}
}
}
return null;
}
use of org.eclipse.jface.dialogs.MessageDialog in project ecf by eclipse.
the class XMPPHyperlink method openContainer.
/**
* @param presenceContainerAdapter
*/
private void openContainer(IContainer container) {
final IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
final IChatManager chatManager = presenceContainerAdapter.getChatManager();
final IRosterManager rosterManager = presenceContainerAdapter.getRosterManager();
if (chatManager != null && rosterManager != null) {
try {
// get local ID
final XMPPID localID = (XMPPID) rosterManager.getRoster().getUser().getID();
final Namespace ns = container.getConnectNamespace();
// create target ID
final XMPPID targetID = (isXMPPS) ? new XMPPSID(ns, getURI().getAuthority()) : new XMPPID(ns, getURI().getAuthority());
// If they are same, just tell user and return
if (localID.equals(targetID)) {
MessageDialog.openError(null, Messages.XMPPHyperlink_MESSAGING_ERROR_TITLE, Messages.XMPPHyperlink_MESSAGING_ERROR_MESSAGE);
return;
} else {
final String localHost = localID.getHostname();
final String targetHost = targetID.getHostname();
// it's pretty obvious that we wish to message to them
if (localHost.equals(targetHost)) {
openMessagesView(chatManager, localID, targetID, targetID.getUsername());
} else {
// Otherwise, ask the user whether messaging, or
// connecting is desired
final MessageDialog messageDialog = new MessageDialog(null, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_TITLE, null, NLS.bind(Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_MESSAGE, new Object[] { targetHost, localHost, targetID.getName(), localID.getName() }), MessageDialog.QUESTION, new String[] { Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_SEND_MESSAGE, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CONNECT, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CANCEL }, 2);
final int selected = messageDialog.open();
switch(selected) {
case 0:
openMessagesView(chatManager, localID, targetID, targetID.getUsername());
return;
case 1:
super.open();
return;
default:
return;
}
}
}
} catch (final Exception e) {
MessageDialog.openError(null, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE, NLS.bind(Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE, e.getLocalizedMessage()));
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE, e));
}
}
}
Aggregations