Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2008 IBM Corporation and others. 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: IBM Corporation - initial API and implementation /
 
 package org.eclipse.help.ui.internal.views;
 
 import java.util.List;
 
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 
 public class DynamicHelpPart extends SectionPart implements IHelpPart {
 	private static final String CANCEL_HREF = "__cancel__"//$NON-NLS-1$
 
 	private static final String MORE_HREF = "__more__"//$NON-NLS-1$
 
 
 
 
 	private String id;
 
 	private String phrase;
 
 	private Job runningJob;
 	private IContext context;
 
 	public static final int SHORT_COUNT = 8;
 
 	class JobListener implements IJobChangeListener {
 		public void aboutToRun(IJobChangeEvent event) {
 		}
 
 		public void awake(IJobChangeEvent event) {
 		}
 
 		public void done(IJobChangeEvent event) {
 			if (event.getJob() == ) {
 				 = null;
 			}
 		}
 
 		public void running(IJobChangeEvent event) {
 		}
 
 		public void scheduled(IJobChangeEvent event) {
 		}
 
 		public void sleeping(IJobChangeEvent event) {
 		}
 	}

Parameters:
parent
toolkit
style
	public DynamicHelpPart(Composite parentFormToolkit toolkit) {
		super(parenttoolkit. | .
		// configure section
		Section section = getSection();
		section.marginWidth = 5;
			}
				if (e.getState()) {
				}
			}
		});
		// create 'clear' hyperlink on the section tool bar
		//ImageHyperlink clearLink = new ImageHyperlink(section, SWT.NULL);
		//toolkit.adapt(clearLink, true, true);
		/*
		clearLink.setToolTipText(HelpUIResources
				.getString("SearchPart.clearResults")); //$NON-NLS-1$
		clearLink.setImage(HelpUIResources
				.getImage(IHelpUIConstants.IMAGE_CLEAR));
		clearLink.setBackground(section.getTitleBarGradientBackground());
		clearLink.addHyperlinkListener(new HyperlinkAdapter() {
			public void linkActivated(HyperlinkEvent e) {
				clearResults();
			}
		});
		section.setTextClient(clearLink);
		*/		
		 = toolkit.createFormText(sectionfalse);
		.setImage(topicKey, HelpUIResources.getImage(topicKey));
		.setImage(nwKey, HelpUIResources.getImage(nwKey));
		.setImage(searchKey, HelpUIResources.getImage(searchKey));
			public void linkActivated(HyperlinkEvent e) {
				Object href = e.getHref();
				if (href.equals()) { 
					if ( != null) {
						 = null;
					}
else if (href.equals()) {
else
			}
			public void linkEntered(HyperlinkEvent e) {
			}
			public void linkExited(HyperlinkEvent e) {
			}
		});
		.setText(""falsefalse); //$NON-NLS-1$
	}
	public void dispose() {
		super.dispose();
	}
	public void setFocus() {
		if (!=null)
	}
	public void stop () {
		if (!=null) {
		}		
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.help.ui.internal.views.IHelpPart#getControl()
	 */
	public Control getControl() {
		return getSection();
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.help.ui.internal.views.IHelpPart#init(org.eclipse.help.ui.internal.views.NewReusableHelpPart)
	 */
	public void init(ReusableHelpPart parentString idIMemento memento) {
		this. = parent;
		this. = id;
	}
	public String getId() {
		return ;
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.help.ui.internal.views.IHelpPart#setVisible(boolean)
	 */
	public void setVisible(boolean visible) {
	}
	void clearResults() {
		if ( != null) {
			 = null;
		}
		.setText(""falsefalse); //$NON-NLS-1$
	}
	public void startSearch(String newPhraseIContext excludeContext) {
		if (!=null && .equals(newPhrase))
			return;
		this. = newPhrase;
		this. = excludeContext;
			startInPlaceSearch(excludeContext);
	}
	private void startInPlaceSearch(final String phrase,
			final IContext excludeContext) {
			protected IStatus run(IProgressMonitor monitor) {
				try {
					try {
								monitor);
catch (InterruptedException e) {
						// TODO should we do someting here?
					}
					performSearch(phraseexcludeContextmonitor);
					// it is ok to cancel the search
				}
			}
		};
		job.setSystem(true);
	}
	private void performSearch(String phraseIContext excludeContext,
			IProgressMonitor monitor) {
		SearchQuery searchQuery = new SearchQuery();
		searchQuery.setSearchWord(phrase);
		SearchResults localResults = new SearchResults(null,
				. * 2, Platform.getNL()) {
			public void addHits(List hitsString highlightTerms) {
				// don't highlight any terms for dynamic help part
				super.addHits(hits""); //$NON-NLS-1$
			}
		};
		BaseHelpSystem.getSearchManager().search(searchQuerylocalResults,
				monitor);
		SearchHit[] hits = localResults.getSearchHits();
		updateResults(phraseexcludeContextnew StringBuffer(), hits);
	}
	void scheduleSearch(Job job) {
		if ( != null) {
		}
		StringBuffer buff = new StringBuffer();
		buff.append("<form>"); //$NON-NLS-1$
		buff.append("<p><span color=\""); //$NON-NLS-1$
		buff.append("\">"); //$NON-NLS-1$
		buff.append("</span>"); //$NON-NLS-1$
		buff.append("<a href=\""); //$NON-NLS-1$
		buff.append("\">"); //$NON-NLS-1$
		buff.append("</a></p>"); //$NON-NLS-1$
		buff.append("</form>"); //$NON-NLS-1$
		.setText(buff.toString(), truefalse);
		 = job;
		job.schedule();
	}
	private void updateResults(final String phrase,
			final IContext excludeContextfinal StringBuffer buffer,
			final SearchHit[] hits) {
			return;
		getSection().getDisplay().asyncExec(new Runnable() {
			public void run() {
				doUpdateResults(phraseexcludeContextbufferhits);
			}
		});
	}	
	private void doUpdateResults(String phraseIContext excludeContextStringBuffer buffSearchHit[] hits) {
		if ( != null) {
		}
		this. = phrase;
		buff.delete(0, buff.length());
		if (hits.length > 0) {
			buff.append("<form>"); //$NON-NLS-1$
			buff.append("<p><span color=\""); //$NON-NLS-1$
			buff.append("\">"); //$NON-NLS-1$
			buff.append("</span></p>"); //$NON-NLS-1$
			.sort(nullhits);
			IHelpResource [] excludedTopics = excludeContext!=null?excludeContext.getRelatedTopics():null;
			for (int i = 0; i < hits.lengthi++) {
				SearchHit hit = hits[i];
				if (hit.canOpen()) // Do not list Welcome/Cheatsheets etc.
					continue;
				if (isExcluded(hit.getHref(), excludedTopics))
					continue;
				if (i==)
					break;
				buff.append("<li indent=\"21\" style=\"image\" value=\""); //$NON-NLS-1$
				buff.append("\">"); //$NON-NLS-1$
				buff.append("<a href=\""); //$NON-NLS-1$
				String href = hit.getHref();
				buff.append(href);
				buff.append("\""); //$NON-NLS-1$
				if (hit.getToc()!=null && !Platform.getWS().equals(.)) {
					buff.append(" alt=\""); //$NON-NLS-1$
					buff.append(EscapeUtils.escapeSpecialChars(hit.getToc().getLabel()));
					buff.append("\""); //$NON-NLS-1$
				}
				buff.append(">"); //$NON-NLS-1$
				buff.append(EscapeUtils.escapeSpecialChars(hit.getLabel()));
				buff.append("</a>"); //$NON-NLS-1$
				buff.append("</li>"); //$NON-NLS-1$
			}
			if (hits.length > 0) {
				buff.append("<p><img href=\""); //$NON-NLS-1$
				buff.append("\"/>"); //$NON-NLS-1$
				buff.append(" <a href=\""); //$NON-NLS-1$
				buff.append("\">"); //$NON-NLS-1$
				buff.append("</a></p>"); //$NON-NLS-1$
			}
			buff.append("</form>"); //$NON-NLS-1$
				.setText(buff.toString(), truefalse);
else
				.setText(NLS.bind(.phrase) , falsefalse); 
	}
	private boolean isExcluded(String hrefIHelpResource [] excludedTopics) {
		if (excludedTopics==nullreturn false;
		for (int i=0; i<excludedTopics.lengthi++) {
			if (href.startsWith(excludedTopics[i].getHref()))
				return true;
				if (!HelpBasePlugin.getActivitySupport().isEnabled(href))
					return true;
			}
		}
		return false;
	}
	private void doMore() {
	}
	private void doOpenLink(Object href) {
		String url = (Stringhref;
		if (url.startsWith("nw:")) { //$NON-NLS-1$
else
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.help.ui.internal.views.IHelpPart#fillContextMenu(org.eclipse.jface.action.IMenuManager)
	 */
	public boolean fillContextMenu(IMenuManager manager) {
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.help.ui.internal.views.IHelpPart#hasFocusControl(org.eclipse.swt.widgets.Control)
	 */
	public boolean hasFocusControl(Control control) {
		return .equals(control);
	}
		return null;
	}
	public void toggleRoleFilter() {
	}
	public void refilter() {
		if (!=null && .length() > 0)
	}
	public void saveState(IMemento memento) {
	}
New to GrepCode? Check out our FAQ X