Skip to content
Binary file added org.eclipse.babel.editor/icons/view_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*
*/
public interface IMessagesEditorChangeListener {

public static int SHOW_ALL = 0;
public static int SHOW_ONLY_MISSING_AND_UNUSED = 1;
public static int SHOW_ONLY_MISSING = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,80 @@
package org.eclipse.babel.editor.actions;

import org.eclipse.babel.editor.IMessagesEditorChangeListener;
import org.eclipse.babel.editor.internal.AbstractMessagesEditor;
import org.eclipse.babel.editor.internal.MessagesEditorChangeAdapter;
import org.eclipse.babel.editor.internal.MessagesEditorContributor;
import org.eclipse.babel.editor.tree.internal.OnlyUnsuedAndMissingKey;
import org.eclipse.babel.editor.util.BabelSharedImages;
import org.eclipse.babel.editor.util.IBabelSharedImages;
import org.eclipse.babel.editor.util.UIUtils;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreeViewer;

/**
*
* @author Hugues Malphettes
*/
public class FilterKeysAction extends Action {

private AbstractMessagesEditor editor;
private TreeViewer treeViewer;
private final int flagToSet;
private ChangeListener listener;

/**
* @param flagToSet
* The flag that will be set on unset
*/
public FilterKeysAction(int flagToSet) {
super("", IAction.AS_CHECK_BOX);
this(null, flagToSet);
}

/**
* @param treeViewer The TreeViewer to interact with
* @param flagToSet
* The flag that will be set on unset
*/
public FilterKeysAction(TreeViewer treeViewer, int flagToSet) {
super("", IAction.AS_RADIO_BUTTON);
this.treeViewer = treeViewer;
this.flagToSet = flagToSet;
listener = new ChangeListener();
update();
}

private class ChangeListener extends MessagesEditorChangeAdapter {
public void showOnlyUnusedAndMissingChanged(int hideEverythingElse) {
MessagesEditorContributor.FILTERS.updateActionBars();
}
}

/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
if (editor != null) {
if (editor.isShowOnlyUnusedAndMissingKeys() != flagToSet) {
editor.setShowOnlyUnusedMissingKeys(flagToSet);
// listener.showOnlyUnusedAndMissingChanged(flagToSet)

OnlyUnsuedAndMissingKey keyFilter = UIUtils.getFilter(this.treeViewer, OnlyUnsuedAndMissingKey.class);
if ( keyFilter != null ) {
if (keyFilter.isShowOnlyUnusedAndMissingKeys() != flagToSet) {
keyFilter.setShowOnlyUnusedMissingKeys(flagToSet);
} else {
editor.setShowOnlyUnusedMissingKeys(IMessagesEditorChangeListener.SHOW_ALL);
// listener.showOnlyUnusedAndMissingChanged(IMessagesEditorChangeListener.SHOW_ALL)
keyFilter.setShowOnlyUnusedMissingKeys(IMessagesEditorChangeListener.SHOW_ALL);
}
}
}
}

public void update() {
if (editor == null) {
super.setEnabled(false);
} else {
super.setEnabled(true);
}
super.setEnabled(this.treeViewer != null);

if (editor != null
&& editor.isShowOnlyUnusedAndMissingKeys() == flagToSet) {
setChecked(true);
} else {
setChecked(false);
boolean checked = false;
if (this.treeViewer != null) {
OnlyUnsuedAndMissingKey keyFilter = UIUtils.getFilter(this.treeViewer, OnlyUnsuedAndMissingKey.class);
checked = keyFilter != null && keyFilter.isShowOnlyUnusedAndMissingKeys() == flagToSet;
}

setChecked(checked);

setText(getTextInternal());
setToolTipText(getTooltipInternal());
setImageDescriptor(getImageDescriptor());

}

@Override
public ImageDescriptor getImageDescriptor() {
switch (flagToSet) {
case IMessagesEditorChangeListener.SHOW_ONLY_MISSING:
Expand All @@ -97,18 +99,6 @@ public ImageDescriptor getImageDescriptor() {
}
}

/*
* public String getImageKey() { switch (flagToSet) { case
* IMessagesEditorChangeListener.SHOW_ONLY_MISSING: return
* UIUtils.IMAGE_MISSING_TRANSLATION; case
* IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED: return
* UIUtils.IMAGE_UNUSED_AND_MISSING_TRANSLATIONS; case
* IMessagesEditorChangeListener.SHOW_ONLY_UNUSED: return
* UIUtils.IMAGE_UNUSED_TRANSLATION; case
* IMessagesEditorChangeListener.SHOW_ALL: default: return
* UIUtils.IMAGE_KEY; } }
*/

public String getTextInternal() {
switch (flagToSet) {
case IMessagesEditorChangeListener.SHOW_ONLY_MISSING:
Expand All @@ -125,34 +115,5 @@ public String getTextInternal() {

private String getTooltipInternal() {
return getTextInternal();
// if (editor == null) {
// return "no active editor";
// }
// switch (editor.isShowOnlyUnusedAndMissingKeys()) {
// case IMessagesEditorChangeListener.SHOW_ONLY_MISSING:
// return "Showing only keys with missing translation";
// case IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED:
// return "Showing only keys with missing or unused translation";
// case IMessagesEditorChangeListener.SHOW_ONLY_UNUSED:
// return "Showing only keys with missing translation";
// case IMessagesEditorChangeListener.SHOW_ALL:
// default:
// return "Showing all keys";
// }
}

public void setEditor(AbstractMessagesEditor editor) {
if (editor == this.editor) {
return;// no change
}
if (this.editor != null) {
this.editor.removeChangeListener(listener);
}
this.editor = editor;
update();
if (editor != null) {
editor.addChangeListener(listener);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package org.eclipse.babel.editor.actions;

import org.eclipse.babel.editor.i18n.I18NPage;
import org.eclipse.babel.editor.internal.AbstractMessagesEditor;
import org.eclipse.babel.editor.internal.MessagesEditorChangeAdapter;
import org.eclipse.babel.editor.util.BabelSharedImages;
Expand All @@ -28,33 +29,35 @@ public class KeyTreeVisibleAction extends Action {
/**
*
*/
public KeyTreeVisibleAction() {
public KeyTreeVisibleAction(AbstractMessagesEditor editor) {
super("Show/Hide Key Tree", IAction.AS_CHECK_BOX);
// setText();
this.editor = editor;
setToolTipText("Show/hide the key tree");
setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_VIEW_LEFT));
}
if (this.editor != null) {
editor.addChangeListener(new MessagesEditorChangeAdapter() {
public void keyTreeVisibleChanged(boolean visible) {
setChecked(visible);
}
});

// TODO RBEditor hold such an action registry. Then move this method to
// constructor
public void setEditor(AbstractMessagesEditor editor) {
this.editor = editor;
editor.addChangeListener(new MessagesEditorChangeAdapter() {
public void keyTreeVisibleChanged(boolean visible) {
setChecked(visible);
}
});
setChecked(editor.getI18NPage().isKeyTreeVisible());
}
boolean keyTreeVisible = true;
I18NPage i18nPage = editor.getI18NPage();
if (i18nPage != null) {
keyTreeVisible = i18nPage.isKeyTreeVisible();
}

setChecked(keyTreeVisible);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
editor.getI18NPage().setKeyTreeVisible(
!editor.getI18NPage().isKeyTreeVisible());
this.editor.getI18NPage().setKeyTreeVisible(!this.editor.getI18NPage().isKeyTreeVisible());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ public class NewLocaleAction extends Action {
private AbstractMessagesEditor editor;

/**
* @param editor2
*
*/
public NewLocaleAction() {
public NewLocaleAction(AbstractMessagesEditor editor) {
super("New &Locale...");
this.editor = editor;
setToolTipText("Add a new locale to the resource bundle.");
setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_NEW_PROPERTIES_FILE));
}

// TODO RBEditor hold such an action registry. Then move this method to
// constructor
public void setEditor(AbstractMessagesEditor editor) {
this.editor = editor;
}

/*
* (non-Javadoc)
*
Expand Down
Loading