diff options
author | Olivier Prouvost | 2014-07-07 17:28:26 +0000 |
---|---|---|
committer | Olivier Prouvost | 2014-07-07 19:17:01 +0000 |
commit | e9feaae3b7d8a5680ab771964c47b7e448f0a37d (patch) | |
tree | cf4cb2ffa3212b10ab7649886dea2438fcd24ea9 | |
parent | d9ae4bf98e0f06e3a9d253e5f3f8ef1c1ca739de (diff) | |
download | org.eclipse.e4.tools-e9feaae3b7d8a5680ab771964c47b7e448f0a37d.tar.gz org.eclipse.e4.tools-e9feaae3b7d8a5680ab771964c47b7e448f0a37d.tar.xz org.eclipse.e4.tools-e9feaae3b7d8a5680ab771964c47b7e448f0a37d.zip |
Bug 428903 - Having a common debug window for all spies
Clean the last useless classes after refactoring
Change-Id: I9131927ef65c5918a4b7e14dd754b58e428e3415
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
13 files changed, 42 insertions, 1429 deletions
diff --git a/bundles/org.eclipse.e4.tools.context.spy/src/org/eclipse/e4/tools/context/spy/ContextSpyHandler.java b/bundles/org.eclipse.e4.tools.context.spy/src/org/eclipse/e4/tools/context/spy/ContextSpyHandler.java deleted file mode 100644 index 054e19ca..00000000 --- a/bundles/org.eclipse.e4.tools.context.spy/src/org/eclipse/e4/tools/context/spy/ContextSpyHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 OPCoach. - * 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: - * Olivier Prouvost <olivier.prouvost@opcoach.com> - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.tools.context.spy; - -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.workbench.modeling.EPartService; -import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; - -public class ContextSpyHandler -{ - - @Execute - public void run(EPartService ps) - { - ps.showPart(ContextSpyPart.CONTEXT_SPY_VIEW_DESC, PartState.ACTIVATE); - } -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSPropertiesContentProvider.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSPropertiesContentProvider.java index 7463dd00..643f8bab 100644 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSPropertiesContentProvider.java +++ b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSPropertiesContentProvider.java @@ -25,22 +25,25 @@ public class CSSPropertiesContentProvider implements IStructuredContentProvider protected CSSEngine cssEngine; protected CSSStylableElement input; - public void dispose() { + @Override + public void dispose() { cssEngine = null; input = null; } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput instanceof CSSStylableElement) { this.input = (CSSStylableElement) newInput; - this.cssEngine = CssSpyDialog.getCSSEngine((Widget) input.getNativeWidget()); + this.cssEngine = CssSpyPart.getCSSEngine(input.getNativeWidget()); } else if (newInput instanceof Widget) { - this.cssEngine = CssSpyDialog.getCSSEngine((Widget) newInput); + this.cssEngine = CssSpyPart.getCSSEngine(newInput); this.input = (CSSStylableElement) cssEngine.getElement(newInput); } } - public Object[] getElements(Object inputElement) { + @Override + public Object[] getElements(Object inputElement) { Collection<String> propertyNames = cssEngine.getCSSProperties(input); List<CSSPropertyProvider> properties = new ArrayList<CSSPropertyProvider>( propertyNames.size()); diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSScratchPadWindow.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSScratchPadWindow.java deleted file mode 100644 index f0c3c635..00000000 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CSSScratchPadWindow.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.eclipse.e4.tools.css.spy; - -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS; -import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.swt.internal.theme.ThemeEngine; -import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.w3c.css.sac.CSSParseException; -import org.w3c.dom.stylesheets.StyleSheet; -import org.w3c.dom.stylesheets.StyleSheetList; - -public class CSSScratchPadWindow extends Dialog { - - private IThemeEngine themeEngine; - - public CSSScratchPadWindow(Shell parentShell, IThemeEngine themeEngine) { - super(parentShell); - this.themeEngine = themeEngine; - setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE/* | SWT.PRIMARY_MODAL */); - // setShellStyle(SWT.DIALOG_TRIM | SWT.MAX | SWT.RESIZE - // | getDefaultOrientation()); - } - - @Override - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText("CSS Scratchpad"); - } - - private static final int APPLY_ID = IDialogConstants.OK_ID + 100; - - private Text cssText; - private Text exceptions; - - @Override - protected Control createDialogArea(Composite parent) { - Composite outer = (Composite) super.createDialogArea(parent); - - SashForm sashForm = new SashForm(outer, SWT.VERTICAL); - - cssText = new Text(sashForm, SWT.BORDER | SWT.MULTI | SWT.WRAP - | SWT.V_SCROLL); - - exceptions = new Text(sashForm, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY); - - GridDataFactory.fillDefaults().grab(true, true).applyTo(sashForm); - sashForm.setWeights(new int[] { 80, 20 }); - - return outer; - } - - @Override - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, APPLY_ID, "Apply", true); - createButton(parent, IDialogConstants.OK_ID, "Close", false); - // createButton(parent, IDialogConstants.CANCEL_ID, - // IDialogConstants.CANCEL_LABEL, false); - } - - /** - * Return the initial size of the dialog. - */ - @Override - protected Point getInitialSize() { - return new Point(600, 500); - } - - @Override - protected void buttonPressed(int buttonId) { - switch (buttonId) { - case APPLY_ID: - applyCSS(); - break; - default: - super.buttonPressed(buttonId); - } - } - - private void applyCSS() { - if (themeEngine == null) { - exceptions.setText("No theme engine available!"); - return; - } - long start = System.nanoTime(); - exceptions.setText(""); - - StringBuilder sb = new StringBuilder(); - - // FIXME: expose these new protocols: resetCurrentTheme() and - // getCSSEngines() - ((ThemeEngine) themeEngine).resetCurrentTheme(); - - int count = 0; - for (CSSEngine engine : ((ThemeEngine) themeEngine).getCSSEngines()) { - if (count++ > 0) { - sb.append("\n\n"); - } - sb.append("Engine[").append(engine.getClass().getSimpleName()) - .append("]"); - ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine - .getDocumentCSS(); - List<StyleSheet> sheets = new ArrayList<StyleSheet>(); - StyleSheetList list = doc.getStyleSheets(); - for (int i = 0; i < list.getLength(); i++) { - sheets.add(list.item(i)); - } - - try { - Reader reader = new StringReader(cssText.getText()); - sheets.add(0, engine.parseStyleSheet(reader)); - doc.removeAllStyleSheets(); - for (StyleSheet sheet : sheets) { - doc.addStyleSheet(sheet); - } - engine.reapply(); - - long nanoDiff = System.nanoTime() - start; - sb.append("\nTime: ").append(nanoDiff / 1000000).append("ms"); - } catch (CSSParseException e) { - sb.append("\nError: line ").append(e.getLineNumber()) - .append(" col ").append(e.getColumnNumber()) - .append(": ").append(e.getLocalizedMessage()); - } catch (IOException e) { - sb.append("\nError: ").append(e.getLocalizedMessage()); - } - } - exceptions.setText(sb.toString()); - } - -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyDialog.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyDialog.java deleted file mode 100644 index f5eae299..00000000 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyDialog.java +++ /dev/null @@ -1,983 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 Manumitting Technologies, Inc. - * 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: - * Brian de Alwis (MT) - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.tools.css.spy; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.e4.ui.css.core.dom.CSSStylableElement; -import org.eclipse.e4.ui.css.core.engine.CSSEngine; -import org.eclipse.e4.ui.css.swt.dom.WidgetElement; -import org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.layout.TableColumnLayout; -import org.eclipse.jface.layout.TreeColumnLayout; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.ColumnViewerEditor; -import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy; -import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.TableViewerEditor; -import org.eclipse.jface.viewers.TableViewerFocusCellManager; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.viewers.TreeViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabItem; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.graphics.Region; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.swt.widgets.Widget; -import org.w3c.css.sac.CSSParseException; -import org.w3c.css.sac.SelectorList; -import org.w3c.dom.NodeList; -import org.w3c.dom.css.CSSStyleDeclaration; -import org.w3c.dom.css.CSSValue; - -/** - * - * @deprecated use now cssSpyPart - * - */ -@Deprecated -public class CssSpyDialog extends Dialog { - /** @return the CSS element corresponding to the argument, or null if none */ - public static CSSStylableElement getCSSElement(Object o) { - if (o instanceof CSSStylableElement) { - return (CSSStylableElement) o; - } else { - CSSEngine engine = getCSSEngine(o); - if (engine != null) { - return (CSSStylableElement) engine.getElement(o); - } - } - return null; - } - - /** @return the CSS engine governing the argument, or null if none */ - public static CSSEngine getCSSEngine(Object o) { - CSSEngine engine = null; - if (o instanceof CSSStylableElement) { - CSSStylableElement element = (CSSStylableElement) o; - engine = WidgetElement.getEngine((Widget) element.getNativeWidget()); - } - if (engine == null && o instanceof Widget) { - if (((Widget) o).isDisposed()) { - return null; - } - engine = WidgetElement.getEngine((Widget) o); - } - if (engine == null && Display.getCurrent() != null) { - engine = new CSSSWTEngineImpl(Display.getCurrent()); - } - return engine; - } - - private Display display; - private Widget specimen; - private Widget shown; - - private TreeViewer widgetTreeViewer; - private WidgetTreeProvider widgetTreeProvider; - private Button showAllShells; - private TableViewer cssPropertiesViewer; - private Text cssRules; - - private List<Shell> highlights = new LinkedList<Shell>(); - private List<Region> highlightRegions = new LinkedList<Region>(); - private Text cssSearchBox; - private Button showUnsetProperties; - private Button showCssFragment; - - protected ViewerFilter unsetPropertyFilter = new ViewerFilter() { - - @Override - public boolean select(Viewer viewer, Object parentElement, - Object element) { - if (element instanceof CSSPropertyProvider) { - try { - return ((CSSPropertyProvider) element).getValue() != null; - } catch (Exception e) { - return false; - } - } - return false; - } - }; - - /** - * Create the dialog. - * - * @param parentShell - */ - public CssSpyDialog(Shell parentShell) { - super(parentShell); - display = parentShell.getDisplay(); - setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX); - } - - @Override - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText("CSS Spy"); - } - - public Widget getSpecimen() { - return specimen; - } - - private boolean isLive() { - return specimen == null; - } - - public void setSpecimen(Widget specimen) { - this.specimen = specimen; - update(); - } - - private Widget getActiveSpecimen() { - if (specimen != null) { - return specimen; - } - return display.getCursorControl(); - } - - protected boolean shouldDismissOnLostFocus() { - return false; - } - - protected void update() { - if (getShell() == null) { - return; - } - Widget current = getActiveSpecimen(); - if (shown == current) { - return; - } - shown = current; - - CSSEngine engine = getCSSEngine(shown); - CSSStylableElement element = (CSSStylableElement) engine - .getElement(shown); - if (element == null) { - return; - } - - updateWidgetTreeInput(); - revealAndSelect(Collections.singletonList(shown)); - } - - private <T> void revealAndSelect(List<T> elements) { - widgetTreeViewer.setSelection(new StructuredSelection(elements), true); - } - - private void updateForWidgetSelection(ISelection sel) { - disposeHighlights(); - if (sel.isEmpty()) { - return; - } - StructuredSelection selection = (StructuredSelection) sel; - for (Object s : selection.toList()) { - if (s instanceof Widget) { - highlightWidget((Widget) s); - } - } - populate(selection.size() == 1 - && selection.getFirstElement() instanceof Widget ? (Widget) selection - .getFirstElement() : null); - } - - private void updateWidgetTreeInput() { - if (showAllShells.getSelection()) { - widgetTreeViewer.setInput(display); - } else { - widgetTreeViewer - .setInput(new Object[] { shown instanceof Control ? ((Control) shown) - .getShell() : shown }); - } - performCSSSearch(new NullProgressMonitor()); - } - - protected void populate(Widget selected) { - if (selected == null) { - cssPropertiesViewer.setInput(null); - cssRules.setText(""); - return; - } - if (selected.isDisposed()) { - cssPropertiesViewer.setInput(null); - cssRules.setText("*DISPOSED*"); - return; - } - - CSSStylableElement element = getCSSElement(selected); - if (element == null) { - cssPropertiesViewer.setInput(null); - cssRules.setText("Not a stylable element"); - return; - } - - cssPropertiesViewer.setInput(selected); - - StringBuilder sb = new StringBuilder(); - CSSEngine engine = getCSSEngine(element); - CSSStyleDeclaration decl = engine.getViewCSS().getComputedStyle( - element, null); - - if (element.getCSSStyle() != null) { - sb.append("\nCSS Inline Style(s):\n "); - Activator.join(sb, element.getCSSStyle().split(";"), ";\n "); - } - - if (decl != null) { - sb.append("\n\nCSS Properties:\n"); - try { - if (decl != null) { - sb.append(decl.getCssText()); - } - } catch (Exception e) { - sb.append(e); - } - } - if (element.getStaticPseudoInstances().length > 0) { - sb.append("\n\nStatic Pseudoinstances:\n "); - Activator.join(sb, element.getStaticPseudoInstances(), "\n "); - } - - if (element.getCSSClass() != null) { - sb.append("\n\nCSS Classes:\n "); - Activator.join(sb, element.getCSSClass().split(" +"), "\n "); - } - - if (element.getAttribute("style") != null) { - sb.append("\n\nSWT Style Bits:\n "); - Activator.join(sb, element.getAttribute("style").split(" +"), - "\n "); - } - - sb.append("\n\nCSS Class Element:\n ").append( - element.getClass().getName()); - - // this is useful for diagnosing issues - if (element.getNativeWidget() instanceof Shell - && ((Shell) element.getNativeWidget()).getParent() != null) { - Shell nw = (Shell) element.getNativeWidget(); - sb.append("\n\nShell parent: ").append(nw.getParent()); - } - if (element.getNativeWidget() instanceof Composite) { - Composite nw = (Composite) element.getNativeWidget(); - sb.append("\n\nSWT Layout: ").append(nw.getLayout()); - } - Rectangle bounds = getBounds(selected); - if (bounds != null) { - sb.append("\nBounds: x=").append(bounds.x).append(" y=") - .append(bounds.y); - sb.append(" h=").append(bounds.height).append(" w=") - .append(bounds.width); - } - - if (element.getNativeWidget() instanceof Widget) { - Widget w = (Widget) element.getNativeWidget(); - if (w.getData() != null) { - sb.append("\nWidget data: ").append(w.getData()); - } - if (w.getData(SWT.SKIN_ID) != null) { - sb.append("\nWidget Skin ID (").append(SWT.SKIN_ID) - .append("): ").append(w.getData(SWT.SKIN_ID)); - } - if (w.getData(SWT.SKIN_CLASS) != null) { - sb.append("\nWidget Skin Class (").append(SWT.SKIN_CLASS) - .append("): ").append(w.getData(SWT.SKIN_CLASS)); - } - } - - cssRules.setText(sb.toString().trim()); - - disposeHighlights(); - highlightWidget(selected); - } - - private Shell getShell(Widget widget) { - if (widget instanceof Control) { - return ((Control) widget).getShell(); - } - return null; - } - - /** Add a highlight-rectangle for the selected widget */ - private void highlightWidget(Widget selected) { - if (selected == null || selected.isDisposed()) { - return; - } - - Rectangle bounds = getBounds(selected); // relative to absolute display, - // not the widget - if (bounds == null /* || bounds.height == 0 || bounds.width == 0 */) { - return; - } - // emulate a transparent background as per SWT Snippet180 - Shell selectedShell = getShell(selected); - // create the highlight; want it to appear on top - Shell highlight = new Shell(selectedShell, SWT.NO_TRIM | SWT.MODELESS - | SWT.NO_FOCUS | SWT.ON_TOP); - highlight.setBackground(display.getSystemColor(SWT.COLOR_RED)); - Region highlightRegion = new Region(); - highlightRegion.add(0, 0, 1, bounds.height + 2); - highlightRegion.add(0, 0, bounds.width + 2, 1); - highlightRegion.add(bounds.width + 1, 0, 1, bounds.height + 2); - highlightRegion.add(0, bounds.height + 1, bounds.width + 2, 1); - highlight.setRegion(highlightRegion); - highlight.setBounds(bounds.x - 1, bounds.y - 1, bounds.width + 2, - bounds.height + 2); - highlight.setEnabled(false); - highlight.setVisible(true); // not open(): setVisible() prevents taking - // focus - - highlights.add(highlight); - highlightRegions.add(highlightRegion); - } - - private void disposeHighlights() { - for (Shell highlight : highlights) { - highlight.dispose(); - } - highlights.clear(); - for (Region region : highlightRegions) { - region.dispose(); - } - highlightRegions.clear(); - } - - private Rectangle getBounds(Widget widget) { - if (widget instanceof Shell) { - // Shell bounds are already in display coordinates - return ((Shell) widget).getBounds(); - } else if (widget instanceof Control) { - Control control = (Control) widget; - Rectangle bounds = control.getBounds(); - return control.getDisplay().map(control.getParent(), null, bounds); - } else if (widget instanceof ToolItem) { - ToolItem item = (ToolItem) widget; - Rectangle bounds = item.getBounds(); - return item.getDisplay().map(item.getParent(), null, bounds); - } else if (widget instanceof CTabItem) { - CTabItem item = (CTabItem) widget; - Rectangle bounds = item.getBounds(); - return item.getDisplay().map(item.getParent(), null, bounds); - } - // FIXME: figure out how to map items to a position - return null; - } - - /** - * Create contents of the dialog. - * - * @param parent - */ - @Override - protected Control createDialogArea(Composite parent) { - Composite outer = (Composite) super.createDialogArea(parent); - - Composite top = new Composite(outer, SWT.NONE); - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(top); - cssSearchBox = new Text(top, SWT.BORDER | SWT.SEARCH - | SWT.ICON_SEARCH | SWT.ICON_CANCEL); - cssSearchBox.setMessage("CSS Selector"); - cssSearchBox.setToolTipText("Highlight matching widgets"); - GridDataFactory.fillDefaults().grab(true, false).applyTo(cssSearchBox); - - showAllShells = new Button(top, SWT.CHECK); - showAllShells.setText("All shells"); - GridDataFactory.swtDefaults().applyTo(showAllShells); - GridDataFactory.fillDefaults().applyTo(top); - - SashForm sashForm = new SashForm(outer, SWT.VERTICAL); - sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, - 1)); - - // / THE WIDGET TREE - Composite widgetsComposite = new Composite(sashForm, SWT.NONE); - - widgetTreeViewer = new TreeViewer(widgetsComposite, SWT.BORDER - | SWT.MULTI); - widgetTreeProvider = new WidgetTreeProvider(); - widgetTreeViewer.setContentProvider(widgetTreeProvider); - widgetTreeViewer.setAutoExpandLevel(0); - widgetTreeViewer.getTree().setLinesVisible(true); - widgetTreeViewer.getTree().setHeaderVisible(true); - ColumnViewerToolTipSupport.enableFor(widgetTreeViewer); - - TreeViewerColumn widgetTypeColumn = new TreeViewerColumn( - widgetTreeViewer, SWT.NONE); - widgetTypeColumn.getColumn().setWidth(100); - widgetTypeColumn.getColumn().setText("Widget"); - widgetTypeColumn.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object item) { - CSSStylableElement element = CssSpyDialog.getCSSElement(item); - return element.getLocalName() + " (" - + element.getNamespaceURI() + ")"; - } - }); - - TreeViewerColumn widgetClassColumn = new TreeViewerColumn( - widgetTreeViewer, SWT.NONE); - widgetClassColumn.getColumn().setText("CSS Class"); - widgetClassColumn.getColumn().setWidth(100); - widgetClassColumn.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object item) { - CSSStylableElement element = CssSpyDialog.getCSSElement(item); - if (element.getCSSClass() == null) { - return null; - } - String classes[] = element.getCSSClass().split(" +"); - return classes.length <= 1 ? classes[0] : classes[0] + " (+" - + (classes.length - 1) + " others)"; - } - - @Override - public String getToolTipText(Object item) { - CSSStylableElement element = CssSpyDialog.getCSSElement(item); - if (element == null) { - return null; - } - StringBuilder sb = new StringBuilder(); - sb.append(element.getLocalName()).append(" (") - .append(element.getNamespaceURI()).append(")"); - if (element.getCSSClass() != null) { - sb.append("\nClasses:\n "); - Activator.join(sb, element.getCSSClass().split(" +"), - "\n "); - } - return sb.toString(); - } - }); - - TreeViewerColumn widgetIdColumn = new TreeViewerColumn( - widgetTreeViewer, SWT.NONE); - widgetIdColumn.getColumn().setWidth(100); - widgetIdColumn.getColumn().setText("CSS Id"); - widgetIdColumn.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object item) { - CSSStylableElement element = CssSpyDialog.getCSSElement(item); - return element.getCSSId(); - } - }); - - TreeColumnLayout widgetsTableLayout = new TreeColumnLayout(); - widgetsTableLayout.setColumnData(widgetTypeColumn.getColumn(), - new ColumnWeightData(50)); - widgetsTableLayout.setColumnData(widgetIdColumn.getColumn(), - new ColumnWeightData(40)); - widgetsTableLayout.setColumnData(widgetClassColumn.getColumn(), - new ColumnWeightData(40)); - widgetsComposite.setLayout(widgetsTableLayout); - - // / HEADERS - Composite container = new Composite(sashForm, SWT.NONE); - container.setLayout(new GridLayout(2, true)); - - Label lblCssProperties = new Label(container, SWT.NONE); - lblCssProperties.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, - false, false, 1, 1)); - lblCssProperties.setText("CSS Properties"); - - Label lblCssRules = new Label(container, SWT.NONE); - lblCssRules.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, - false, 1, 1)); - lblCssRules.setText("CSS Rules"); - - // // THE CSS PROPERTIES TABLE - Composite propsComposite = new Composite(container, SWT.BORDER); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); - gridData.minimumHeight = 50; - propsComposite.setLayoutData(gridData); - - cssPropertiesViewer = new TableViewer(propsComposite, SWT.BORDER - | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); - cssPropertiesViewer - .setContentProvider(new CSSPropertiesContentProvider()); - cssPropertiesViewer.getTable().setLinesVisible(true); - cssPropertiesViewer.getTable().setHeaderVisible(true); - cssPropertiesViewer.setComparator(new ViewerComparator()); - - final TextCellEditor textCellEditor = new TextCellEditor( - cssPropertiesViewer.getTable()); - TableViewerEditor - .create(cssPropertiesViewer, - new TableViewerFocusCellManager(cssPropertiesViewer, - new FocusCellOwnerDrawHighlighter( - cssPropertiesViewer)), - new ColumnViewerEditorActivationStrategy( - cssPropertiesViewer), - ColumnViewerEditor.TABBING_HORIZONTAL - | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR - | ColumnViewerEditor.TABBING_VERTICAL - | ColumnViewerEditor.KEYBOARD_ACTIVATION); - - - TableViewerColumn propName = new TableViewerColumn(cssPropertiesViewer, - SWT.NONE); - propName.getColumn().setWidth(100); - propName.getColumn().setText("Property"); - propName.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - return ((CSSPropertyProvider) element).getPropertyName(); - } - }); - - TableViewerColumn propValue = new TableViewerColumn( - cssPropertiesViewer, SWT.NONE); - propValue.getColumn().setWidth(100); - propValue.getColumn().setText("Value"); - propValue.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - try { - return ((CSSPropertyProvider) element).getValue(); - } catch (Exception e) { - System.err.println("Error fetching property: " + element - + ": " + e); - return null; - } - } - }); - propValue.setEditingSupport(new EditingSupport(cssPropertiesViewer) { - @Override - protected CellEditor getCellEditor(Object element) { - // do the fancy footwork here to return an appropriate editor to - // the value-type - return textCellEditor; - } - - @Override - protected boolean canEdit(Object element) { - return true; - } - - @Override - protected Object getValue(Object element) { - try { - String value = ((CSSPropertyProvider) element).getValue(); - return value == null ? "" : value; - } catch (Exception e) { - return ""; - } - } - - @Override - protected void setValue(Object element, Object value) { - try { - if (value == null || ((String) value).trim().length() == 0) { - return; - } - CSSPropertyProvider provider = (CSSPropertyProvider) element; - provider.setValue((String) value); - } catch (Exception e) { - MessageDialog.openError(getShell(), "Error", - "Unable to set property:\n\n" - + e.getMessage()); - } - cssPropertiesViewer.update(element, null); - } - }); - - TableColumnLayout propsTableLayout = new TableColumnLayout(); - propsTableLayout.setColumnData(propName.getColumn(), - new ColumnWeightData(50)); - propsTableLayout.setColumnData(propValue.getColumn(), - new ColumnWeightData(50)); - propsComposite.setLayout(propsTableLayout); - - // / THE CSS RULES - cssRules = new Text(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL - | SWT.MULTI); - cssRules.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, - 1)); - - // / THE CSS PROPERTIES TABLE (again) - showUnsetProperties = new Button(container, SWT.CHECK); - showUnsetProperties.setText("Show unset properties"); - showCssFragment = new Button(container, SWT.PUSH); - showCssFragment.setText("Show CSS fragment"); - showCssFragment - .setToolTipText("Generates CSS rule block for the selected widget"); - - // and for balance - new Label(container, SWT.NONE); - - // / The listeners - - cssSearchBox.addModifyListener(new ModifyListener() { - private Runnable updater; - private IProgressMonitor monitor; - - @Override - public void modifyText(ModifyEvent e) { - if (monitor != null) { - monitor.setCanceled(false); - } - display.timerExec(200, updater = new Runnable() { - @Override - public void run() { - if (updater == this) { - performCSSSearch(monitor = new NullProgressMonitor()); - } - } - }); - } - }); - cssSearchBox.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.ARROW_DOWN - && (e.stateMask & SWT.MODIFIER_MASK) == 0) { - widgetTreeViewer.getControl().setFocus(); - } - } - }); - - widgetTreeViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - updateForWidgetSelection(event.getSelection()); - showCssFragment.setEnabled(!event.getSelection() - .isEmpty()); - } - }); - if (isLive()) { - container.addMouseMoveListener(new MouseMoveListener() { - @Override - public void mouseMove(MouseEvent e) { - update(); - } - }); - } - - if (shouldDismissOnLostFocus()) { - container.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - setReturnCode(Window.OK); - close(); - } - }); - } - container.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.character == SWT.ESC) { - cancelPressed(); - } else if (e.character == SWT.CR | e.character == SWT.LF) { - okPressed(); - } - } - }); - showAllShells.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateWidgetTreeInput(); - } - }); - - outer.addDisposeListener(new DisposeListener() { - @Override - public void widgetDisposed(DisposeEvent e) { - dispose(); - } - }); - - showUnsetProperties.setSelection(true); - showUnsetProperties.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (showUnsetProperties.getSelection()) { - cssPropertiesViewer.removeFilter(unsetPropertyFilter); - } else { - cssPropertiesViewer.addFilter(unsetPropertyFilter); - } - } - }); - - showCssFragment.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - showCssFragment(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - widgetSelected(e); - } - }); - - update(); - sashForm.setWeights(new int[] { 50, 50 }); - widgetTreeViewer.getControl().setFocus(); - return outer; - } - - protected void showCssFragment() { - if (!(widgetTreeViewer.getSelection() instanceof IStructuredSelection) - || widgetTreeViewer.getSelection().isEmpty()) { - return; - } - - StringBuilder sb = new StringBuilder(); - for (Object o : ((IStructuredSelection) widgetTreeViewer.getSelection()) - .toArray()) { - if (o instanceof Widget) { - if (sb.length() > 0) { - sb.append('\n'); - } - addCssFragment((Widget) o, sb); - } - } - TextPopupDialog tpd = new TextPopupDialog(widgetTreeViewer.getControl() - .getShell(), "CSS", sb.toString(), true, - "Escape to dismiss"); - tpd.open(); - } - - private void addCssFragment(Widget w, StringBuilder sb) { - CSSStylableElement element = getCSSElement(w); - if (element == null) { - return; - } - - sb.append(element.getLocalName()); - if (element.getCSSId() != null) { - sb.append("#").append(element.getCSSId()); - } - sb.append(" {"); - - CSSEngine engine = getCSSEngine(element); - // we first check the viewCSS and then the property values - CSSStyleDeclaration decl = engine.getViewCSS().getComputedStyle( - element, null); - - List<String> propertyNames = new ArrayList<String>( - engine.getCSSProperties(element)); - Collections.sort(propertyNames); - - int count = 0; - - // First list the generated properties - for (Iterator<String> iter = propertyNames.iterator(); iter.hasNext();) { - String propertyName = iter.next(); - String genValue = trim(engine.retrieveCSSProperty(element, - propertyName, "")); - String declValue = null; - - if (genValue == null) { - continue; - } - - if (decl != null) { - CSSValue cssValue = decl.getPropertyCSSValue(propertyName); - if (cssValue != null) { - declValue = trim(cssValue.getCssText()); - } - } - if (count == 0) { - sb.append("\n /* actual values */"); - } - sb.append("\n ").append(propertyName).append(": ") - .append(genValue).append(";"); - if (declValue != null) { - sb.append("\t/* declared in CSS: ").append(declValue) - .append(" */"); - } - count++; - iter.remove(); // remove so we don't re-report below - } - - // then list any declared properties; generated properties already - // removed - if (decl != null) { - int declCount = 0; - for (String propertyName : propertyNames) { - String declValue = null; - CSSValue cssValue = decl.getPropertyCSSValue(propertyName); - if (cssValue != null) { - declValue = trim(cssValue.getCssText()); - } - if (declValue == null) { - continue; - } - if (declCount == 0) { - sb.append("\n\n /* declared in CSS rules */"); - } - sb.append("\n ").append(propertyName).append(": ") - .append(declValue).append(";"); - count++; - declCount++; - } - } - sb.append(count > 0 ? "\n}" : "}"); - } - - /** Trim the string; return null if empty */ - private String trim(String s) { - if (s == null) { - return null; - } - s = s.trim(); - return s.length() > 0 ? s : null; - } - - protected void performCSSSearch(IProgressMonitor progress) { - List<Widget> widgets = new ArrayList<Widget>(); - performCSSSearch(progress, cssSearchBox.getText(), widgets); - if (!progress.isCanceled()) { - revealAndSelect(widgets); - } - } - - private void performCSSSearch(IProgressMonitor monitor, String text, - Collection<Widget> results) { - if (text.trim().length() == 0) { - return; - } - widgetTreeViewer.collapseAll(); - Object[] roots = widgetTreeProvider.getElements(widgetTreeViewer - .getInput()); - monitor.beginTask("Searching for \"" + text + "\"", roots.length * 10); - for (Object root : roots) { - if (monitor.isCanceled()) { - return; - } - - CSSStylableElement element = getCSSElement(root); - if (element == null) { - continue; - } - - CSSEngine engine = getCSSEngine(root); - try { - SelectorList selectors = engine.parseSelectors(text); - monitor.worked(2); - processCSSSearch(new SubProgressMonitor(monitor, 8), engine, - selectors, element, null, results); - } catch (CSSParseException e) { - System.out.println(e.toString()); - } catch (IOException e) { - System.out.println(e.toString()); - } - } - monitor.done(); - } - - private void processCSSSearch(IProgressMonitor monitor, CSSEngine engine, - SelectorList selectors, CSSStylableElement element, String pseudo, - Collection<Widget> results) { - if (monitor.isCanceled()) { - return; - } - NodeList children = element.getChildNodes(); - monitor.beginTask("Searching", 5 + 5 * children.getLength()); - boolean matched = false; - for (int i = 0; i < selectors.getLength(); i++) { - if (matched = engine.matches(selectors.item(i), element, pseudo)) { - break; - } - } - if (matched) { - results.add((Widget) element.getNativeWidget()); - } - monitor.worked(5); - for (int i = 0; i < children.getLength(); i++) { - if (monitor.isCanceled()) { - return; - } - processCSSSearch(new SubProgressMonitor(monitor, 5), engine, - selectors, (CSSStylableElement) children.item(i), pseudo, - results); - } - monitor.done(); - } - - protected void dispose() { - disposeHighlights(); - } - - /** - * Create contents of the button bar. - * - * @param parent - */ - @Override - protected void createButtonsForButtonBar(Composite parent) { - createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, - true); - } - - /** - * Return the initial size of the dialog. - */ - @Override - protected Point getInitialSize() { - return new Point(600, 500); - } -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyPart.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyPart.java index 826a328e..9569c123 100644 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyPart.java +++ b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/CssSpyPart.java @@ -874,18 +874,18 @@ public class CssSpyPart Shell controlShell = (control == null) ? display.getActiveShell() : control.getShell(); Shell spyPartShell = outer.getShell(); - if (spyPartShell != controlShell) + if (p != cssPart) + { + // Must remove the highlights if selected + disposeHighlights(); + + } else if (spyPartShell != controlShell) { // A widget has been selected in another shell.. We can display the // corresponding control as a specimen shown = null; setSpecimen(control); } - else if (p != cssPart) - { - // Must remove the highlights if selected - disposeHighlights(); - } } diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenScratchpadHandler.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenScratchpadHandler.java deleted file mode 100644 index b887ec07..00000000 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenScratchpadHandler.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.eclipse.e4.tools.css.spy; - -import javax.inject.Named; - -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.ui.css.swt.theme.IThemeEngine; -import org.eclipse.e4.ui.services.IServiceConstants; -import org.eclipse.swt.widgets.Shell; - -public class OpenScratchpadHandler { - @Execute - public void open(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, - IThemeEngine themeEngine) { - CSSScratchPadWindow scratchpad = new CSSScratchPadWindow(shell, themeEngine); - scratchpad.open(); - } -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenSpyHandler.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenSpyHandler.java deleted file mode 100644 index 96b73496..00000000 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/OpenSpyHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Manumitting Technologies, Inc. - * 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: - * Brian de Alwis (MT) - initial API and implementation - *******************************************************************************/ -package org.eclipse.e4.tools.css.spy; - -import javax.inject.Inject; -import javax.inject.Provider; - -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.core.services.statusreporter.StatusReporter; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; - -public class OpenSpyHandler { - - @Inject - @Optional - protected Display display; - - @Inject - protected IEclipseContext context; - - @Inject - protected Provider<StatusReporter> reporter; - - @Execute - public void openSpy() { - Control control = display.getCursorControl(); - // it may be that only the shell was selected - if (control == null) { - control = display.getActiveShell(); - } - CssSpyDialog spy = new CssSpyDialog(control.getShell()); - spy.setSpecimen(control); - spy.open(); - } -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java deleted file mode 100644 index 5f22f184..00000000 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java +++ /dev/null @@ -1,182 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011,2014 Manumitting Technologies, Inc. - * 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: - * Brian de Alwis (MT) - initial API and implementation - * Lars Vogel <lars.vogel@gmail.com> - Bug 427451 - *******************************************************************************/ -package org.eclipse.e4.tools.css.spy; - -import javax.inject.Inject; - -import org.eclipse.e4.core.di.annotations.Execute; -import org.eclipse.e4.core.di.annotations.Optional; -import org.eclipse.e4.core.services.log.Logger; -import org.eclipse.e4.ui.bindings.EBindingService; -import org.eclipse.e4.ui.model.application.MApplication; -import org.eclipse.e4.ui.model.application.commands.MBindingTable; -import org.eclipse.e4.ui.model.application.commands.MCommand; -import org.eclipse.e4.ui.model.application.commands.MHandler; -import org.eclipse.e4.ui.model.application.commands.MKeyBinding; -import org.eclipse.e4.ui.workbench.modeling.EModelService; - -public class SpyInstaller { - private static final String BUNDLE_ID = "org.eclipse.e4.tools.css.spy"; - public static final String OPEN_SPY_COMMAND_ID = "org.eclipse.e4.css.OpenSpy"; - private static final String SPY_HANDLER_ID = OpenSpyHandler.class.getName(); - private static final String SPY_HANDLER_URI = "bundleclass://" + BUNDLE_ID - + "/" - + OpenSpyHandler.class.getName(); - - public static final String OPEN_SCRATCHPAD_COMMAND_ID = "org.eclipse.e4.css.OpenSctachpad"; - private static final String SCRATCHPAD_HANDLER_ID = OpenScratchpadHandler.class - .getName(); - private static final String SCRATCHPAD_HANDLER_URI = "bundleclass://" - + BUNDLE_ID + "/" - + OpenScratchpadHandler.class.getName(); - private static final String CONTRIBUTOR_URI = "platform:/plugin/" - + BUNDLE_ID; - - @Inject - protected MApplication app; - - @Inject - EModelService modelService; - - @Inject - @Optional - protected Logger logger; - - @Execute - public void execute() { - // rectify situation introduced by bug 376475 - removeBindingTable("bt.org.eclipse.e4.css.OpenSpy"); - - MCommand openSpyCommand = installCommand("Open CSS Spy", - OPEN_SPY_COMMAND_ID); - installHandler(openSpyCommand, SPY_HANDLER_ID, SPY_HANDLER_URI); - - // M1 = Control or Cmd on MacOS X - // M2 = Shift - // M3 = Alt - // M4 = Control on MacOS X, Command on others - installBinding("org.eclipse.ui.contexts.dialogAndWindow", - openSpyCommand, "M2+M3+F5"); - - MCommand openScratchpadCommand = installCommand("Open CSS Scratchpad", - OPEN_SCRATCHPAD_COMMAND_ID); - installHandler(openScratchpadCommand, SCRATCHPAD_HANDLER_ID, SCRATCHPAD_HANDLER_URI); - installBinding("org.eclipse.ui.contexts.dialogAndWindow", - openScratchpadCommand, "M2+M3+F6"); - } - - private void removeBindingTable(String tableId) { - for (MBindingTable table : app.getBindingTables()) { - if (tableId.equals(table.getElementId())) { - app.getBindingTables().remove(table); - return; - } - } - } - - private MCommand installCommand(String label, String commandId) { - for(MCommand cmd : app.getCommands()) { - if (commandId.equals(cmd.getElementId())) { - return cmd; - } - } - - MCommand cmd = modelService.createModelElement(MCommand.class); - cmd.setCommandName(label); - cmd.setElementId(commandId); - cmd.setContributorURI(CONTRIBUTOR_URI); - app.getCommands().add(cmd); - return cmd; - } - - private MHandler installHandler(MCommand cmd, String handlerId, - String handlerURI) { - for(MHandler hdlr : app.getHandlers()) { - if (handlerId.equals(hdlr.getElementId())) { - return hdlr; - } - } - - MHandler hdlr = modelService.createModelElement(MHandler.class); - hdlr.setElementId(handlerId); - hdlr.setContributionURI(handlerURI); - hdlr.setCommand(cmd); - hdlr.setContributorURI(CONTRIBUTOR_URI); - app.getHandlers().add(hdlr); - return hdlr; - } - - private void installBinding(String bindingContextId, MCommand cmd, - String keySeq) { - // there is a one-to-one mapping between binding contexts and - // binding tables, though binding tables may not necessarily - // guaranteed an element id. - MBindingTable bindingTable = null; - for(MBindingTable table : app.getBindingTables()) { - // check if the binding was a user-defined binding, otherwise remove - for (MKeyBinding binding : table.getBindings()) { - if (binding.getCommand() == cmd) { - // if explicitly set or unbound by the user... - if (binding.getTags().contains( - EBindingService.TYPE_ATTR_TAG + ":user")) { - logInfo("Found user-remapped binding for {0} to {1}: not rebinding", - cmd.getElementId(), binding.getKeySequence()); - return; - } else if (binding.getTags().contains( - EBindingService.DELETED_BINDING_TAG)) { - logInfo("User deleted binding for {0}: not rebinding", - cmd.getElementId()); - return; - } - logInfo("Removing existing binding for {0} to {1}", - cmd.getElementId(), binding.getKeySequence()); - table.getBindings().remove(binding); - break; - } - } - if (table.getBindingContext() != null - && bindingContextId.equals(table.getBindingContext() - .getElementId())) { - bindingTable = table; - } - } - - if(bindingTable == null) { - logError("Cannot find table for binding context: {0}", - bindingContextId); - return; - } - - MKeyBinding binding = modelService - .createModelElement(MKeyBinding.class); - binding.setCommand(cmd); - binding.setKeySequence(keySeq); - binding.setElementId("kb." + cmd.getElementId()); - binding.setContributorURI(CONTRIBUTOR_URI); - bindingTable.getBindings().add(binding); - } - - private void logInfo(String message, Object... args) { - if (logger == null) { - return; - } - logger.info(message, args); - } - - private void logError(String message, Object... args) { - if (logger == null) { - return; - } - logger.error(message, args); - } - -} diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/WidgetTreeProvider.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/WidgetTreeProvider.java index f9af9909..cf08a8cc 100644 --- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/WidgetTreeProvider.java +++ b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/WidgetTreeProvider.java @@ -27,10 +27,12 @@ import org.w3c.dom.NodeList; public class WidgetTreeProvider implements ITreeContentProvider { private static final Object[] EMPTY_ARRAY = new Object[0]; - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } - public Object[] getElements(Object inputElement) { + @Override + public Object[] getElements(Object inputElement) { if (inputElement instanceof Object[]) { return (Object[]) inputElement; } else if (inputElement instanceof Collection< ? >) { @@ -40,7 +42,8 @@ public class WidgetTreeProvider implements ITreeContentProvider { } - public Object[] getChildren(Object parentElement) { + @Override + public Object[] getChildren(Object parentElement) { if (parentElement instanceof Display) { List<Shell> shells = new ArrayList<Shell>(); for (Shell s : ((Display) parentElement).getShells()) { @@ -50,7 +53,7 @@ public class WidgetTreeProvider implements ITreeContentProvider { } return shells.toArray(); } - CSSStylableElement element = CssSpyDialog.getCSSElement(parentElement); + CSSStylableElement element = CssSpyPart.getCSSElement(parentElement); if (element == null) { return EMPTY_ARRAY; } @@ -62,7 +65,8 @@ public class WidgetTreeProvider implements ITreeContentProvider { return children.toArray(); } - public Object getParent(Object element) { + @Override + public Object getParent(Object element) { if (element instanceof Control) { Control control = (Control) element; return control.isDisposed() ? null : control.getParent(); @@ -74,11 +78,13 @@ public class WidgetTreeProvider implements ITreeContentProvider { return null; } - public boolean hasChildren(Object element) { + @Override + public boolean hasChildren(Object element) { return getChildren(element).length > 0; } - public void dispose() { + @Override + public void dispose() { } } diff --git a/bundles/org.eclipse.e4.tools.emf.liveeditor/plugin.xml b/bundles/org.eclipse.e4.tools.emf.liveeditor/plugin.xml index da661ebd..f0de5202 100644 --- a/bundles/org.eclipse.e4.tools.emf.liveeditor/plugin.xml +++ b/bundles/org.eclipse.e4.tools.emf.liveeditor/plugin.xml @@ -6,7 +6,7 @@ <spyPart description="Open the live model editor" icon="icons/full/obj16/application_lightning.png" - name="Live Model Editor" + name="Model Spy" part="org.eclipse.e4.tools.emf.liveeditor.LivePartDelegator" shortcut="M2+M3+F9"> </spyPart> diff --git a/bundles/org.eclipse.e4.tools.event.spy/plugin.xml b/bundles/org.eclipse.e4.tools.event.spy/plugin.xml index e5ba6731..51aec65e 100644 --- a/bundles/org.eclipse.e4.tools.event.spy/plugin.xml +++ b/bundles/org.eclipse.e4.tools.event.spy/plugin.xml @@ -7,7 +7,7 @@ description="Open the Event Spy" icon="icons/eventspy.gif" name="Event Spy" - part="org.eclipse.e4.tools.event.spy.internal.ui.SpyDialog" + part="org.eclipse.e4.tools.event.spy.internal.ui.EventSpyPart" shortcut="M2+M3+F8"> </spyPart> </extension> diff --git a/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyDialog.java b/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/EventSpyPart.java index 6b9c9188..bee1bf20 100644 --- a/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyDialog.java +++ b/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/EventSpyPart.java @@ -8,7 +8,9 @@ * Contributors: * IBM Corporation - initial API and implementation * Olivier Prouvost <olivier.prouvost@opcoach.com> - * - Fix bug 428903 : transform this dialog into a part to be definied with spyPart extension + * - Fix bug 428903 : transform this dialog into a part to be defined with spyPart extension + * - Fix Bug 428903 - Having a common debug window for all spies + *******************************************************************************/ package org.eclipse.e4.tools.event.spy.internal.ui; @@ -34,7 +36,7 @@ import org.eclipse.swt.layout.RowData; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; -public class SpyDialog /*extends Dialog */ implements EventMonitor.NewEventListener { +public class EventSpyPart implements EventMonitor.NewEventListener { private final static String DIALOG_TITLE = "Event spy dialog"; private final static String[] SHOW_FILTER_LINK_TEXT = new String[]{"Show filters", "Hide filters"}; @@ -85,7 +87,7 @@ public class SpyDialog /*extends Dialog */ implements EventMonitor.NewEventListe @PostConstruct - protected void createDialogArea(Composite parent, @Optional SpyDialogMemento memento) { + protected void createDialogArea(Composite parent, @Optional SpyPartMemento memento) { // Bug 428903 : create now a part, and inject directly optional memento (set in saveDialogMemento). @@ -102,25 +104,25 @@ public class SpyDialog /*extends Dialog */ implements EventMonitor.NewEventListe @PreDestroy private void saveDialogMemento() { - SpyDialogMemento memento = null; + SpyPartMemento memento = null; String baseTopic = capturedEventFilters.getBaseTopic(); Collection<CapturedEventFilter> filters = capturedEventFilters.getFilters(); IEclipseContext context = appplication.getContext(); if (!CapturedEventFilters.BASE_EVENT_TOPIC.equals(baseTopic)) { - memento = new SpyDialogMemento(); + memento = new SpyPartMemento(); memento.setBaseTopic(baseTopic); } if (!filters.isEmpty()) { if (memento == null) { - memento = new SpyDialogMemento(); + memento = new SpyPartMemento(); } memento.setFilters(filters); } if (memento != null) { - context.set(SpyDialogMemento.class.getName(), memento); - } else if (context.containsKey(SpyDialogMemento.class.getName())) { - context.remove(SpyDialogMemento.class.getName()); + context.set(SpyPartMemento.class.getName(), memento); + } else if (context.containsKey(SpyPartMemento.class.getName())) { + context.remove(SpyPartMemento.class.getName()); } } @@ -156,7 +158,7 @@ public class SpyDialog /*extends Dialog */ implements EventMonitor.NewEventListe }); } - private void createFilters(Composite parent, SpyDialogMemento memento) { + private void createFilters(Composite parent, SpyPartMemento memento) { capturedEventFilters = new CapturedEventFilters(outer); capturedEventFilters.getControl().setVisible(false); GridData gridData = createDefaultGridData(); diff --git a/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyDialogMemento.java b/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyPartMemento.java index a5e437f9..d66ea047 100644 --- a/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyDialogMemento.java +++ b/bundles/org.eclipse.e4.tools.event.spy/src/org/eclipse/e4/tools/event/spy/internal/ui/SpyPartMemento.java @@ -14,7 +14,7 @@ import java.util.Collection; import org.eclipse.e4.tools.event.spy.internal.model.CapturedEventFilter;
-public class SpyDialogMemento {
+public class SpyPartMemento {
private String baseTopic;
private Collection<CapturedEventFilter> filters;
|