private static IResource getAdapter(final IEditorReference ref) { IEditorInput input; try { input = ref.getEditorInput(); } catch (final PartInitException e) { // ignore if factory can't restore input, see bug 461786 return null; } if (input instanceof FileEditorInput) { final FileEditorInput fi = (FileEditorInput) input; final IFile file = fi.getFile(); if (file != null) { return file; } } // here we can only guess how the input might be related to a resource final IFile adapter = Util.getAdapter(input, IFile.class); if (adapter != null) { return adapter; } return Util.getAdapter(input, IResource.class); }
public String getColumnText(Object element, int index) { BindingElement bindingElement = ((BindingElement) element); switch (index) { case COMMAND_NAME_COLUMN: {// name String name = bindingElement.getName(); if (name != null && name.endsWith("()")) { name = name.substring(0, name.length() - 2); } return name; } case KEY_SEQUENCE_COLUMN: // keys TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); case CATEGORY_COLUMN: // category String id = bindingElement.getId(); if (id.equalsIgnoreCase("net.heartsome.cat.ts.command.preference")) { return Messages.getString("preferencepage.KeysPreferencePage.toolCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.lockToolBar")) { return Messages.getString("preferencepage.KeysPreferencePage.toolbarCategory"); } else if (id.equalsIgnoreCase("org.eclipse.ui.window.showKeyAssist")) { return Messages.getString("preferencepage.KeysPreferencePage.helpCategory"); } return bindingElement.getCategory(); } return null; }
final static boolean deletes(final Binding toDelete, final Binding binding) { boolean outDeletes = true; outDeletes &= Util.equals(toDelete.getContextId(), binding.getContextId()); outDeletes &= Util.equals(toDelete.getTriggerSequence(), binding.getTriggerSequence()); if (toDelete.getLocale() != null) { outDeletes &= Util.equals(toDelete.getLocale(), binding.getLocale()); } if (toDelete.getPlatform() != null) { outDeletes &= Util.equals(toDelete.getPlatform(), binding.getPlatform()); } outDeletes &= (binding.getType() == Binding.SYSTEM); outDeletes &= Util.equals(toDelete.getParameterizedCommand(), null); return outDeletes; }
/** * Updates listeners about property changes in the model. * * @param source * Object * @param propId * String * @param inOld * Object * @param inNew * Object */ public void firePropertyChange(final Object source, final String propId, final Object inOld, final Object inNew) { if (!isNotifying()) { return; } if (Util.equals(inOld, inNew)) { return; } final Object[] listeners = getEventManager().getListeners(); final PropertyChangeEvent event = new PropertyChangeEvent(source, propId, inOld, inNew); for (int i = 0; i < listeners.length; i++) { ((IPropertyChangeListener) listeners[i]).propertyChange(event); } }
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { Object result = super.getAdapter(adapter); // restrict delegating to the UI thread for bug 144851 if (result == null && Display.getCurrent() != null) { IEditorPart innerEditor = getActiveEditor(); // see bug 138823 - prevent some subclasses from causing // an infinite loop if (innerEditor != null && innerEditor != this) { result = Util.getAdapter(innerEditor, adapter); } } return result; }
@Override protected Object getValue(Object element) { // System.out.println(element); BindingElement bindingElement = ((BindingElement) element); TriggerSequence seq = bindingElement.getTrigger(); return seq == null ? Util.ZERO_LENGTH_STRING : seq.format(); }
public void firePropertyChange(Object source, String propId, Object oldVal, Object newVal) { if (!isNotifying()) { return; } if (Util.equals(oldVal, newVal)) { return; } Object[] listeners = getEventManager().getListeners(); PropertyChangeEvent event = new PropertyChangeEvent(source, propId, oldVal, newVal); for (int i = 0; i < listeners.length; i++) { ((IPropertyChangeListener) listeners[i]).propertyChange(event); } }
public void exportCSV(Shell shell) { final FileDialog fileDialog = new FileDialog(shell, SWT.SAVE | SWT.SHEET); fileDialog.setFilterExtensions(new String[] { "*.csv" }); //$NON-NLS-1$ fileDialog.setFilterNames(new String[] { Util.translateString(RESOURCE_BUNDLE, "csvFilterName") }); //$NON-NLS-1$ fileDialog.setOverwrite(true); final String filePath = fileDialog.open(); if (filePath == null) { return; } final SafeRunnable runnable = new SafeRunnable() { public final void run() throws IOException { Writer fileWriter = null; try { fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8")); //$NON-NLS-1$ final Object[] bindingElements = bindingModel.getBindings().toArray(); for (int i = 0; i < bindingElements.length; i++) { final BindingElement be = (BindingElement) bindingElements[i]; if (be.getTrigger() == null || be.getTrigger().isEmpty() || be.getContext() == null || be.getContext().getName() == null) { continue; } StringBuffer buffer = new StringBuffer(); buffer.append(ESCAPED_QUOTE + Util.replaceAll(be.getCategory(), ESCAPED_QUOTE, REPLACEMENT) + ESCAPED_QUOTE + DELIMITER); buffer.append(ESCAPED_QUOTE + be.getName() + ESCAPED_QUOTE + DELIMITER); buffer.append(ESCAPED_QUOTE + be.getTrigger().format() + ESCAPED_QUOTE + DELIMITER); buffer.append(ESCAPED_QUOTE + be.getContext().getName() + ESCAPED_QUOTE); buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$ fileWriter.write(buffer.toString()); } } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (final IOException e) { // At least I tried. } } } } }; SafeRunner.run(runnable); }
/** * Exports the key bindings to a CSV file. * * @param inShell * Shell */ public void exportCSV(final Shell inShell) { final FileDialog lFileDialog = new FileDialog(inShell, SWT.SAVE | SWT.SHEET); lFileDialog.setFilterExtensions(new String[] { "*.csv" }); //$NON-NLS-1$ lFileDialog.setFilterNames(new String[] { Util.translateString(RESOURCE_BUNDLE, "csvFilterName") }); //$NON-NLS-1$ lFileDialog.setOverwrite(true); final String lFilePath = lFileDialog.open(); if (lFilePath == null) { return; } final SafeRunnable lRunnable = new SafeRunnable() { @Override public final void run() throws IOException { Writer lFileWriter = null; try { lFileWriter = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(lFilePath), "UTF-8")); //$NON-NLS-1$ final Object[] lBindingElements = bindingModel.getBindings() .toArray(); for (int i = 0; i < lBindingElements.length; i++) { final BindingElement lElement = (BindingElement) lBindingElements[i]; if (lElement.getTrigger() == null || lElement.getTrigger().isEmpty()) { continue; } final StringBuilder lBuffer = new StringBuilder(); lBuffer.append(ESCAPED_QUOTE) .append(Util.replaceAll(lElement.getCategory(), ESCAPED_QUOTE, REPLACEMENT)) .append(ESCAPED_QUOTE).append(DELIMITER); lBuffer.append(ESCAPED_QUOTE).append(lElement.getName()) .append(ESCAPED_QUOTE).append(DELIMITER); lBuffer.append(ESCAPED_QUOTE) .append(lElement.getTrigger().format()) .append(ESCAPED_QUOTE).append(DELIMITER); lBuffer.append(ESCAPED_QUOTE) .append(lElement.getContext() == null ? "" //$NON-NLS-1$ : lElement.getContext().getName()) .append(ESCAPED_QUOTE); lBuffer.append(System.getProperty("line.separator")); //$NON-NLS-1$ lFileWriter.write(lBuffer.toString()); } } finally { if (lFileWriter != null) { try { lFileWriter.close(); } catch (final IOException e) { // At least I tried. } } } } }; SafeRunner.run(lRunnable); }
/** * Returns the implementation of IWorkbenchAdapter for the given object. * @param o * the object to look up. * @return IWorkbenchAdapter or<code>null</code> if the adapter is not defined or the object is not adaptable. */ protected final IWorkbenchAdapter getAdapter(Object o) { return (IWorkbenchAdapter) Util.getAdapter(o, IWorkbenchAdapter.class); }
/** * Returns the implementation of IWorkbenchAdapter2 for the given object. * @param o * the object to look up. * @return IWorkbenchAdapter2 or<code>null</code> if the adapter is not defined or the object is not adaptable. */ protected final IWorkbenchAdapter2 getAdapter2(Object o) { return (IWorkbenchAdapter2) Util.getAdapter(o, IWorkbenchAdapter2.class); }
/** * Returns the implementation of IWorkbenchAdapter3 for the given object. * @param o * the object to look up. * @return IWorkbenchAdapter3 or<code>null</code> if the adapter is not defined or the object is not adaptable. * @since 3.7 */ protected final IWorkbenchAdapter3 getAdapter3(Object o) { return (IWorkbenchAdapter3) Util.getAdapter(o, IWorkbenchAdapter3.class); }