private static final @NonNull String ZOOM_IN = "Zoom In";
private static final @NonNull String ZOOM_OUT = "Zoom Out";
// Separator
- private static final String PIN_VIEW = "Pin View";
+ private static final @NonNull String PIN_VIEW = "Pin View";
+
private static final List<String> TOOLBAR_BUTTONS_TOOLTIPS = ImmutableList.of(
+ PIN_VIEW,
+ "",
ALIGN_VIEWS, CONFIGURE_SYMBOL_PROVIDERS,
"",
SORT_BY_NAME, SORT_BY_ID, SORT_BY_START,
"",
ADD_BOOKMARK, PREVIOUS_MARKER, NEXT_MARKER,
"",
- SELECT_PREVIOUS_ITEM, SELECT_NEXT_ITEM, ZOOM_IN, ZOOM_OUT,
- "",
- PIN_VIEW);
+ SELECT_PREVIOUS_ITEM, SELECT_NEXT_ITEM, ZOOM_IN, ZOOM_OUT);
/**
* Initialization
}
assertEquals(TOOLBAR_BUTTONS_TOOLTIPS, buttons);
}
-}
\ No newline at end of file
+}
package org.eclipse.tracecompass.tmf.ui.views;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.widgets.Composite;
// ------------------------------------------------------------------------
/**
- * Returns whether the pin flag is set.
- * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
+ * Returns whether the view is pinned.
*
- * @return pin flag
+ * @return if the view is pinned
*/
public boolean isPinned() {
return ((fPinAction != null) && (fPinAction.isChecked()));
}
/**
- * Method adds a pin action to the TmfView. The pin action allows to toggle the <code>fIsPinned</code> flag.
- * For example, this flag can be used to ignore time synchronization signals from other TmfViews.
+ * Method adds a pin action to the TmfView. For example, this action can be
+ * used to ignore time synchronization signals from other TmfViews. <br>
+ *
+ * Uses {@link TmfView#setPinned(boolean)} to propagate the state of the
+ * action button.
*/
protected void contributePinActionToToolBar() {
if (fPinAction == null) {
toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
toolBarManager.add(fPinAction);
}
+
+ fPinAction.addPropertyChangeListener(new IPropertyChangeListener() {
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (IAction.CHECKED.equals(event.getProperty())) {
+ /* Take action on the pin state */
+ Object value = event.getNewValue();
+ if (!(value instanceof Boolean)) {
+ throw new IllegalStateException();
+ }
+ setPinned((Boolean) value);
+ }
+ }
+ });
+ }
+
+ /**
+ * TODO: change to abstract on API break <br>
+ * <br>
+ * When this method return <code>True</code> a toggle button is added to the
+ * view toolbar.<br>
+ * <br>
+ * One should implement {@link TmfView#setPinned(boolean)} to take action on state change.
+ *
+ * @return if the view can be pined
+ * @since 2.2
+ */
+ protected boolean canBePinned() {
+ return true;
+ }
+
+ /**
+ * TODO: change to abstract on API break
+ * Actions to take on pin property change.
+ * @param pinned
+ * The pin state to take action on
+ * @since 2.2
+ */
+ protected synchronized void setPinned(boolean pinned) {
+ /** Do nothing by default */
}
@Override
public void createPartControl(final Composite parent) {
fParentComposite = parent;
+
+ if (canBePinned()) {
+ contributePinActionToToolBar();
+ }
+
if (this instanceof ITmfTimeAligned) {
contributeAlignViewsActionToToolbar();
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
}
});
- contributeToActionBars();
loadSortOption();
IEditorPart editor = getSite().getPage().getActiveEditor();
fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
}
- private void contributeToActionBars() {
- // Create pin action
- contributePinActionToToolBar();
- fPinAction.addPropertyChangeListener(new IPropertyChangeListener() {
- @Override
- public void propertyChange(PropertyChangeEvent event) {
- if (IAction.CHECKED.equals(event.getProperty()) && !isPinned()) {
- if (fSavedRangeSyncSignal != null) {
- windowRangeUpdated(fSavedRangeSyncSignal);
- fSavedRangeSyncSignal = null;
- }
-
- if (fSavedTimeSyncSignal != null) {
- selectionRangeUpdated(fSavedTimeSyncSignal);
- fSavedTimeSyncSignal = null;
- }
- }
- }
- });
+ /**
+ * @since 2.2
+ */
+ @Override
+ protected synchronized void setPinned(boolean pinned) {
+ if (!pinned) {
+ if (fSavedRangeSyncSignal != null) {
+ windowRangeUpdated(fSavedRangeSyncSignal);
+ fSavedRangeSyncSignal = null;
+ }
+
+ if (fSavedTimeSyncSignal != null) {
+ selectionRangeUpdated(fSavedTimeSyncSignal);
+ fSavedTimeSyncSignal = null;
+ }
+ }
}
+
/**
* @since 1.2
*/