diff --git a/org.eclipse.babel.editor/icons/view_menu.png b/org.eclipse.babel.editor/icons/view_menu.png new file mode 100644 index 0000000..d8dc2f8 Binary files /dev/null and b/org.eclipse.babel.editor/icons/view_menu.png differ diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/IMessagesEditorChangeListener.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/IMessagesEditorChangeListener.java index 81e8b1f..5364f50 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/IMessagesEditorChangeListener.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/IMessagesEditorChangeListener.java @@ -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; diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/FilterKeysAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/FilterKeysAction.java index 65d834c..6249bbe 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/FilterKeysAction.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/FilterKeysAction.java @@ -11,14 +11,14 @@ 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; /** * @@ -26,63 +26,65 @@ */ 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: @@ -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: @@ -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); - } - } - } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/KeyTreeVisibleAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/KeyTreeVisibleAction.java index eed9c27..f67570f 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/KeyTreeVisibleAction.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/KeyTreeVisibleAction.java @@ -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; @@ -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()); } } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/NewLocaleAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/NewLocaleAction.java index 317da4c..c0527b4 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/NewLocaleAction.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/actions/NewLocaleAction.java @@ -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) * diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/AbstractI18NEntry.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/AbstractI18NEntry.java index 38b2bc5..65a9fe1 100755 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/AbstractI18NEntry.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/AbstractI18NEntry.java @@ -18,30 +18,28 @@ import org.eclipse.babel.core.message.IMessagesBundle; import org.eclipse.babel.core.message.IMessagesBundleGroup; import org.eclipse.babel.core.message.internal.Message; -import org.eclipse.babel.core.message.manager.RBManager; import org.eclipse.babel.core.util.BabelUtils; 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.plugin.MessagesEditorPlugin; import org.eclipse.babel.editor.util.UIUtils; import org.eclipse.babel.editor.widgets.NullableText; -import org.eclipse.jface.bindings.keys.IKeyLookup; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CBanner; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.TraverseEvent; import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; /** * Tree for displaying and navigating through resource bundle keys. @@ -55,18 +53,19 @@ public abstract class AbstractI18NEntry extends Composite { private final String projectName; protected final Locale locale; - private boolean expanded = true; protected NullableText textBox; - private CBanner banner; protected String focusGainedText; public static final String INSTANCE_CLASS = "org.eclipse.babel.editor.i18n.I18NEntry"; private IMessagesEditorChangeListener msgEditorUpdateKey = new MessagesEditorChangeAdapter() { + @Override public void selectedKeyChanged(String oldKey, String newKey) { updateKey(newKey); } }; + private FormToolkit toolkit; + private Section section; /** * Constructor. @@ -79,38 +78,30 @@ public void selectedKeyChanged(String oldKey, String newKey) { public AbstractI18NEntry(Composite parent, final AbstractMessagesEditor editor, final Locale locale) { super(parent, SWT.NONE); + this.setLayout(new FillLayout()); + + this.toolkit = new FormToolkit(this.getDisplay()); + this.section = this.toolkit.createSection(this, ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR ); + this.editor = editor; this.locale = locale; this.bundleGroupId = editor.getBundleGroup().getResourceBundleId(); this.projectName = editor.getBundleGroup().getProjectName(); - GridLayout gridLayout = new GridLayout(1, false); - gridLayout.horizontalSpacing = 0; - gridLayout.verticalSpacing = 0; - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - - setLayout(gridLayout); - GridData gd = new GridData(GridData.FILL_BOTH); - // gd.heightHint = 80; - setLayoutData(gd); - - banner = new CBanner(this, SWT.NONE); + String localeName = UIUtils.getDisplayName(this.getLocale()); + String title = localeName + (!isEditable() ? " (" + MessagesEditorPlugin.getString("editor.readOnly") + ")" : ""); - Control bannerLeft = new EntryLeftBanner(banner, this);// createBannerLeft(banner); - Control bannerRight = new EntryRightBanner(banner, this);// createBannerRight(banner); +// Control bannerLeft = new FormEntryLeftBanner(this.section, this);// createBannerLeft(banner); +// this.section.setTextClient(bannerLeft); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - - banner.setLeft(bannerLeft); - banner.setRight(bannerRight); - // banner.setRightWidth(300); - banner.setSimple(false); - banner.setLayoutData(gridData); + EntryRightBanner entryRightBanner = new EntryRightBanner(this.section, this); + this.section.setTextClient(entryRightBanner); + this.section.setText(title); createTextbox(); + this.section.setClient(this.textBox); + this.section.setLayoutData( new GridData(GridData.FILL_BOTH)); + } @@ -118,47 +109,6 @@ public AbstractMessagesEditor getResourceBundleEditor() { return editor; } - public void setExpanded(boolean expanded) { - this.expanded = expanded; - textBox.setVisible(expanded); - - if (expanded) { - GridData gridData = new GridData(); - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - gridData.heightHint = UIUtils.getHeightInChars(textBox, 3); - textBox.setLayoutData(gridData); - - GridData gd = new GridData(GridData.FILL_BOTH); - // gd.heightHint = 80; - setLayoutData(gd); - getParent().pack(); - getParent().layout(true, true); - - } else { - GridData gridData = ((GridData) textBox.getLayoutData()); - gridData.verticalAlignment = GridData.BEGINNING; - gridData.grabExcessVerticalSpace = false; - textBox.setLayoutData(gridData); - - gridData = (GridData) getLayoutData(); - gridData.heightHint = banner.getSize().y; - gridData.verticalAlignment = GridData.BEGINNING; - gridData.grabExcessVerticalSpace = false; - setLayoutData(gridData); - - getParent().pack(); - getParent().layout(true, true); - } - - } - - public boolean getExpanded() { - return expanded; - } - public Locale getLocale() { return locale; } @@ -184,7 +134,7 @@ public String getResourceLocationLabel() { * @param locale */ private void createTextbox() { - textBox = new NullableText(this, SWT.MULTI | SWT.WRAP | SWT.H_SCROLL + textBox = new NullableText(this.section, SWT.MULTI | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, locale); textBox.setEnabled(false); textBox.setOrientation(UIUtils.getOrientation(locale)); @@ -227,6 +177,8 @@ public void modifyText(ModifyEvent e) { } }); + textBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + editor.addChangeListener(msgEditorUpdateKey); } @@ -269,548 +221,3 @@ public void dispose() { } } - -// TODO Grab and Apply font fix: -// /** -// * Represents a data entry section for a bundle entry. -// * @author Pascal Essiembre (essiembre@users.sourceforge.net) -// * @version $Author: pessiembr $ $Revision: 1.3 $ $Date: 2008/01/11 04:15:15 $ -// */ -// public class BundleEntryComposite extends Composite { -// -// /*default*/ final ResourceManager resourceManager; -// /*default*/ final Locale locale; -// private final Font boldFont; -// private final Font smallFont; -// -// /*default*/ Text textBox; -// private Button commentedCheckbox; -// private Button gotoButton; -// private Button duplButton; -// private Button simButton; -// -// /*default*/ String activeKey; -// /*default*/ String textBeforeUpdate; -// -// /*default*/ DuplicateValuesVisitor duplVisitor; -// /*default*/ SimilarValuesVisitor similarVisitor; -// -// -// /** -// * Constructor. -// * @param parent parent composite -// * @param resourceManager resource manager -// * @param locale locale for this bundle entry -// */ -// public BundleEntryComposite( -// final Composite parent, -// final ResourceManager resourceManager, -// final Locale locale) { -// -// super(parent, SWT.NONE); -// this.resourceManager = resourceManager; -// this.locale = locale; -// -// this.boldFont = UIUtils.createFont(this, SWT.BOLD, 0); -// this.smallFont = UIUtils.createFont(SWT.NONE, -1); -// -// GridLayout gridLayout = new GridLayout(1, false); -// gridLayout.horizontalSpacing = 0; -// gridLayout.verticalSpacing = 2; -// gridLayout.marginWidth = 0; -// gridLayout.marginHeight = 0; -// -// createLabelRow(); -// createTextRow(); -// -// setLayout(gridLayout); -// GridData gd = new GridData(GridData.FILL_BOTH); -// gd.heightHint = 80; -// setLayoutData(gd); -// -// -// } -// -// /** -// * Update bundles if the value of the active key changed. -// */ -// public void updateBundleOnChanges(){ -// if (activeKey != null) { -// MessagesBundleGroup messagesBundleGroup = resourceManager.getBundleGroup(); -// Message entry = messagesBundleGroup.getBundleEntry(locale, activeKey); -// boolean commentedSelected = commentedCheckbox.getSelection(); -// String textBoxValue = textBox.getText(); -// -// if (entry == null || !textBoxValue.equals(entry.getValue()) -// || entry.isCommented() != commentedSelected) { -// String comment = null; -// if (entry != null) { -// comment = entry.getComment(); -// } -// messagesBundleGroup.addBundleEntry(locale, new Message( -// activeKey, -// textBox.getText(), -// comment, -// commentedSelected)); -// } -// } -// } -// -// /** -// * @see org.eclipse.swt.widgets.Widget#dispose() -// */ -// public void dispose() { -// super.dispose(); -// boldFont.dispose(); -// smallFont.dispose(); -// -// //Addition by Eric Fettweis -// for(Iterator it = swtFontCache.values().iterator();it.hasNext();){ -// Font font = (Font) it.next(); -// font.dispose(); -// } -// swtFontCache.clear(); -// } -// -// /** -// * Gets the locale associated with this bundle entry -// * @return a locale -// */ -// public Locale getLocale() { -// return locale; -// } -// -// /** -// * Sets a selection in the text box. -// * @param start starting position to select -// * @param end ending position to select -// */ -// public void setTextSelection(int start, int end) { -// textBox.setSelection(start, end); -// } -// -// /** -// * Refreshes the text field value with value matching given key. -// * @param key key used to grab value -// */ -// public void refresh(String key) { -// activeKey = key; -// MessagesBundleGroup messagesBundleGroup = resourceManager.getBundleGroup(); -// if (key != null && messagesBundleGroup.isKey(key)) { -// Message bundleEntry = messagesBundleGroup.getBundleEntry(locale, key); -// SourceEditor sourceEditor = resourceManager.getSourceEditor(locale); -// if (bundleEntry == null) { -// textBox.setText(""); //$NON-NLS-1$ -// commentedCheckbox.setSelection(false); -// } else { -// commentedCheckbox.setSelection(bundleEntry.isCommented()); -// String value = bundleEntry.getValue(); -// textBox.setText(value); -// } -// commentedCheckbox.setEnabled(!sourceEditor.isReadOnly()); -// textBox.setEnabled(!sourceEditor.isReadOnly()); -// gotoButton.setEnabled(true); -// if (MsgEditorPreferences.getReportDuplicateValues()) { -// findDuplicates(bundleEntry); -// } else { -// duplVisitor = null; -// } -// if (MsgEditorPreferences.getReportSimilarValues()) { -// findSimilar(bundleEntry); -// } else { -// similarVisitor = null; -// } -// } else { -// commentedCheckbox.setSelection(false); -// commentedCheckbox.setEnabled(false); -// textBox.setText(""); //$NON-NLS-1$ -// textBox.setEnabled(false); -// gotoButton.setEnabled(false); -// duplButton.setVisible(false); -// simButton.setVisible(false); -// } -// resetCommented(); -// } -// -// private void findSimilar(Message bundleEntry) { -// ProximityAnalyzer analyzer; -// if (MsgEditorPreferences.getReportSimilarValuesLevensthein()) { -// analyzer = LevenshteinDistanceAnalyzer.getInstance(); -// } else { -// analyzer = WordCountAnalyzer.getInstance(); -// } -// MessagesBundleGroup messagesBundleGroup = resourceManager.getBundleGroup(); -// if (similarVisitor == null) { -// similarVisitor = new SimilarValuesVisitor(); -// } -// similarVisitor.setProximityAnalyzer(analyzer); -// similarVisitor.clear(); -// messagesBundleGroup.getBundle(locale).accept(similarVisitor, bundleEntry); -// if (duplVisitor != null) { -// similarVisitor.getSimilars().removeAll(duplVisitor.getDuplicates()); -// } -// simButton.setVisible(similarVisitor.getSimilars().size() > 0); -// } -// -// private void findDuplicates(Message bundleEntry) { -// MessagesBundleGroup messagesBundleGroup = resourceManager.getBundleGroup(); -// if (duplVisitor == null) { -// duplVisitor = new DuplicateValuesVisitor(); -// } -// duplVisitor.clear(); -// messagesBundleGroup.getBundle(locale).accept(duplVisitor, bundleEntry); -// duplButton.setVisible(duplVisitor.getDuplicates().size() > 0); -// } -// -// -// /** -// * Creates the text field label, icon, and commented check box. -// */ -// private void createLabelRow() { -// Composite labelComposite = new Composite(this, SWT.NONE); -// GridLayout gridLayout = new GridLayout(); -// gridLayout.numColumns = 6; -// gridLayout.horizontalSpacing = 5; -// gridLayout.verticalSpacing = 0; -// gridLayout.marginWidth = 0; -// gridLayout.marginHeight = 0; -// labelComposite.setLayout(gridLayout); -// labelComposite.setLayoutData( -// new GridData(GridData.FILL_HORIZONTAL)); -// -// // Locale text -// Label txtLabel = new Label(labelComposite, SWT.NONE); -// txtLabel.setText(" " + //$NON-NLS-1$ -// UIUtils.getDisplayName(locale) + " "); //$NON-NLS-1$ -// txtLabel.setFont(boldFont); -// GridData gridData = new GridData(); -// -// // Similar button -// gridData = new GridData(); -// gridData.horizontalAlignment = GridData.END; -// gridData.grabExcessHorizontalSpace = true; -// simButton = new Button(labelComposite, SWT.PUSH | SWT.FLAT); -// simButton.setImage(UIUtils.getImage("similar.gif")); //$NON-NLS-1$ -// simButton.setLayoutData(gridData); -// simButton.setVisible(false); -// simButton.setToolTipText( -// RBEPlugin.getString("value.similar.tooltip")); //$NON-NLS-1$ -// simButton.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent event) { -// String head = RBEPlugin.getString( -// "dialog.similar.head"); //$NON-NLS-1$ -// String body = RBEPlugin.getString( -// "dialog.similar.body", activeKey, //$NON-NLS-1$ -// UIUtils.getDisplayName(locale)); -// body += "\n\n"; //$NON-NLS-1$ -// for (Iterator iter = similarVisitor.getSimilars().iterator(); -// iter.hasNext();) { -// body += " " //$NON-NLS-1$ -// + ((Message) iter.next()).getKey() -// + "\n"; //$NON-NLS-1$ -// } -// MessageDialog.openInformation(getShell(), head, body); -// } -// }); -// -// // Duplicate button -// gridData = new GridData(); -// gridData.horizontalAlignment = GridData.END; -// duplButton = new Button(labelComposite, SWT.PUSH | SWT.FLAT); -// duplButton.setImage(UIUtils.getImage("duplicate.gif")); //$NON-NLS-1$ -// duplButton.setLayoutData(gridData); -// duplButton.setVisible(false); -// duplButton.setToolTipText( -// RBEPlugin.getString("value.duplicate.tooltip")); //$NON-NLS-1$ -// -// duplButton.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent event) { -// String head = RBEPlugin.getString( -// "dialog.identical.head"); //$NON-NLS-1$ -// String body = RBEPlugin.getString( -// "dialog.identical.body", activeKey, //$NON-NLS-1$ -// UIUtils.getDisplayName(locale)); -// body += "\n\n"; //$NON-NLS-1$ -// for (Iterator iter = duplVisitor.getDuplicates().iterator(); -// iter.hasNext();) { -// body += " " //$NON-NLS-1$ -// + ((Message) iter.next()).getKey() -// + "\n"; //$NON-NLS-1$ -// } -// MessageDialog.openInformation(getShell(), head, body); -// } -// }); -// -// // Commented checkbox -// gridData = new GridData(); -// gridData.horizontalAlignment = GridData.END; -// //gridData.grabExcessHorizontalSpace = true; -// commentedCheckbox = new Button( -// labelComposite, SWT.CHECK); -// commentedCheckbox.setText("#"); //$NON-NLS-1$ -// commentedCheckbox.setFont(smallFont); -// commentedCheckbox.setLayoutData(gridData); -// commentedCheckbox.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent event) { -// resetCommented(); -// updateBundleOnChanges(); -// } -// }); -// commentedCheckbox.setEnabled(false); -// -// // Country flag -// gridData = new GridData(); -// gridData.horizontalAlignment = GridData.END; -// Label imgLabel = new Label(labelComposite, SWT.NONE); -// imgLabel.setLayoutData(gridData); -// imgLabel.setImage(loadCountryIcon(locale)); -// -// // Goto button -// gridData = new GridData(); -// gridData.horizontalAlignment = GridData.END; -// gotoButton = new Button( -// labelComposite, SWT.ARROW | SWT.RIGHT); -// gotoButton.setToolTipText( -// RBEPlugin.getString("value.goto.tooltip")); //$NON-NLS-1$ -// gotoButton.setEnabled(false); -// gotoButton.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent event) { -// ITextEditor editor = resourceManager.getSourceEditor( -// locale).getEditor(); -// Object activeEditor = -// editor.getSite().getPage().getActiveEditor(); -// if (activeEditor instanceof MessagesEditor) { -// ((MessagesEditor) activeEditor).setActivePage(locale); -// } -// } -// }); -// gotoButton.setLayoutData(gridData); -// } -// /** -// * Creates the text row. -// */ -// private void createTextRow() { -// textBox = new Text(this, SWT.MULTI | SWT.WRAP | -// SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); -// textBox.setEnabled(false); -// //Addition by Eric FETTWEIS -// //Note that this does not seem to work... It would however be usefull for -// arabic and some other languages -// textBox.setOrientation(getOrientation(locale)); -// -// GridData gridData = new GridData(); -// gridData.verticalAlignment = GridData.FILL; -// gridData.grabExcessVerticalSpace = true; -// gridData.horizontalAlignment = GridData.FILL; -// gridData.grabExcessHorizontalSpace = true; -// gridData.heightHint = UIUtils.getHeightInChars(textBox, 3); -// textBox.setLayoutData(gridData); -// textBox.addFocusListener(new FocusListener() { -// public void focusGained(FocusEvent event) { -// textBeforeUpdate = textBox.getText(); -// } -// public void focusLost(FocusEvent event) { -// updateBundleOnChanges(); -// } -// }); -// //TODO add a preference property listener and add/remove this listener -// textBox.addTraverseListener(new TraverseListener() { -// public void keyTraversed(TraverseEvent event) { -// if (!MsgEditorPreferences.getFieldTabInserts() -// && event.character == SWT.TAB) { -// event.doit = true; -// } -// } -// }); -// textBox.addKeyListener(new KeyAdapter() { -// public void keyReleased(KeyEvent event) { -// Text eventBox = (Text) event.widget; -// final ITextEditor editor = resourceManager.getSourceEditor( -// locale).getEditor(); -// // Text field has changed: make editor dirty if not already -// if (textBeforeUpdate != null -// && !textBeforeUpdate.equals(eventBox.getText())) { -// // Make the editor dirty if not already. If it is, -// // we wait until field focus lost (or save) to -// // update it completely. -// if (!editor.isDirty()) { -// int caretPosition = eventBox.getCaretPosition(); -// updateBundleOnChanges(); -// eventBox.setSelection(caretPosition); -// } -// //autoDetectRequiredFont(eventBox.getText()); -// } -// } -// }); -// // Eric Fettweis : new listener to automatically change the font -// textBox.addModifyListener(new ModifyListener() { -// -// public void modifyText(ModifyEvent e) { -// String text = textBox.getText(); -// Font f = textBox.getFont(); -// String fontName = getBestFont(f.getFontData()[0].getName(), text); -// if(fontName!=null){ -// f = getSWTFont(f, fontName); -// textBox.setFont(f); -// } -// } -// -// }); -// } -// -// -// -// /*default*/ void resetCommented() { -// if (commentedCheckbox.getSelection()) { -// commentedCheckbox.setToolTipText( -// RBEPlugin.getString("value.uncomment.tooltip"));//$NON-NLS-1$ -// textBox.setForeground( -// getDisplay().getSystemColor(SWT.COLOR_GRAY)); -// } else { -// commentedCheckbox.setToolTipText( -// RBEPlugin.getString("value.comment.tooltip"));//$NON-NLS-1$ -// textBox.setForeground(null); -// } -// } -// -// -// -// /** Additions by Eric FETTWEIS */ -// /*private void autoDetectRequiredFont(String value) { -// Font f = getFont(); -// FontData[] data = f.getFontData(); -// boolean resetFont = true; -// for (int i = 0; i < data.length; i++) { -// java.awt.Font test = new java.awt.Font(data[i].getName(), -// java.awt.Font.PLAIN, 12); -// if(test.canDisplayUpTo(value)==-1){ -// resetFont = false; -// break; -// } -// } -// if(resetFont){ -// String[] fonts = -// GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); -// for (int i = 0; i < fonts.length; i++) { -// java.awt.Font fnt = new java.awt.Font(fonts[i],java.awt.Font.PLAIN,12); -// if(fnt.canDisplayUpTo(value)==-1){ -// textBox.setFont(createFont(fonts[i])); -// break; -// } -// } -// } -// }*/ -// /** -// * Holds swt fonts used for the textBox. -// */ -// private Map swtFontCache = new HashMap(); -// -// /** -// * Gets a font by its name. The resulting font is build based on the baseFont -// parameter. -// * The font is retrieved from the swtFontCache, or created if needed. -// * @param baseFont the current font used to build the new one. -// * Only the name of the new font will differ fromm the original one. -// * @parama baseFont a font -// * @param name the new font name -// * @return a font with the same style and size as the original. -// */ -// private Font getSWTFont(Font baseFont, String name){ -// Font font = (Font) swtFontCache.get(name); -// if(font==null){ -// font = createFont(baseFont, getDisplay(), name); -// swtFontCache.put(name, font); -// } -// return font; -// } -// /** -// * Gets the name of the font which will be the best to display a String. -// * All installed fonts are searched. If a font can display the entire string, -// then it is retuned immediately. -// * Otherwise, the font returned is the one which can display properly the -// longest substring possible from the argument value. -// * @param baseFontName a font to be tested before any other. It will be the -// current font used by a widget. -// * @param value the string to be displayed. -// * @return a font name -// */ -// private static String getBestFont(String baseFontName, String value){ -// if(canFullyDisplay(baseFontName, value)) return baseFontName; -// String[] fonts = -// GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); -// String fontName=null; -// int currentScore = 0; -// for (int i = 0; i < fonts.length; i++) { -// int score = canDisplayUpTo(fonts[i], value); -// if(score==-1){//no need to loop further -// fontName=fonts[i]; -// break; -// } -// if(score>currentScore){ -// fontName=fonts[i]; -// currentScore = score; -// } -// } -// -// return fontName; -// } -// -// /** -// * A cache holding an instance of every AWT font tested. -// */ -// private static Map awtFontCache = new HashMap(); -// -// /** -// * Creates a variation from an original font, by changing the face name. -// * @param baseFont the original font -// * @param display the current display -// * @param name the new font face name -// * @return a new Font -// */ -// private static Font createFont(Font baseFont, Display display, String name){ -// FontData[] fontData = baseFont.getFontData(); -// for (int i = 0; i < fontData.length; i++) { -// fontData[i].setName(name); -// } -// return new Font(display, fontData); -// } -// /** -// * Can a font display correctly an entire string ? -// * @param fontName the font name -// * @param value the string to be displayed -// * @return -// */ -// private static boolean canFullyDisplay(String fontName, String value){ -// return canDisplayUpTo(fontName, value)==-1; -// } -// -// /** -// * Test the number of characters from a given String that a font can display -// correctly. -// * @param fontName the name of the font -// * @param value the value to be displayed -// * @return the number of characters that can be displayed, or -1 if the entire -// string can be displayed successfuly. -// * @see java.aw.Font#canDisplayUpTo(String) -// */ -// private static int canDisplayUpTo(String fontName, String value){ -// java.awt.Font font = getAWTFont(fontName); -// return font.canDisplayUpTo(value); -// } -// /** -// * Returns a cached or new AWT font by its name. -// * If the font needs to be created, its style will be Font.PLAIN and its size -// will be 12. -// * @param name teh font name -// * @return an AWT Font -// */ -// private static java.awt.Font getAWTFont(String name){ -// java.awt.Font font = (java.awt.Font) awtFontCache.get(name); -// if(font==null){ -// font = new java.awt.Font(name, java.awt.Font.PLAIN, 12); -// awtFontCache.put(name, font); -// } -// return font; -// } - -// } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/EntryRightBanner.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/EntryRightBanner.java index 82ef73a..faa0fe7 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/EntryRightBanner.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/EntryRightBanner.java @@ -11,26 +11,17 @@ package org.eclipse.babel.editor.i18n; import java.util.Collection; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; import java.util.Observable; import java.util.Observer; -import org.eclipse.babel.core.message.checks.IMessageCheck; import org.eclipse.babel.core.message.checks.IMessageCheckResult; -import org.eclipse.babel.core.message.checks.internal.DuplicateValueCheck; -import org.eclipse.babel.core.message.checks.internal.DuplicateValueMessageCheckResult; -import org.eclipse.babel.core.message.checks.internal.MissingValueCheck; -import org.eclipse.babel.core.message.checks.internal.MissingValueCheckResult; import org.eclipse.babel.editor.IMessagesEditorChangeListener; -import org.eclipse.babel.editor.i18n.actions.ShowDuplicateAction; -import org.eclipse.babel.editor.i18n.actions.ShowMissingAction; import org.eclipse.babel.editor.internal.AbstractMessagesEditor; import org.eclipse.babel.editor.internal.MessagesEditorChangeAdapter; -import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; @@ -45,9 +36,8 @@ */ public class EntryRightBanner extends Composite { - private Label colon; private Label warningIcon; - private final Map actionByMarkerIds = new HashMap(); + private final ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT); private final AbstractMessagesEditor editor; private final AbstractI18NEntry i18nEntry; @@ -88,11 +78,27 @@ public EntryRightBanner(Composite parent, final AbstractI18NEntry i18nEntry) { warningIcon.setImage(PlatformUI.getWorkbench().getSharedImages() .getImage(ISharedImages.IMG_OBJS_WARN_TSK)); warningIcon.setVisible(false); - warningIcon.setToolTipText("This locale has warnings."); - colon = new Label(this, SWT.NONE); - colon.setText(":"); - colon.setVisible(false); + LocaleWarningToolTip myTooltipLabel = new LocaleWarningToolTip(warningIcon) { + + @Override + protected Composite createContentArea(Composite parent) { + Composite comp = new Composite( parent, SWT.NONE); + Object data = warningIcon.getData("markers"); + comp.setLayout(new RowLayout(SWT.VERTICAL)); + if (data instanceof Collection collection) { + Collection markers = (Collection) collection; + for ( IMessageCheckResult marker : markers) { + Label markerLabel = new Label(comp, SWT.NONE); + markerLabel.setText(marker.getText()); + } + } + return comp; + } + }; + myTooltipLabel.setShift(new Point(-5, -5)); + myTooltipLabel.setHideOnMouseDown(false); + myTooltipLabel.activate(); toolBarMgr.createControl(this); toolBarMgr.update(true); @@ -105,55 +111,25 @@ public EntryRightBanner(Composite parent, final AbstractI18NEntry i18nEntry) { * @param warningIcon * @param colon */ - private void updateMarkers() { - Display display = toolBarMgr.getControl().getDisplay(); - // [RAP] only update markers, which belong to this UIThread - if (display.equals(Display.getCurrent()) && !isDisposed()) { - display.asyncExec(new Runnable() { - public void run() { - if (isDisposed()) - return; - // if (!PlatformUI.getWorkbench().getDisplay().isDisposed() - // && !editor.getMarkerManager().isDisposed()) { - boolean isMarked = false; - toolBarMgr.removeAll(); - actionByMarkerIds.clear(); - String key = editor.getSelectedKey(); - Collection checks = editor.getMarkers() - .getFailedChecks(key, locale); - if (checks != null) { - for (IMessageCheckResult check : checks) { - Action action = getCheckAction(key, check); - if (action != null) { - toolBarMgr.add(action); - toolBarMgr.update(true); - getParent().layout(true, true); - isMarked = true; - } - } - } - toolBarMgr.update(true); - getParent().layout(true, true); - - warningIcon.setVisible(isMarked); - colon.setVisible(isMarked); - } - // } - }); - } + private void updateMarkers() { + Display display = toolBarMgr.getControl().getDisplay(); + // [RAP] only update markers, which belong to this UIThread + if (display.equals(Display.getCurrent()) && !isDisposed()) { + display.asyncExec(new Runnable() { + public void run() { + if (isDisposed()) { + return; + } - } + String key = editor.getSelectedKey(); + Collection checks = editor.getMarkers().getFailedChecks(key, locale); - private Action getCheckAction(String key, IMessageCheckResult check) { - if (check instanceof MissingValueCheckResult checkResult) { - return new ShowMissingAction(key, locale); - } else if (check instanceof DuplicateValueMessageCheckResult checkResult) { - return new ShowDuplicateAction( - checkResult.getDuplicateKeys(), key, - locale); - } - return null; - } + warningIcon.setVisible(checks != null && checks.size() > 0); + warningIcon.setData("markers", checks); + } + }); + } + } @Override public void dispose() { diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FilterDropDown.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FilterDropDown.java new file mode 100644 index 0000000..bfd0fb0 --- /dev/null +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FilterDropDown.java @@ -0,0 +1,82 @@ +package org.eclipse.babel.editor.i18n; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.babel.editor.IMessagesEditorChangeListener; +import org.eclipse.babel.editor.actions.FilterKeysAction; +import org.eclipse.babel.editor.internal.AbstractMessagesEditor; +import org.eclipse.babel.editor.util.BabelSharedImages; +import org.eclipse.babel.editor.util.IBabelSharedImages; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.ToolItem; + +public class FilterDropDown extends Action { + + private Menu fMenu; + private List actions = new ArrayList<>(); + private AbstractMessagesEditor editor; + private TreeViewer treeViewer; + + public FilterDropDown(AbstractMessagesEditor editor, TreeViewer treeViewer) { + super("Set filter", IAction.AS_PUSH_BUTTON); + this.editor = editor; + this.treeViewer = treeViewer; + setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_VIEW_MENU)); + actions = new ArrayList<>(); + createActions(); + } + + private void createActions() { + actions.add(new FilterKeysAction(this.treeViewer, IMessagesEditorChangeListener.SHOW_ALL)); + actions.add(new FilterKeysAction(this.treeViewer, IMessagesEditorChangeListener.SHOW_ONLY_MISSING)); + actions.add(new FilterKeysAction(this.treeViewer, IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED)); + actions.add(new FilterKeysAction(this.treeViewer, IMessagesEditorChangeListener.SHOW_ONLY_UNUSED)); + } + + @Override + public void runWithEvent(Event event) { + ToolItem toolItem = (ToolItem) event.widget; + + Menu localMenu = getMenu(toolItem.getParent().getShell()); + + // Show the menu + Rectangle ib = toolItem.getBounds(); + Point displayAt = toolItem.getParent().toDisplay(ib.x, ib.y + ib.height); + localMenu.setLocation(displayAt); + localMenu.setVisible(true); + } + + public void dispose() { + if (fMenu != null && !fMenu.isDisposed()) { + fMenu.dispose(); + } + } + + public Menu getMenu(Control parent) { + if (fMenu != null && !fMenu.isDisposed()) { + fMenu.dispose(); + } + + fMenu = new Menu(parent); + for (IAction action : actions) { + addActionToMenu(fMenu, action); + } + return fMenu; + } + + protected void addActionToMenu(Menu parent, IAction action) { + ActionContributionItem item = new ActionContributionItem(action); + item.fill(parent, -1); + } + + +} \ No newline at end of file diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FormEntryLeftBanner.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FormEntryLeftBanner.java new file mode 100644 index 0000000..d7763ca --- /dev/null +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/FormEntryLeftBanner.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2007 Pascal Essiembre. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pascal Essiembre - initial API and implementation + ******************************************************************************/ +package org.eclipse.babel.editor.i18n; + +import java.util.Locale; + +import org.eclipse.babel.editor.i18n.actions.FoldingAction; +import org.eclipse.babel.editor.plugin.MessagesEditorPlugin; +import org.eclipse.babel.editor.util.LocaleImageUtil; +import org.eclipse.babel.editor.util.UIUtils; +import org.eclipse.babel.editor.widgets.ActionButton; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; + +/** + * Tree for displaying and navigating through resource bundle keys. + * + * @author Pascal Essiembre + */ +public class FormEntryLeftBanner extends Composite { + + /** + * Constructor. + * + * @param parent + * parent composite + * @param keyTree + * key tree + */ + public FormEntryLeftBanner(Composite parent, final AbstractI18NEntry i18NEntry) { + super(parent, SWT.NONE); + + FillLayout layout = new FillLayout(SWT.HORIZONTAL); + this.setLayout(layout); + // TODO have "show country flags" in preferences. + // TODO have text aligned bottom next to flag icon. + Label imgLabel = new Label(this, SWT.NONE); + Image countryIcon = LocaleImageUtil.getCountryIcon(i18NEntry.getLocale()); + if (countryIcon != null) { + imgLabel.setImage(countryIcon); + } + + ToolBarManager compositeToolbar = new ToolBarManager(); + + final IAction foldAction = new FoldingAction(i18NEntry); + compositeToolbar.add(foldAction); + ToolBar toolbar = compositeToolbar.createControl(this); + + // Button commentButton = new Button(compos, SWT.TOGGLE); + // commentButton.setImage(UIUtils.getImage("comment.gif")); + +// Link localeLabel = new Link(this, SWT.NONE); +// localeLabel.setFont(UIUtils.createFont(localeLabel, SWT.BOLD)); +// +// boolean isEditable = i18NEntry.isEditable(); +// localeLabel.setText("" + UIUtils.getDisplayName(i18NEntry.getLocale()) + "" +// + (!isEditable ? " (" + MessagesEditorPlugin.getString("editor.readOnly") + ")" : "")); +// +// localeLabel +// .setToolTipText(MessagesEditorPlugin.getString("editor.i18nentry.resourcelocation", i18NEntry.getResourceLocationLabel())); //$NON-NLS-1$ +// +// localeLabel.addSelectionListener(new SelectionAdapter() { +// public void widgetSelected(SelectionEvent e) { +// i18NEntry.getResourceBundleEditor().setActivePage(i18NEntry.getLocale()); +// } +// }); + + + } +} diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/I18NPage.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/I18NPage.java index b4590e9..b0b3f23 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/I18NPage.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/I18NPage.java @@ -21,10 +21,14 @@ import org.eclipse.babel.core.message.manager.IMessagesEditorListener; import org.eclipse.babel.core.message.manager.RBManager; import org.eclipse.babel.editor.IMessagesEditorChangeListener; +import org.eclipse.babel.editor.actions.KeyTreeVisibleAction; +import org.eclipse.babel.editor.actions.NewLocaleAction; import org.eclipse.babel.editor.internal.AbstractMessagesEditor; import org.eclipse.babel.editor.internal.MessagesEditorChangeAdapter; -import org.eclipse.babel.editor.tree.actions.AbstractRenameKeyAction; +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.IToolBarManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; @@ -33,12 +37,14 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.forms.IFormColors; +import org.eclipse.ui.forms.widgets.ColumnLayout; +import org.eclipse.ui.forms.widgets.ColumnLayoutData; +import org.eclipse.ui.forms.widgets.Form; +import org.eclipse.ui.forms.widgets.FormToolkit; /** * Internationalization page where one can edit all resource bundle entries at @@ -46,7 +52,7 @@ * * @author Pascal Essiembre */ -public class I18NPage extends ScrolledComposite implements ISelectionProvider { +public class I18NPage extends Composite implements ISelectionProvider { /** Minimum height of text fields. */ private static final int TEXT_MIN_HEIGHT = 90; @@ -54,15 +60,16 @@ public class I18NPage extends ScrolledComposite implements ISelectionProvider { protected final AbstractMessagesEditor editor; protected final SideNavComposite keysComposite; private final Composite valuesComposite; - private final Map entryComposites = new HashMap(); + private final Map entryComposites = new HashMap<>(); private Composite entriesComposite; - // private Composite parent; private boolean keyTreeVisible = true; - - // private final StackLayout layout = new StackLayout(); private final SashForm sashForm; + private FormToolkit toolkit; + + private Form form; + /** * Constructor. * @@ -76,45 +83,27 @@ public class I18NPage extends ScrolledComposite implements ISelectionProvider { public I18NPage(Composite parent, int style, final AbstractMessagesEditor editor) { super(parent, style); - this.editor = editor; - sashForm = new SashForm(this, SWT.SMOOTH); - sashForm.setBackground(getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); - editor.getEditorSite().getPage().addPartListener(new IPartListener() { - public void partActivated(IWorkbenchPart part) { - if (part == editor) { - sashForm.setBackground(getDisplay().getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); - } - } - public void partDeactivated(IWorkbenchPart part) { - if (part == editor) { - sashForm.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); - - } - } - - public void partBroughtToTop(IWorkbenchPart part) { - } - - public void partClosed(IWorkbenchPart part) { - } + this.editor = editor; + this.toolkit = new FormToolkit(getDisplay()); + this.setLayout(new FillLayout()); - public void partOpened(IWorkbenchPart part) { - } - }); + this.form = this.toolkit.createForm(this); + this.toolkit.decorateFormHeading(this.form); + this.form.setImage(BabelSharedImages.get(IBabelSharedImages.IMAGE_RESOURCE_BUNDLE)); + this.form.setText("Messages Editor"); + this.form.getBody().setLayout( new FillLayout()); - setContent(sashForm); + this.sashForm = new SashForm(this.form.getBody(), SWT.NONE); + this.sashForm.setBackground(this.toolkit.getColors().getColor(IFormColors.BORDER )); - keysComposite = new SideNavComposite(sashForm, editor); + this.keysComposite = new SideNavComposite(sashForm, editor); + this.keysComposite.setBackground(this.form.getBackground()); - valuesComposite = createValuesComposite(sashForm); + this.valuesComposite = createValuesComposite(sashForm); sashForm.setWeights(new int[] { 25, 75 }); - setExpandHorizontal(true); - setExpandVertical(true); - setMinWidth(400); - RBManager instance = RBManager.getInstance(editor.getBundleGroup() .getProjectName()); instance.addMessagesEditorListener(new IMessagesEditorListener() { @@ -146,6 +135,14 @@ public void onResourceChanged(IMessagesBundle bundle) { } }); + + IToolBarManager toolBarManager = this.form.getToolBarManager(); + + KeyTreeVisibleAction toggleKeyTreeAction = new KeyTreeVisibleAction(editor); + NewLocaleAction newLocaleAction = new NewLocaleAction(editor); + toolBarManager.add(toggleKeyTreeAction); + toolBarManager.add(newLocaleAction); + this.form.updateToolBar(); } /** @@ -175,25 +172,35 @@ public boolean isKeyTreeVisible() { private Composite createValuesComposite(SashForm parent) { final ScrolledComposite scrolledComposite = new ScrolledComposite( - parent, SWT.V_SCROLL | SWT.H_SCROLL); + parent, SWT.V_SCROLL); + scrolledComposite.setExpandHorizontal(true); scrolledComposite.setExpandVertical(true); scrolledComposite.setSize(SWT.DEFAULT, 100); + scrolledComposite.setBackground(this.form.getBackground()); + entriesComposite = new Composite(scrolledComposite, SWT.NONE); + entriesComposite.setBackground(this.form.getBackground()); - entriesComposite = new Composite(scrolledComposite, SWT.BORDER); scrolledComposite.setContent(entriesComposite); scrolledComposite.setMinSize(entriesComposite.computeSize(SWT.DEFAULT, editor.getBundleGroup().getLocales().length * TEXT_MIN_HEIGHT)); - entriesComposite.setLayout(new GridLayout(1, false)); + ColumnLayout columnLayout = new ColumnLayout(); + columnLayout.maxNumColumns = 1; + entriesComposite.setLayout(columnLayout); Locale[] locales = editor.getBundleGroup().getLocales(); UIUtils.sortLocales(locales); locales = UIUtils.filterLocales(locales); for (int i = 0; i < locales.length; i++) { Locale locale = locales[i]; - addI18NEntry(locale); + AbstractI18NEntry i18NEntry = addI18NEntry(locale); + ColumnLayoutData gridData = new ColumnLayoutData(); + gridData.heightHint = SWT.DEFAULT; + i18NEntry.setLayoutData(gridData); } + entriesComposite.layout(); + editor.addChangeListener(new MessagesEditorChangeAdapter() { public void selectedKeyChanged(String oldKey, String newKey) { boolean isKey = newKey != null @@ -205,7 +212,7 @@ public void selectedKeyChanged(String oldKey, String newKey) { return scrolledComposite; } - public void addI18NEntry(Locale locale) { + public AbstractI18NEntry addI18NEntry(Locale locale) { AbstractI18NEntry i18NEntry = null; try { Class clazz = Class.forName(AbstractI18NEntry.INSTANCE_CLASS); @@ -219,6 +226,8 @@ public void addI18NEntry(Locale locale) { // entryComposite.addFocusListener(localBehaviour); entryComposites.put(locale, i18NEntry); entriesComposite.layout(); + + return i18NEntry; } public void removeI18NEntry(Locale locale) { diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/LocaleWarningToolTip.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/LocaleWarningToolTip.java new file mode 100644 index 0000000..cf8b194 --- /dev/null +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/LocaleWarningToolTip.java @@ -0,0 +1,80 @@ +package org.eclipse.babel.editor.i18n; + +import org.eclipse.babel.editor.util.BabelSharedImages; +import org.eclipse.babel.editor.util.IBabelSharedImages; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.window.ToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; + +public abstract class LocaleWarningToolTip extends ToolTip { + + private String headerText = ""; + private Label titleTextLabel; + private Label titleImageLabel; // TODO : Implement image support + + protected LocaleWarningToolTip(Control control) { + super(control); + } + + public String getText() + { + return this.headerText; + } + + public void setText(String text) { + this.headerText = text; + if ( this.titleTextLabel != null && !this.titleTextLabel.isDisposed()) { + this.titleTextLabel.setText(this.headerText); + } + } + + @Override + protected Composite createToolTipContentArea(Event event, Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + + GridLayout toolTipLayout = new GridLayout(1, false); + toolTipLayout.marginBottom = 0; + toolTipLayout.marginTop = 0; + toolTipLayout.marginHeight = 0; + toolTipLayout.marginWidth = 0; + toolTipLayout.marginLeft = 0; + toolTipLayout.marginRight = 0; + toolTipLayout.verticalSpacing = 1; + comp.setLayout(toolTipLayout); + + Composite headerCompsite = new Composite(comp, SWT.NONE); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); + data.widthHint = 200; + headerCompsite.setLayoutData(data); + + GridLayout headerLayout = new GridLayout(2, false); + headerLayout.marginBottom = 2; + headerLayout.marginTop = 2; + headerLayout.marginHeight = 0; + headerLayout.marginWidth = 0; + headerLayout.marginLeft = 5; + headerLayout.marginRight = 2; + + headerCompsite.setLayout(headerLayout); + + this.titleImageLabel = new Label(headerCompsite, SWT.NONE); + this.titleImageLabel.setImage(BabelSharedImages.get(IBabelSharedImages.IMAGE_PROPERTIES_FILE)); + + this.titleTextLabel = new Label(headerCompsite, SWT.NONE); + this.titleTextLabel.setText("Resource bundle problems"); + this.titleTextLabel.setFont(JFaceResources.getBannerFont()); + this.titleTextLabel.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createContentArea(comp).setLayoutData(new GridData(GridData.FILL_BOTH)); + + return comp; + } + + abstract Control createContentArea(Composite parent); + } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavComposite.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavComposite.java index ff7fa0f..50d1d43 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavComposite.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavComposite.java @@ -13,7 +13,6 @@ import org.eclipse.babel.editor.internal.AbstractMessagesEditor; import org.eclipse.babel.editor.tree.actions.CollapseAllAction; import org.eclipse.babel.editor.tree.actions.ExpandAllAction; -import org.eclipse.babel.editor.tree.actions.FlatModelAction; import org.eclipse.babel.editor.tree.actions.TreeModelAction; import org.eclipse.babel.editor.tree.internal.KeyTreeContributor; import org.eclipse.jface.action.Separator; @@ -24,6 +23,8 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; /** * Tree for displaying and navigating through resource bundle keys. @@ -49,40 +50,47 @@ public class SideNavComposite extends Composite { */ public SideNavComposite(Composite parent, final AbstractMessagesEditor editor) { - super(parent, SWT.BORDER); + super(parent, SWT.NONE); this.editor = editor; - + setLayout(new GridLayout(1, true)); + + FormToolkit toolKit = new FormToolkit(this.getDisplay()); + Section messageKeySection = toolKit.createSection(this, Section.TITLE_BAR | Section.EXPANDED ); + messageKeySection.setText("Message keys"); // Create a toolbar. ToolBarManager toolBarMgr = new ToolBarManager(SWT.FLAT); - ToolBar toolBar = toolBarMgr.createControl(this); + ToolBar toolBar = toolBarMgr.createControl(messageKeySection); - this.treeViewer = new TreeViewer(this, SWT.MULTI | SWT.BORDER - | SWT.V_SCROLL | SWT.H_SCROLL); + messageKeySection.setTextClient(toolBar); - setLayout(new GridLayout(1, false)); + messageKeySection.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); + + this.treeViewer = new TreeViewer(messageKeySection, SWT.MULTI | SWT.BORDER + | SWT.V_SCROLL | SWT.H_SCROLL); - GridData gid; + // createTopSection(); + createKeyTree(); + + messageKeySection.setClient(this.treeViewer.getControl()); - gid = new GridData(); - gid.horizontalAlignment = GridData.END; - gid.verticalAlignment = GridData.BEGINNING; - toolBar.setLayoutData(gid); - toolBarMgr.add(new TreeModelAction(editor, treeViewer)); - toolBarMgr.add(new FlatModelAction(editor, treeViewer)); + toolBarMgr.add(new TreeModelAction(this.editor, this.treeViewer)); toolBarMgr.add(new Separator()); - toolBarMgr.add(new ExpandAllAction(editor, treeViewer)); - toolBarMgr.add(new CollapseAllAction(editor, treeViewer)); + toolBarMgr.add(new ExpandAllAction(this.editor, this.treeViewer)); + toolBarMgr.add(new CollapseAllAction(this.editor, this.treeViewer)); + + toolBarMgr.add(new FilterDropDown(this.editor, this.treeViewer)); + toolBarMgr.update(true); // TODO have two toolbars, one left-align, and one right, with drop // down menu // initListener(); - - // createTopSection(); - createKeyTree(); textBoxComp = new SideNavTextBoxComposite(this, editor); + textBoxComp.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); } + + // private void initListener() { // IResourceChangeListener listener = new IResourceChangeListener() { // @@ -118,16 +126,8 @@ public void dispose() { * Creates the middle (tree) section of this composite. */ private void createKeyTree() { - - GridData gridData = new GridData(); - gridData.verticalAlignment = GridData.FILL; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - KeyTreeContributor treeContributor = new KeyTreeContributor(editor); treeContributor.contribute(treeViewer); - treeViewer.getTree().setLayoutData(gridData); } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavTextBoxComposite.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavTextBoxComposite.java index ca31be6..917fa41 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavTextBoxComposite.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/SideNavTextBoxComposite.java @@ -32,6 +32,7 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.FormToolkit; /** * Tree for displaying and navigating through resource bundle keys. @@ -59,6 +60,9 @@ public class SideNavTextBoxComposite extends Composite { public SideNavTextBoxComposite(Composite parent, final AbstractMessagesEditor editor) { super(parent, SWT.NONE); + + FormToolkit toolkit = new FormToolkit(getDisplay()); + this.editor = editor; GridLayout gridLayout = new GridLayout(); @@ -68,22 +72,17 @@ public SideNavTextBoxComposite(Composite parent, gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; setLayout(gridLayout); - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.verticalAlignment = GridData.CENTER; - gridData.grabExcessHorizontalSpace = true; - setLayoutData(gridData); + GridData gridData = null; // Text box - addTextBox = new Text(this, SWT.BORDER); + addTextBox = toolkit.createText(this, "", SWT.BORDER); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = GridData.FILL; addTextBox.setLayoutData(gridData); // Add button - addButton = new Button(this, SWT.PUSH); - addButton.setText(MessagesEditorPlugin.getString("key.add")); //$NON-NLS-1$ + addButton = toolkit.createButton(this, MessagesEditorPlugin.getString("key.add"), SWT.PUSH); //$NON-NLS-1$ addButton.setEnabled(false); addButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/actions/FoldingAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/actions/FoldingAction.java index 0623edf..69c7500 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/actions/FoldingAction.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/i18n/actions/FoldingAction.java @@ -30,7 +30,7 @@ public class FoldingAction extends Action { public FoldingAction(AbstractI18NEntry i18NEntry) { super(); this.i18NEntry = i18NEntry; - this.expanded = i18NEntry.getExpanded(); +// this.expanded = i18NEntry.getExpanded(); setText("Collapse"); setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_MINUS)); setToolTipText("TODO put something here"); // TODO put tooltip @@ -42,13 +42,13 @@ public FoldingAction(AbstractI18NEntry i18NEntry) { * @see org.eclipse.jface.action.IAction#run() */ public void run() { - if (i18NEntry.getExpanded()) { - setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_PLUS)); - i18NEntry.setExpanded(false); - } else { - setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_MINUS)); - i18NEntry.setExpanded(true); - } +// if (i18NEntry.getExpanded()) { +// setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_PLUS)); +// i18NEntry.setExpanded(false); +// } else { +// setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_MINUS)); +// i18NEntry.setExpanded(true); +// } } } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/AbstractMessagesEditor.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/AbstractMessagesEditor.java index 35d4153..108e5da 100755 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/AbstractMessagesEditor.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/AbstractMessagesEditor.java @@ -22,11 +22,9 @@ import org.eclipse.babel.core.message.IMessagesBundle; import org.eclipse.babel.core.message.internal.IMessagesBundleGroupListener; -import org.eclipse.babel.core.message.internal.IMessagesBundleListener; import org.eclipse.babel.core.message.internal.MessageException; import org.eclipse.babel.core.message.internal.MessagesBundle; import org.eclipse.babel.core.message.internal.MessagesBundleGroup; -import org.eclipse.babel.core.message.internal.MessagesBundleGroupAdapter; import org.eclipse.babel.core.message.manager.RBManager; import org.eclipse.babel.core.message.resource.IMessagesResource; import org.eclipse.babel.core.message.tree.internal.AbstractKeyTreeModel; @@ -476,7 +474,12 @@ public void dispose() { for (IMessagesEditorChangeListener listener : changeListeners) { listener.editorDisposed(); } - i18nPage.dispose(); + + if(i18nPage != null) { + this.i18nPage.dispose(); + this.i18nPage = null; + } + for (ITextEditor textEditor : textEditorsIndex) { textEditor.dispose(); } @@ -553,22 +556,8 @@ public I18NPage getI18NPage() { return i18nPage; } - /** - * one of the SHOW_* constants defined in the - * {@link IMessagesEditorChangeListener} - */ - private int showOnlyMissingAndUnusedKeys = IMessagesEditorChangeListener.SHOW_ALL; - - /** - * @return true when only unused and missing keys should be displayed. flase - * by default. - */ - public int isShowOnlyUnusedAndMissingKeys() { - return showOnlyMissingAndUnusedKeys; - } - - public void setShowOnlyUnusedMissingKeys(int showFlag) { - showOnlyMissingAndUnusedKeys = showFlag; + public void notifyChange(int showFlag) + { for (IMessagesEditorChangeListener listener : getChangeListeners()) { listener.showOnlyUnusedAndMissingChanged(showFlag); } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorContributor.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorContributor.java index cd47369..8e09a94 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorContributor.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorContributor.java @@ -10,20 +10,10 @@ ******************************************************************************/ package org.eclipse.babel.editor.internal; -import org.eclipse.babel.editor.IMessagesEditorChangeListener; -import org.eclipse.babel.editor.actions.FilterKeysAction; -import org.eclipse.babel.editor.actions.KeyTreeVisibleAction; -import org.eclipse.babel.editor.actions.NewLocaleAction; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.part.MultiPageEditorActionBarContributor; import org.eclipse.ui.texteditor.ITextEditor; @@ -35,24 +25,14 @@ * editor. Multi-page contributor replaces the contributors for the individual * editors in the multi-page editor. */ -public class MessagesEditorContributor extends - MultiPageEditorActionBarContributor { +public class MessagesEditorContributor extends MultiPageEditorActionBarContributor { private IEditorPart activeEditorPart; - private KeyTreeVisibleAction toggleKeyTreeAction; - private NewLocaleAction newLocaleAction; - private IMenuManager resourceBundleMenu; - private static String resourceBundleMenuID; - - /** singleton: probably not the cleanest way to access it from anywhere. */ - public static ActionGroup FILTERS = new FilterKeysActionGroup(); - /** * Creates a multi-page contributor. */ public MessagesEditorContributor() { super(); - createActions(); } /** @@ -82,8 +62,7 @@ public void setActivePage(IEditorPart part) { IActionBars actionBars = getActionBars(); if (actionBars != null) { - ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part - : null; + ITextEditor editor = (part instanceof ITextEditor textEditor) ? textEditor: null; actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE)); @@ -107,122 +86,4 @@ public void setActivePage(IEditorPart part) { actionBars.updateActionBars(); } } - - private void createActions() { - // sampleAction = new Action() { - // public void run() { - // MessageDialog.openInformation(null, - // "ResourceBundle Editor Plug-in", "Sample Action Executed"); - // } - // }; - // sampleAction.setText("Sample Action"); - // sampleAction.setToolTipText("Sample Action tool tip"); - // sampleAction.setImageDescriptor( - // PlatformUI.getWorkbench().getSharedImages(). - // getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK)); - - toggleKeyTreeAction = new KeyTreeVisibleAction(); - newLocaleAction = new NewLocaleAction(); - - // toggleKeyTreeAction.setText("Show/Hide Key Tree"); - // toggleKeyTreeAction.setToolTipText("Click to show/hide the key tree"); - // toggleKeyTreeAction.setImageDescriptor( - // PlatformUI.getWorkbench().getSharedImages(). - // getImageDescriptor(IDE.SharedImages.IMG_OPEN_MARKER)); - - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor - * #contributeToMenu(org.eclipse.jface.action.IMenuManager) - */ - public void contributeToMenu(IMenuManager manager) { - // System.out.println("active editor part:" +activeEditorPart); - // System.out.println("menu editor:" + rbEditor); - resourceBundleMenu = new MenuManager("&Messages", resourceBundleMenuID); - manager.prependToGroup(IWorkbenchActionConstants.M_EDIT, - resourceBundleMenu); - resourceBundleMenu.add(toggleKeyTreeAction); - resourceBundleMenu.add(newLocaleAction); - - FILTERS.fillContextMenu(resourceBundleMenu); - } - - /** - * @see org.eclipse.ui.part.EditorActionBarContributor - * #contributeToToolBar(org.eclipse.jface.action.IToolBarManager) - */ - public void contributeToToolBar(IToolBarManager manager) { - // System.out.println("toolbar get page:" + getPage()); - // System.out.println("toolbar editor:" + rbEditor); - manager.add(new Separator()); - // manager.add(sampleAction); - manager.add(toggleKeyTreeAction); - manager.add(newLocaleAction); - - ((FilterKeysActionGroup) FILTERS).fillActionBars(getActionBars()); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActiveEditor - * (org.eclipse.ui.IEditorPart) - */ - public void setActiveEditor(IEditorPart part) { - super.setActiveEditor(part); - AbstractMessagesEditor me = part instanceof AbstractMessagesEditor ? (AbstractMessagesEditor) part - : null; - toggleKeyTreeAction.setEditor(me); - ((FilterKeysActionGroup) FILTERS).setActiveEditor(part); - newLocaleAction.setEditor(me); - } - - /** - * Groups the filter actions together. - */ - private static class FilterKeysActionGroup extends ActionGroup { - FilterKeysAction[] filtersAction = new FilterKeysAction[4]; - - public FilterKeysActionGroup() { - filtersAction[0] = new FilterKeysAction( - IMessagesEditorChangeListener.SHOW_ALL); - filtersAction[1] = new FilterKeysAction( - IMessagesEditorChangeListener.SHOW_ONLY_MISSING); - filtersAction[2] = new FilterKeysAction( - IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED); - filtersAction[3] = new FilterKeysAction( - IMessagesEditorChangeListener.SHOW_ONLY_UNUSED); - } - - public void fillActionBars(IActionBars actionBars) { - for (int i = 0; i < filtersAction.length; i++) { - actionBars.getToolBarManager().add(filtersAction[i]); - } - } - - public void fillContextMenu(IMenuManager menu) { - MenuManager filters = new MenuManager("Filters"); - for (int i = 0; i < filtersAction.length; i++) { - filters.add(filtersAction[i]); - } - menu.add(filters); - } - - public void updateActionBars() { - for (int i = 0; i < filtersAction.length; i++) { - filtersAction[i].update(); - } - } - - public void setActiveEditor(IEditorPart part) { - AbstractMessagesEditor me = part instanceof AbstractMessagesEditor ? (AbstractMessagesEditor) part - : null; - for (int i = 0; i < filtersAction.length; i++) { - filtersAction[i].setEditor(me); - } - } - } - } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorMarkers.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorMarkers.java index cb95973..2879306 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorMarkers.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/internal/MessagesEditorMarkers.java @@ -28,7 +28,6 @@ import org.eclipse.babel.editor.resource.validator.IValidationMarkerStrategy; import org.eclipse.babel.editor.resource.validator.MessagesBundleGroupValidator; import org.eclipse.babel.editor.resource.validator.ValidationFailureEvent; -import org.eclipse.babel.editor.util.UIUtils; import org.eclipse.swt.widgets.Display; /** diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/FlatModelAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/FlatModelAction.java deleted file mode 100644 index 119a16d..0000000 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/FlatModelAction.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Pascal Essiembre. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pascal Essiembre - initial API and implementation - ******************************************************************************/ -package org.eclipse.babel.editor.tree.actions; - -import org.eclipse.babel.core.message.tree.TreeType; -import org.eclipse.babel.editor.internal.AbstractMessagesEditor; -import org.eclipse.babel.editor.plugin.MessagesEditorPlugin; -import org.eclipse.babel.editor.tree.internal.KeyTreeContentProvider; -import org.eclipse.babel.editor.util.BabelSharedImages; -import org.eclipse.babel.editor.util.IBabelSharedImages; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.TreeViewer; - -/** - * @author Pascal Essiembre - * - */ -public class FlatModelAction extends AbstractTreeAction { - - /** - * @param editor - * @param treeViewer - */ - public FlatModelAction(AbstractMessagesEditor editor, TreeViewer treeViewer) { - super(editor, treeViewer, IAction.AS_RADIO_BUTTON); - setText(MessagesEditorPlugin.getString("key.layout.flat")); //$NON-NLS-1$ - setImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_LAYOUT_FLAT)); - setDisabledImageDescriptor(BabelSharedImages.getDescriptor(IBabelSharedImages.IMAGE_LAYOUT_FLAT)); - setToolTipText("Display in a list"); // TODO put tooltip - } - - /** - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - KeyTreeContentProvider contentProvider = (KeyTreeContentProvider) treeViewer - .getContentProvider(); - contentProvider.setTreeType(TreeType.Flat); - } -} diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/TreeModelAction.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/TreeModelAction.java index e943717..026ae12 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/TreeModelAction.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/actions/TreeModelAction.java @@ -43,6 +43,10 @@ public TreeModelAction(AbstractMessagesEditor editor, TreeViewer treeViewer) { public void run() { KeyTreeContentProvider contentProvider = (KeyTreeContentProvider) treeViewer .getContentProvider(); - contentProvider.setTreeType(TreeType.Tree); + + TreeType currentTreeType = contentProvider.getTreeType(); + TreeType newTreeType = currentTreeType == TreeType.Tree ? TreeType.Flat : TreeType.Tree; // Toggle tree type. + contentProvider.setTreeType(newTreeType); + setChecked(newTreeType == TreeType.Tree); } } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/KeyTreeContributor.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/KeyTreeContributor.java index 8dfc148..5a2aa41 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/KeyTreeContributor.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/KeyTreeContributor.java @@ -87,12 +87,13 @@ public void contribute(final TreeViewer treeViewer) { treeType); treeViewer.setContentProvider(contentProvider); ColumnViewerToolTipSupport.enableFor(treeViewer); - treeViewer.setLabelProvider(new KeyTreeLabelProvider(editor, treeModel, - contentProvider)); - if (treeViewer.getInput() == null) + treeViewer.setLabelProvider(new KeyTreeLabelProvider(editor, treeModel, contentProvider)); + + if (treeViewer.getInput() == null) { treeViewer.setUseHashlookup(true); + } - ViewerFilter onlyUnusedAndMissingKeysFilter = new OnlyUnsuedAndMissingKey(); + ViewerFilter onlyUnusedAndMissingKeysFilter = new OnlyUnsuedAndMissingKey(this.editor); ViewerFilter[] filters = { onlyUnusedAndMissingKeysFilter }; treeViewer.setFilters(filters); @@ -119,59 +120,6 @@ public void contribute(final TreeViewer treeViewer) { treeViewer.getTree()) }); } - private class OnlyUnsuedAndMissingKey extends ViewerFilter implements - AbstractKeyTreeModel.IKeyTreeNodeLeafFilter { - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers - * .Viewer, java.lang.Object, java.lang.Object) - */ - public boolean select(Viewer viewer, Object parentElement, - Object element) { - if (editor.isShowOnlyUnusedAndMissingKeys() == IMessagesEditorChangeListener.SHOW_ALL - || !(element instanceof KeyTreeNode)) { - // no filtering. the element is displayed by default. - return true; - } - if (editor.getI18NPage() != null - && editor.getI18NPage().isKeyTreeVisible()) { - return editor.getKeyTreeModel().isBranchFiltered(this, - (KeyTreeNode) element); - } else { - return isFilteredLeaf((KeyTreeNode) element); - } - } - - /** - * @param node - * @return true if this node should be in the filter. Does not navigate - * the tree of KeyTreeNode. false unless the node is a missing - * or unused key. - */ - public boolean isFilteredLeaf(IKeyTreeNode node) { - MessagesEditorMarkers markers = KeyTreeContributor.this.editor - .getMarkers(); - String key = node.getMessageKey(); - boolean missingOrUnused = markers.isMissingOrUnusedKey(key); - if (!missingOrUnused) { - return false; - } - switch (editor.isShowOnlyUnusedAndMissingKeys()) { - case IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED: - return missingOrUnused; - case IMessagesEditorChangeListener.SHOW_ONLY_MISSING: - return !markers.isUnusedKey(key, missingOrUnused); - case IMessagesEditorChangeListener.SHOW_ONLY_UNUSED: - return markers.isUnusedKey(key, missingOrUnused); - default: - return false; - } - } - - } /** * Contributes markers. diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/OnlyUnsuedAndMissingKey.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/OnlyUnsuedAndMissingKey.java new file mode 100644 index 0000000..5f60538 --- /dev/null +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/tree/internal/OnlyUnsuedAndMissingKey.java @@ -0,0 +1,88 @@ +package org.eclipse.babel.editor.tree.internal; + +import org.eclipse.babel.core.message.tree.IKeyTreeNode; +import org.eclipse.babel.core.message.tree.internal.AbstractKeyTreeModel; +import org.eclipse.babel.core.message.tree.internal.KeyTreeNode; +import org.eclipse.babel.editor.IMessagesEditorChangeListener; +import org.eclipse.babel.editor.internal.AbstractMessagesEditor; +import org.eclipse.babel.editor.internal.MessagesEditorMarkers; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +public class OnlyUnsuedAndMissingKey extends ViewerFilter implements + AbstractKeyTreeModel.IKeyTreeNodeLeafFilter { + + /** + * one of the SHOW_* constants defined in the + * {@link IMessagesEditorChangeListener} + */ + private int showOnlyMissingAndUnusedKeys = IMessagesEditorChangeListener.SHOW_ALL; + + private AbstractMessagesEditor editor; + + public OnlyUnsuedAndMissingKey(AbstractMessagesEditor editor) { + this.editor = editor; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers + * .Viewer, java.lang.Object, java.lang.Object) + */ + public boolean select(Viewer viewer, Object parentElement, + Object element) { + + if (this.isShowOnlyUnusedAndMissingKeys() == IMessagesEditorChangeListener.SHOW_ALL + || !(element instanceof KeyTreeNode)) { + // no filtering. the element is displayed by default. + return true; + } + if (this.editor.getI18NPage() != null + && this.editor.getI18NPage().isKeyTreeVisible()) { + return this.editor.getKeyTreeModel().isBranchFiltered(this, + (KeyTreeNode) element); + } else { + return isFilteredLeaf((KeyTreeNode) element); + } + } + + /** + * @param node + * @return true if this node should be in the filter. Does not navigate + * the tree of KeyTreeNode. false unless the node is a missing + * or unused key. + */ + public boolean isFilteredLeaf(IKeyTreeNode node) { + MessagesEditorMarkers markers = this.editor.getMarkers(); + String key = node.getMessageKey(); + boolean missingOrUnused = markers.isMissingOrUnusedKey(key); + if (!missingOrUnused) { + return false; + } + switch (this.isShowOnlyUnusedAndMissingKeys()) { + case IMessagesEditorChangeListener.SHOW_ONLY_MISSING_AND_UNUSED: + return missingOrUnused; + case IMessagesEditorChangeListener.SHOW_ONLY_MISSING: + return !markers.isUnusedKey(key, missingOrUnused); + case IMessagesEditorChangeListener.SHOW_ONLY_UNUSED: + return markers.isUnusedKey(key, missingOrUnused); + default: + return false; + } + } + + /** + * @return true when only unused and missing keys should be displayed. false by default. + */ + public int isShowOnlyUnusedAndMissingKeys() { + return this.showOnlyMissingAndUnusedKeys; + } + + public void setShowOnlyUnusedMissingKeys(int showFlag) { + this.showOnlyMissingAndUnusedKeys = showFlag; + this.editor.notifyChange(showFlag); + } + +} \ No newline at end of file diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/BabelSharedImages.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/BabelSharedImages.java index c0ff8a0..446f5e3 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/BabelSharedImages.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/BabelSharedImages.java @@ -51,6 +51,8 @@ public class BabelSharedImages { localRegistry.put(IBabelSharedImages.IMAGE_PLUS, createImageDescriptor(IBabelSharedImages.IMAGE_PLUS)); localRegistry.put(IBabelSharedImages.IMAGE_SIMILAR, createImageDescriptor(IBabelSharedImages.IMAGE_SIMILAR)); + + localRegistry.put(IBabelSharedImages.IMAGE_VIEW_MENU, createImageDescriptor(IBabelSharedImages.IMAGE_VIEW_MENU)); } private BabelSharedImages() diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/IBabelSharedImages.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/IBabelSharedImages.java index bbb6041..cdd7728 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/IBabelSharedImages.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/IBabelSharedImages.java @@ -47,4 +47,5 @@ public interface IBabelSharedImages { public static final String IMAGE_WARNING = "warning.gif"; //$NON-NLS-1$ public static final String IMAGE_ERROR = "error_co.gif"; //$NON-NLS-1$ + public static final String IMAGE_VIEW_MENU = "view_menu.png"; //$NON-NLS-1$ } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/UIUtils.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/UIUtils.java index a7a63ca..b500b6d 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/UIUtils.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/util/UIUtils.java @@ -36,6 +36,9 @@ import org.eclipse.core.runtime.Status; import org.eclipse.core.text.StringMatcher; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; @@ -324,6 +327,16 @@ public static boolean hasNature(IProject proj, String nature) { return false; } - + @SuppressWarnings("unchecked") + public static T getFilter(Viewer viewer, Class clazz) { + if ( viewer instanceof StructuredViewer structuredViewer ) { + for ( ViewerFilter viewerFilter : structuredViewer.getFilters()) { + if ( clazz.isInstance(viewerFilter) ) { + return (T)viewerFilter; + } + } + } + return null; + } } diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/views/MessagesBundleGroupOutline.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/views/MessagesBundleGroupOutline.java index fc5242d..89740d9 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/views/MessagesBundleGroupOutline.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/views/MessagesBundleGroupOutline.java @@ -10,10 +10,10 @@ ******************************************************************************/ package org.eclipse.babel.editor.views; +import org.eclipse.babel.editor.i18n.FilterDropDown; import org.eclipse.babel.editor.internal.AbstractMessagesEditor; import org.eclipse.babel.editor.tree.actions.CollapseAllAction; import org.eclipse.babel.editor.tree.actions.ExpandAllAction; -import org.eclipse.babel.editor.tree.actions.FlatModelAction; import org.eclipse.babel.editor.tree.actions.TreeModelAction; import org.eclipse.babel.editor.tree.internal.KeyTreeContributor; import org.eclipse.jface.action.IToolBarManager; @@ -103,11 +103,11 @@ public void setActionBars(IActionBars actionbars) { // ActionContext // IAction - toolBarMgr.add(new TreeModelAction(editor, getTreeViewer())); - toolBarMgr.add(new FlatModelAction(editor, getTreeViewer())); + toolBarMgr.add(new TreeModelAction(this.editor, getTreeViewer())); toolBarMgr.add(new Separator()); - toolBarMgr.add(new ExpandAllAction(editor, getTreeViewer())); - toolBarMgr.add(new CollapseAllAction(editor, getTreeViewer())); + toolBarMgr.add(new ExpandAllAction(this.editor, getTreeViewer())); + toolBarMgr.add(new CollapseAllAction(this.editor, getTreeViewer())); + toolBarMgr.add(new FilterDropDown(this.editor, getTreeViewer())); } // // diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/widgets/NullableText.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/widgets/NullableText.java index 52ba400..0537988 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/widgets/NullableText.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/widgets/NullableText.java @@ -81,10 +81,8 @@ public NullableText(Composite parent, int style, Locale locale) { gridLayout.verticalSpacing = 0; gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; - setLayout(gridLayout); - GridData gd = new GridData(GridData.FILL_BOTH); - setLayoutData(gd); + setLayout(gridLayout); initComponents(); this.locale = locale; @@ -186,6 +184,7 @@ public void setEnabled(boolean enabled) { private void initComponents() { GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true); + gridData.heightHint = 100; text.setLayoutData(gridData); text.addKeyListener(keyListener);