How to check if save button is clicked in Eclipse Plugin development? - eclipse-plugin

Probably a duplicate of this question, but I am specifically looking for a way to check that the save button in Eclipse was clicked, not that the editor is being saved.

You can use an IExecutionListener to listen to the File Save command. Something like:
ICommandService commandSvc = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
Command saveCommand = commandSvc.getCommand(IWorkbenchCommandConstants.FILE_SAVE);
saveCommand.addExecutionListener(new IExecutionListener()
{
#Override
public void preExecute(final String commandId, final ExecutionEvent event)
{
}
#Override
public void postExecuteSuccess(final String commandId, final Object returnValue)
{
}
#Override
public void postExecuteFailure(final String commandId, final ExecutionException exception)
{
}
#Override
public void notHandled(final String commandId, final NotHandledException exception)
{
}
});
IWorkbenchCommandConstants.FILE_SAVE is the standard constant containing the file save command id.
The ExecutionEvent parameter has a getTrigger method which returns to object that caused the command to run. It looks like this will be a MenuItem if the 'File > Save' menu caused the command to run.

Related

Revit Synchronization event

Starting with this...
https://github.com/jeremytammik/RevitLookup/blob/master/CS/EventTrack/Events/ApplicationEvents.cs
I'm trying to add an event listener for a synchronization event. the code below throws an error stating that the m_app is null. Can i not subscribe to this event while Revit is starting up?
I was able to do this before with application.ViewActivated += ..... Im wondering if this has something to do with DB vs UI driven events and when they are allowed to be subscribed to? I just don't know.
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app = null;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
return Result.Succeeded;
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("asd","asd");
}
}
}
Here is updated code reflecting my response to the first answer. The message box opens when the document is loaded. No errors are thrown when I try to initialize the synchronization event handlers, however, neither of the message boxes open before or after a synchronization event.
public class checkHealth : IExternalApplication
{
// Document doc;
static public Autodesk.Revit.ApplicationServices.Application m_app;
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentOpened += new EventHandler<DocumentOpenedEventArgs>(app_DocOpened);
return Result.Succeeded;
}
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}
void m_app_DocumentSavingToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)
{
MessageBox.Show("sync", "sync");
}
void m_app_DocumentSavedToCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
{
MessageBox.Show("Doone", "Done");
}
}
this worked.... Thanks largely in part to the SDK sample project EventsMonitor
namespace RevitModelHealth
{
public class checkHealth : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(app_syncStart);
application.ControlledApplication.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(app_syncOver);
return Result.Succeeded;
}
public void app_syncStart(object o ,DocumentSynchronizingWithCentralEventArgs args)
{
MessageBox.Show("","Stasrting");
}
public void app_syncOver(object o,DocumentSynchronizedWithCentralEventArgs args)
{
MessageBox.Show("", "Over");
}
}
}
Try
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral)
in your OnStartup() method.
The call is failing because instance member m_app is initialized to null.
The UIApplication.ControlledApplication object that raises the DocumentSynchronizingWithCentralEventArgs is being accessible from the parameter to OnStartup.
You can try this:
public void app_DocOpened(object sender, DocumentOpenedEventArgs args)
{
MessageBox.Show("asd","asd");
Autodesk.Revit.ApplicationServices.Application m_app = args.Document.Application;
m_app.DocumentSynchronizingWithCentral += new EventHandler<DocumentSynchronizingWithCentralEventArgs>(m_app_DocumentSavingToCentral);
m_app.DocumentSynchronizedWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs>(m_app_DocumentSavedToCentral);
}

How to transfer value from website to windows forms online?

I am creating an application on Windows Form and collided with a trouble.
I am getting each second a value from a website by Selenium Webdriver, using XPath and recording it to my local string. I am getting value of a timer. It doesn't matter, it's comfortable to me to get it like a string.
So. I have a loop, which reading data from website and this string I put to TextBox each second too.
But I am not able to see an output of the textBox until my loop is run. I don't want to stop it.
I want to see values from a website online in my application.
Do you have ideas how to refresh the form each second?
I can provide my code if you need.
Thank you in advance, my guru!
public static ChromeDriver GetDriver() {
return new ChromeDriver();
}
public static void CheckGame(string URLevent) {
while (GameIsRun) {
GetInformation(GetDriver(), URLevent);
GameIsRun = false;
}
}
static void GetInformation(ChromeDriver driver, string URLevent) {
driver.Navigate().GoToUrl(URLevent);
do {
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/" +
"div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
Print print = new Print()
print.Info(TimeOfGame);
System.Threading.Thread.Sleep(1000);
}
while (TimeOfGame != "90:00");
}
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
Form form = new Form();
}
private static Form1 _form = null;
public static Form1 Form {
get {
if (_form == null) {
_form = new Form1();
}
return _form;
}
}
private void button1_Click(object sender, EventArgs e) {
string eventId = tbEventID.Text; //this works vice versa. It's not my issue.
string URLevent = "url..." + tbEventID.Text + "/";
Program.CheckGame(URLevent);
}
}
public class Print {
public void Info(string TimeOfGame) {
Form1.Form.tbTeam1.Text = TimeOfGame;
//my issue is here. I want to check result at TextBox each second!
}
}
This statement in your code
TimeOfGame = driver.FindElement(By.XPath("html/body/div/div/div//div/div[#class='headroom-wrapper']/div//div[3]/div")).GetAttribute("innerHTML");
is very brittle. You should use getText() method for extracting the inner text of HTML methods. Also, in order to locate webElement precisely, it is preferred to use focused relative Xpath over absolute Xpath.

