I have an xml file in my RCP application. I am displaying it to user using FormEditor.
public class MyFormEditor extends FormEditor implements IResourceChangeListener{
public MyFormEditor(){
ResourcePlugin.getWorkspace.addResourceChangeListener(this);
...
}
#Override
public void resourceChanged(IResourceChangeEvent event){
int type = event.getType();
switch(type){
IResourceChangeEvent.PRE_DELETE:
IResourceChangeEvent.PRE_CLOSE:
this.close(true);
break;
IResourceChangeEvent.POST_CHANGE:
System.out.println("Resource is change.");
break;
default:
break;
}
}
#Override
public void dispose(){
ResourcePlugin.getWorkspace.removeResourceChangeListener(this);
super.dispose();
}
}
IResourceChange.POST_CHANGE event gets triggered when I save resource or I update the resource from SVN repository.
Under IResourceChange.POST_CHANGE how to determine resource is updated from SVN?
I tried following thing but it didn't work for me.
IResourceDelta delta = event.getDelta;
int flags = delta.getFlags();
boolean sync = (flags & IResourceDelta.SYNC) != 0;
if(sync){
System.out.println("Resource updated from server.");
}
Do let me know if you need any other info.
Related
I don't know why i have tow errors one at ClickListener() and ShowListener()? I am trying to like OnItemClickListener but for MeowBottomNavigation
getSupportActionBar().hide();
bottomNavigation =findViewById(R.id.bottomNavigation);
bottomNavigation.add(new MeowBottomNavigation.Model(1, R.drawable.ic_baseline_message));
bottomNavigation.add(new MeowBottomNavigation.Model(2, R.drawable.ic_settings));
bottomNavigation.add(newMeowBottomNavigation.Model(3,R.drawable.ic_baseline_account_circle_24));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new FragmentChatt()).commit();
bottomNavigation.setOnClickMenuListener(new MeowBottomNavigation.**ClickListener()** {
public void onClickItem(MeowBottomNavigation.Model item) {
//Toast.makeText(getApplicationContext(),"Clicked item"+item.getId(),Toast.LENGTH_SHORT).show();
}
});
bottomNavigation.setOnShowListener(new MeowBottomNavigation.**ShowListener()** {
public void onShowItem(MeowBottomNavigation.Model item) {
Fragment select_fragment=null;
switch (item.getId()){
case ID_CHAT:
select_fragment=new FragmentChatt();
break;
case ID_SETTINGS:
select_fragment=new FragmentSettengs();
break;
case ID_ACOUNT:
select_fragment=new FragmentAcount();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,select_fragment).commit();
}
});
}
}
I know this is an old post now, but for anyone who's still having the same problem check your module implementation in build.gradle file.
Here's the a dependency that worked for me:
dependencies {
implementation 'com.etebarian:meow-bottom-navigation-java:1.2.0'
}
You can also check their github:
Documentation
But that is a deprecated solution, so here's the new one they recommend New Documentation.
If you want to use the new solution, you need to implement the dependency:
dependencies {
implementation 'com.etebarian:meow-bottom-navigation:1.3.1'
}
And change the setOnShowListener and setOnClickMenuListener methods with:
bottomNavigation.setOnClickMenuListener(new Function1<MeowBottomNavigation.Model, Unit>() {
#Override
public Unit invoke(MeowBottomNavigation.Model model) {
// YOUR CODES
return null;
}
});
bottomNavigation.setOnShowListener(new Function1<MeowBottomNavigation.Model, Unit>() {
#Override
public Unit invoke(MeowBottomNavigation.Model model) {
// YOUR CODES
return null;
}
});
Basically the idea is that I need some sort of session/cookie imitation for Java. I have to develop some kind of a blogging program for a university project. It does not have to be for Web, I mean that I don't need servlet's and other Java EE stuff. The whole interface has to be in the console.
So here is the problem, I've developed a Menu class in which I add a MenuItem object for every menu option I want to be added, after I navigate my menu and I want to log into my account, I need something like a session, otherwise I cannot hide the "Login" and "Register" options, and can't decide whether to show the "Logout" option. Since the Menu class is instantiated only once, there is no way it could be updated on the go(or at least I think so, still learning Java).
If there is someone who can give me an advice or an idea, that would help me a lot.
Here is the Menu class:
package my.app;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import my.toolbox.InputHandler;
public class Menu extends MenuItem {
protected SessionImitator SESSION = SessionImitator.getInstance();
protected String title;
private static final String OUT_OF_RANGE = "Please select an option within the range";
private static final MenuItem SEPARATOR = new MenuItem("---------------------");
private static final MenuItem BACK = new MenuItem("Go Back");
private static final MenuItem EXIT = new MenuItem("Exit", new Runnable() {
public void run() {
System.exit(0);
}
});
List<MenuItem> items;
public Menu(String title, MenuItem ... items) {
this(title, false, true, items);
}
public Menu(String title, boolean addBack, boolean addExit, MenuItem ... items) {
super(title);
setExecutable(this);
init(addBack, addExit, items);
}
private void init(boolean addBack, boolean addExit, MenuItem ... items) {
this.items = new ArrayList<MenuItem>(Arrays.asList());
for (MenuItem item : items) {
if (item.isSessionDependent()) {
if (!item.getSessionAction() && SESSION.isSet()) {
continue;
}
}
this.items.add(item);
}
if (SESSION.isSet()) {
System.out.println("THIS PART DOES NOT WORK SINCE THE OBJECT IT's NOT UPDATED AFTER THE SESSION IS SET!");
}
if (addBack) this.items.add(BACK);
if (addExit) this.items.add(EXIT);
}
private void display() {
int option = 0;
System.out.println(SEPARATOR.getTitle());
System.out.println(getTitle() + ":");
System.out.println(SEPARATOR.getTitle());
for (MenuItem item : items) {
System.out.println((option++) + ": " + item.getTitle());
}
System.out.println(SEPARATOR.getTitle());
System.out.println("select an option: ");
System.out.flush();
}
private MenuItem prompt() {
display();
int option = InputHandler.readInt();
if (option >= 0 && option < items.size()) {
return items.get(option);
}
System.out.println(OUT_OF_RANGE);
return null;
}
public void run() {
try {
for (MenuItem item = prompt(); item.isExecutable(); item = prompt()) {
item.run();
}
} catch (Throwable t) {
t.printStackTrace(System.out);
}
}
}
The MenuItem class:
package my.app;
public class MenuItem implements Runnable {
private String title;
private Runnable executable;
private boolean sessionDependent;
private boolean sessionAction;
protected MenuItem(String title) {
this(title, null, false, false);
}
protected MenuItem(String title, boolean sessionDependent, boolean sessionAction) {
this(title, null, sessionDependent, sessionAction);
}
protected MenuItem(String title, Runnable executable) {
this(title, executable, false, false);
}
public MenuItem(String title, Runnable executable, boolean sessionDependent, boolean sessionAction) {
this.title = title;
this.executable = executable;
this.sessionDependent = sessionDependent;
this.sessionAction = sessionAction;
}
public void run() {
try {
executable.run();
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
public boolean isExecutable() {
return executable != null;
}
protected void setExecutable(Runnable executable) {
this.executable = executable;
}
public String getTitle() {
return title;
}
public boolean isSessionDependent() {
return sessionDependent;
}
public boolean getSessionAction() {
return sessionAction;
}
}
And the SessionImitator class:
package my.app;
public class SessionImitator {
private static SessionImitator instance = null;
protected int userId;
protected boolean locked = false;
protected SessionImitator() {
}
public static SessionImitator getInstance() {
if (instance == null) {
instance = new SessionImitator();
}
return instance;
}
public int getUserId() {
return userId;
}
public void setUserId(String id) {
if (!locked) {
this.userId = Integer.parseInt(id);
}
}
public boolean isSet() {
return locked;
}
}
What you are describing seems like you want to save a "state" of the program. But specifically of the state of the menu.
A simple implementation is to make your menu serializable, then save the serialized menu object to a file and reload it on login, if the file exists.
The above example would work for a user on a computer. If you wanted to persist across networks, etc. You might want to write the serialized object to a blob in a db table and then load it from there.
If your program is standalone, what you need is a container to hold current state of the application. There are different ways to obtain that:
a singleton: a dedicated class stores the state in its attributes and has a static member of its own class. That way you can get access to the state with code like State state = State.getInstance() - that is what your SessionImitator currently is.
a simple object injected in all other classes that could need it. A way to build that is to create an instance of a class holding state and pass it (for example in constructor) of other classes:
State state = new State();
...
Menu menu = new Menu(state);
a dependancy injection framework like Spring or Guice. It can help you to use the injection pattern but is really worthy when you have complex dependencies.
I want to make some processing every time when a particular DataObject is saved. If I understand NetBeans IDE API correctly, there is an Savable interface that can be used to implement saving options for custom editors. The problem here is that I do not want to implement my own editor, nor DataObject. I have a MIME type that is edited by a default Gsf editor (the common scripting language api) and has a GsfDataObject (I expect with the DOSavable). I want to keep all that way, just to add a hook, maybe a callback method or something, that would be called every time a save is done upon a given GsfDataObject (and I want a default save action be called, I dont want to override it).
So far I came to this simple solution but it seems ugly (it is more or less inspired by http://wiki.netbeans.org/DevFaqListenForSaveEvents ):
// I have a FileObject fobj
final DataObject dobj = DataObject.find(fobj);
dobj.addPropertyChangeListener(new PropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(DataObject.PROP_MODIFIED)) {
if (!((Boolean) evt.getOldValue()) & ((Boolean) evt.getNewValue())) {
System.out.println(">>>> here it gets modified");
} else {
System.out.println(">>>> here the data object gets saved");
}
}
}
});
However, this is not called only when the save is done, but also when the file gets modified, but then the modifications are reverted by Ctrl + Z. It only checks whether the data object changes its state from modified to unmodified. Is there a way to hook to a save event only?
P.S.: I tried to call new SJDOSavable(dobj).add(); in the moment when the DataObject gets modified and then to remove it in the other branch. However, the handleSave method does not get called. SJDOSavable class is a simple Savable implemented according to DOSavable from the DataSystems API:
private static final class SJDOSavable extends AbstractSavable implements Icon {
final DataObject obj;
public SJDOSavable(DataObject obj) {
this.obj = obj;
}
#Override
public String findDisplayName() {
return obj.getNodeDelegate().getDisplayName();
}
#Override
protected void handleSave() throws IOException {
System.out.println(">>>>> but this does not get called");
}
#Override
public boolean equals(Object other) {
if (other instanceof SJDOSavable) {
SJDOSavable dos = (SJDOSavable) other;
return obj.equals(dos.obj);
}
return false;
}
#Override
public int hashCode() {
return obj.hashCode();
}
final void remove() {
unregister();
}
final void add() {
register();
}
#Override
public void paintIcon(Component c, Graphics g, int x, int y) {
icon().paintIcon(c, g, x, y);
}
#Override
public int getIconWidth() {
return icon().getIconWidth();
}
#Override
public int getIconHeight() {
return icon().getIconHeight();
}
private Icon icon() {
return ImageUtilities.image2Icon(obj.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16));
}
}
Did you try this ?
http://wiki.netbeans.org/DevFaqListenForSaveEvents
Also if you want to listen to global Save events, it seems you can do that now.
https://netbeans.org/bugzilla/show_bug.cgi?id=140719
I'm working on a JavaFX application which will have several tab panes which I want to set to visible or hidden using check box which will send boolean flag to render or not to render the component.
Check box
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
Tab pane which will listen for the boolean property:
public boolean renderTab;
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
this.renderTab = renderTab;
}
tabPane.setVisible(renderTab);
The check box and the tab pane are isolated into different Java Classes. I need to send the value of the flag every time when I check or uncheck the flag. Can you tell me how I can send the flag using getter and setter?
EDIT
I tested this code:
final CheckMenuItem toolbarSubMenuNavigation = new CheckMenuItem("Navigation");
toolbarSubMenuNavigation.setOnAction(new EventHandler<ActionEvent>()
{
#Override
public void handle(ActionEvent e)
{
boolean dcd = toolbarSubMenuNavigation.isSelected();
DataTabs nn = new DataTabs();
nn.setRenderTab(dcd);
// call here the getter setter and send boolean flag
System.out.println("subsystem1 #1 Enabled!");
}
});
and
public boolean renderTab;
public boolean isRenderTab()
{
return renderTab;
}
public void setRenderTab(boolean renderTab)
{
this.renderTab = renderTab;
}
But it's not working when I switch the checkbox.
No.
Inorder to get that eithr you need to have a intance or you need to create new intance there.
If you create a new object there it will create a fresh intance,which doesnt helps you any more..
I guess the only way you have is to Make the renderTab as a static field and access there.
I currently have code to share a variable between two entry points in my application. The variable is the iconCount variable used to indicate how many notices the user has which is displayed on the home screen beside the icon. The way I've managed to do this is with a singleton and it (seems) to work fine at the moment. The issue is now that I do not want those notices to reset to zero when I completely turn off and turn on the phone. Should there be 7 notifications, I want there to be 7 notifications even after a device restart. For this I apparently need a persistent store integration which I've researched for a while.
So far my code for the bare singleton is:
public class MyAppIndicator{
public ApplicationIndicator _indicator;
public static MyAppIndicator _instance;
MyAppIndicator () {
setupIndicator();
}
public static MyAppIndicator getInstance() {
if (_instance == null) {
_instance = new MyAppIndicator ();
}
return(_instance);
}
public void setupIndicator() {
//Setup notification
if (_indicator == null) {
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
_indicator = reg.getApplicationIndicator();
if(_indicator == null) {
ApplicationIcon icon = new ApplicationIcon(EncodedImage.getEncodedImageResource ("notificationsdemo_jde.png"));
_indicator = reg.register(icon, false, true);
_indicator.setValue(0);
_indicator.setVisible(false);
}
}
}
public void setVisible1(boolean visible, int count) {
if (_indicator != null) {
if (visible) {
_indicator.setVisible(true);
_indicator.setValue(count); //UserInterface.incrementCount()
} else {
_indicator.setVisible(false);
}
}
}
}
I have been using the blackberry tutorial to figure out how to implement the persistable storage: http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747
Now before I go any further I must stress I'm very new to java development so my coding might be completely wrong, but here is what I've tried to do:
public void setVisible1(boolean visible, int count) {
if (_indicator != null) {
if (visible) {
_indicator.setVisible(true);
_indicator.setValue(count); //UserInterface.incrementCount()
StoreInfo info = new StoreInfo();
info.incElement();
synchronized (persistentCount) {
//persistentCount.setContents(_data);
persistentCount.commit();
}
} else {
_indicator.setVisible(false);
}
}
}
static {
persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (persistentCount) {
if (persistentCount.getContents() == null) {
persistentCount.setContents(new Vector()); //don't know what to do with this?
persistentCount.commit();
}
}
}
private static final class StoreInfo implements Persistable{
private int iconCount;
public StoreInfo(){}
public int getElement(){
return (int)iconCount;
}
public void incElement(){
iconCount++; //persistently increment icon variable
}
public void resetElement(){
iconCount=0; //when user checks application
}
}
The code above doesn't work which I'd expect somehow because I'm having trouble implementing the persistent portion. If anyone has any idea or input on how to accomplish this any assistance would be helpful. And of course thanks in advance.
In the example they have a variable called _data that holds the StoreInfo class, so first of all you should be keeping the StoreInfo in some variable. To do this have something like the following in your static initializer:
persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (persistentCount) {
if (persistentCount.getContents() == null) {
persistentCount.setContents(new StoreInfo());
persistentCount.commit();
}
}
_data = (StoreInfo)persistentCount.getContents();
Now when you want to update it and save to the PersistentStore you can have something like:
_data.incElement();
synchronized(persistentCount) {
persistentCount.setContents(_data);
persistentCount.commit();
}
Assuming you're going to only ever have one instance of StoreInfo it could be better to put the commit code into the modifier methods so you don't forget to save the new values to the PersistentStore.