how to remove pop-out and zoom button google doc?

I am loading the pdf documents in WebView through appending the pdf url to google doc api
http://docs.google.com/gview?embedded=true&url=myurl
Pdf is loading just fine but the webpage displays two options - Zoom-in and Pop-Out. Is there any way to disable/hide pop-out option and zoom button? Any help would be appreciated.Thanks in advance!
webview.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webview.loadUrl("javascript:(function() { " +
"document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
})
Better and easy way just open your google doc file link.
Right click on zoom button and select inspect element and copy the parent div class name.
Then add it like this:
webView.loadUrl("javascript:(function() {document.querySelector('[class=\"ndfHFb-c4YZDc-Wrql6b\"]').remove();})()");
inside onPageFinished() method.
I have use it and its working fine for pop out click disabled.
webview.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
})

Android App: Replace default button background with custom background in a Dialog Fragment

What I'm trying to do is change the default backgrounds of a custom DialogFragment that I have written. Normally, I would do this by changing the XML layout file, however, for a DialogFragment these buttons don't exist in the layout file.
In essence, I'm trying to get access to the setPositiveButton, setNegativeButton and setNeutral buttons in order to modify them. Alternatively, I would next try to do this by getting them by id, however, since they aren't defined in a layout file, I do not have a corresponding id for them. I've found plenty examples of how to modify the rest of the layout, but I can't find anywhere that positive/neutral/negative buttons are modifiable.
Ideally, I could do this in the following block of code:
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
...
}
})
Thanks in advance.
Here is the code ... The button instance is valid only after the dialog created. Hope this helps you.
public static class CustomDialog extends DialogFragment
{
public static CustomDialog newInstance()
{
return new CustomDialog();
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
super.onCreateDialog(savedInstanceState);
Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog dialog = builder.create();
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCEL",new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
return dialog;
}
#Override
public void onStart()
{
super.onStart();
Button pButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
Button nButton = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE);
pButton.setBackgroundColor(getResources().getColor(R.color.Blue));
nButton.setBackgroundColor(getResources().getColor(R.color.Green));
}
}

NullPointer on MenuItem when loading controller

Ok, I'm having trouble making a Menu with Menu Items.
I was following this tutorial ( http://docs.oracle.com/javafx/2/ui_controls/menu_controls.htm ), but when I run it I get a nullpointer error. My code looks like this:
#Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
ventas.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
FXMLLoader ventasloader;
ventasloader = new FXMLLoader(getClass().getResource("VentasGUI.fxml"));
Stage ventasstage = new Stage();
AnchorPane ventas = null;
try {
ventas = (AnchorPane) ventasloader.load();
} catch (IOException ex) {
Logger.getLogger(PuntoDeVentaController.class.getName()).log(Level.SEVERE, null, ex);
}
Scene ventasscene = new Scene(ventas);
ventasstage.setScene(ventasscene);
ventasstage.setTitle("Venta");
VentasGUIController controller = ventasloader.<VentasGUIController>getController();
controller.setUser(userID);
ventasstage.show();
}
...but even when I leave just the skeleton code that NetBeans automatically adds:
#Override
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
ventas.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
throw new UnsupportedOperationException("Not supported yet.");
}
...rather than get the "Not supported yet" I get the nullpointerexception. I looked at the docs on http://docs.oracle.com/javafx/2/api/javafx/scene/control/MenuItem.html but I don't see that my event handler is empty, and it seems to be exactly the same as in the tutorial.
Anyone know what I'm doing wrong?
Thanks!
You haven't told where the NPE occurs so I guess here:
ventas.setOnAction(new EventHandler<ActionEvent>() {
Further I guess that ventas is a JavaFX control which you have defined in your .fxml file.
There are two things which have to be done that a connection between the .fxml file and the Java code works.
Annotate ventas with #FXML in your Java file
Define the fx:id of the ventas control in the SceneBuilder (set it to ventas)