Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 215091 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/editor/toc/TocFileValidator.java (-11 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 48-59 Link Here
48
		}
48
		}
49
		IFile file = (IFile) selection[0];
49
		IFile file = (IFile) selection[0];
50
		// Ensure we have a TOC file
50
		// Ensure we have a TOC file
51
		if (!TocExtensionUtil.isTOCFile(file.getFullPath())) {
51
		if (!HelpEditorUtil.isTOCFile(file.getFullPath())) {
52
			return errorStatus(PDEUIMessages.TocFileValidator_errorInvalidTOC);
52
			return errorStatus(PDEUIMessages.TocFileValidator_errorInvalidTOC);
53
		}
53
		}
54
54
55
		//Ensure that the TOC file selected isn't the current file
55
		//Ensure that the TOC file selected isn't the current file
56
		if (TocExtensionUtil.isCurrentResource(file.getFullPath(), fModel)) {
56
		if (HelpEditorUtil.isCurrentResource(file.getFullPath(), fModel)) {
57
			return errorStatus(PDEUIMessages.TocFileValidator_errorSameTOC);
57
			return errorStatus(PDEUIMessages.TocFileValidator_errorSameTOC);
58
		}
58
		}
59
59
Lines 62-79 Link Here
62
62
63
	}
63
	}
64
64
65
	/**
66
	 * @param message
67
	 * @return
68
	 */
69
	private IStatus errorStatus(String message) {
65
	private IStatus errorStatus(String message) {
70
		return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, message, null);
66
		return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.ERROR, message, null);
71
	}
67
	}
72
68
73
	/**
74
	 * @param message
75
	 * @return
76
	 */
77
	private IStatus okStatus(String message) {
69
	private IStatus okStatus(String message) {
78
		return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, message, null);
70
		return new Status(IStatus.OK, PDEPlugin.getPluginId(), IStatus.OK, message, null);
79
	}
71
	}
(-)src/org/eclipse/pde/internal/ui/editor/toc/TocTreeSection.java (-13 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 356-366 Link Here
356
356
357
				TocObject parent = tocObject.getParent();
357
				TocObject parent = tocObject.getParent();
358
				if (sel.size() == 1 && (tocObject.getType() == ITocConstants.TYPE_TOC || parent.getType() == ITocConstants.TYPE_TOPIC || parent.getType() == ITocConstants.TYPE_TOC)) { /* Semantic rule: 
358
				if (sel.size() == 1 && (tocObject.getType() == ITocConstants.TYPE_TOC || parent.getType() == ITocConstants.TYPE_TOPIC || parent.getType() == ITocConstants.TYPE_TOC)) { /* Semantic rule: 
359
								 * As long as the selection is a child of a 
359
																	 * As long as the selection is a child of a 
360
								 * TOC root or a topic, or the selection itself
360
																	 * TOC root or a topic, or the selection itself
361
								 * is a TOC root, then a new object can be added
361
																	 * is a TOC root, then a new object can be added
362
								 * either to the selection or to the parent
362
																	 * either to the selection or to the parent
363
								 */
363
																	 */
364
					canAddObject = true;
364
					canAddObject = true;
365
				}
365
				}
366
366
Lines 670-682 Link Here
670
		String message = null;
670
		String message = null;
671
671
672
		if (tocFile) {
672
		if (tocFile) {
673
			if (TocExtensionUtil.isTOCFile(path)) {
673
			if (HelpEditorUtil.isTOCFile(path)) {
674
				return true;
674
				return true;
675
			}
675
			}
676
676
677
			message = PDEUIMessages.TocPage_invalidTocFile;
677
			message = PDEUIMessages.TocPage_invalidTocFile;
678
		} else {
678
		} else {
679
			if (TocExtensionUtil.hasValidPageExtension(path)) {
679
			if (HelpEditorUtil.hasValidPageExtension(path)) {
680
				return true;
680
				return true;
681
			}
681
			}
682
682
Lines 739-745 Link Here
739
	 * 
739
	 * 
740
	 * @param dropTarget The target that the drop occurs near/on
740
	 * @param dropTarget The target that the drop occurs near/on
741
	 * @param dropLocation The location of the drop relative to the target
741
	 * @param dropLocation The location of the drop relative to the target
742
	 * @return
742
	 * @return parent
743
	 */
743
	 */
744
	private TocTopic determineParent(TocObject dropTarget, int dropLocation) {
744
	private TocTopic determineParent(TocObject dropTarget, int dropLocation) {
745
		//We must determine what object will be the parent of the
745
		//We must determine what object will be the parent of the
Lines 755-768 Link Here
755
		} else { //In all other cases, it depends on the location of the drop
755
		} else { //In all other cases, it depends on the location of the drop
756
			//relative to the drop target
756
			//relative to the drop target
757
			switch (dropLocation) {
757
			switch (dropLocation) {
758
				case TocDropAdapter.LOCATION_JUST_AFTER : { //if the drop occured after an expanded node
758
				case TocDropAdapter.LOCATION_JUST_AFTER : { //if the drop occurred after an expanded node
759
					//and all of its children,
759
					//and all of its children,
760
					//make the drop target's parent the target parent object
760
					//make the drop target's parent the target parent object
761
					if (!fTocTree.getExpandedState(dropTarget)) {
761
					if (!fTocTree.getExpandedState(dropTarget)) {
762
						return (TocTopic) dropTarget.getParent();
762
						return (TocTopic) dropTarget.getParent();
763
					}
763
					}
764
					//otherwise, the target parent is the drop target,
764
					//otherwise, the target parent is the drop target,
765
					//since the drop occured between it and its first child
765
					//since the drop occurred between it and its first child
766
				}
766
				}
767
				case ViewerDropAdapter.LOCATION_ON : { //the drop location is directly on the drop target
767
				case ViewerDropAdapter.LOCATION_ON : { //the drop location is directly on the drop target
768
					//set the parent object to be the drop target
768
					//set the parent object to be the drop target
Lines 811-821 Link Here
811
				// If the path is to a valid TOC file
811
				// If the path is to a valid TOC file
812
				// and it isn't the file in this model
812
				// and it isn't the file in this model
813
				// then make a link
813
				// then make a link
814
				if (TocExtensionUtil.isTOCFile(path) && !TocExtensionUtil.isCurrentResource(path, fModel)) {
814
				if (HelpEditorUtil.isTOCFile(path) && !HelpEditorUtil.isCurrentResource(path, fModel)) {
815
					tocObjects.add(makeNewTocLink(targetParent, file));
815
					tocObjects.add(makeNewTocLink(targetParent, file));
816
				}
816
				}
817
				// If the path is to a file with an HTML page extension, make a topic
817
				// If the path is to a file with an HTML page extension, make a topic
818
				else if (TocExtensionUtil.hasValidPageExtension(path)) {
818
				else if (HelpEditorUtil.hasValidPageExtension(path)) {
819
					TocTopic topic = makeNewTocTopic(targetParent, file);
819
					TocTopic topic = makeNewTocTopic(targetParent, file);
820
					String title = generateTitle(targetParent, path);
820
					String title = generateTitle(targetParent, path);
821
821
(-)src/org/eclipse/pde/internal/ui/editor/toc/TocExtensionUtil.java (-100 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.pde.internal.ui.editor.toc;
13
14
import java.util.HashSet;
15
import java.util.Locale;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.pde.core.IBaseModel;
19
import org.eclipse.pde.core.IModel;
20
import org.eclipse.pde.internal.core.itoc.ITocConstants;
21
import org.eclipse.pde.internal.ui.util.XMLRootElementMatcher;
22
23
public class TocExtensionUtil {
24
	public static final String[] pageExtensions = {"htm", "shtml", "html", "xhtml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
25
	public static final String tocExtension = "xml"; //$NON-NLS-1$
26
	private static HashSet pageExtensionSet = new HashSet(pageExtensions.length);
27
28
	private static void populateHashSet() {
29
		for (int i = 0; i < pageExtensions.length; ++i) {
30
			pageExtensionSet.add(pageExtensions[i]);
31
		}
32
	}
33
34
	public static boolean hasValidPageExtension(IPath path) {
35
		String fileExtension = path.getFileExtension();
36
		if (fileExtension != null) {
37
			fileExtension = fileExtension.toLowerCase(Locale.ENGLISH);
38
			if (pageExtensionSet.isEmpty()) {
39
				populateHashSet();
40
			}
41
42
			return pageExtensionSet.contains(fileExtension);
43
		}
44
45
		return false;
46
	}
47
48
	private static boolean hasValidTocExtension(IPath path) {
49
		String fileExtension = path.getFileExtension();
50
		return fileExtension != null && fileExtension.equals(tocExtension);
51
	}
52
53
	/**
54
	 * @param file
55
	 */
56
	public static boolean isTOCFile(IPath path) {
57
		if (!hasValidTocExtension(path))
58
			return false;
59
60
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
61
62
		IResource resource = root.findMember(path);
63
		if (resource != null && resource instanceof IFile) {
64
			return XMLRootElementMatcher.fileMatchesElement((IFile) resource, ITocConstants.ELEMENT_TOC);
65
		}
66
67
		return XMLRootElementMatcher.fileMatchesElement(path.toFile(), ITocConstants.ELEMENT_TOC);
68
	}
69
70
	public static boolean isCurrentResource(IPath path, IBaseModel model) {
71
		if (model instanceof IModel) {
72
			IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
73
			IPath fullPath;
74
75
			if (workspacePath.isPrefixOf(path)) {
76
				fullPath = ((IModel) model).getUnderlyingResource().getLocation();
77
			} else {
78
				fullPath = ((IModel) model).getUnderlyingResource().getFullPath();
79
			}
80
81
			return fullPath.equals(path);
82
		}
83
84
		return false;
85
	}
86
87
	public static String getPageExtensionList() {
88
		StringBuffer buf = new StringBuffer();
89
90
		for (int i = 0; i < pageExtensions.length; ++i) {
91
			buf.append('.');
92
			buf.append(pageExtensions[i]);
93
			if (i != pageExtensions.length - 1) {
94
				buf.append(", "); //$NON-NLS-1$
95
			}
96
		}
97
98
		return buf.toString();
99
	}
100
}
(-)src/org/eclipse/pde/internal/ui/editor/toc/TocDropAdapter.java (-5 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 166-179 Link Here
166
					return;
166
					return;
167
				}
167
				}
168
168
169
				if (!TocExtensionUtil.hasValidPageExtension(path) && !TocExtensionUtil.isTOCFile(path)) {
169
				if(!HelpEditorUtil.hasValidPageExtension(path)
170
					event.detail = DND.DROP_NONE;
170
					&& !HelpEditorUtil.isTOCFile(path))
171
				{	event.detail = DND.DROP_NONE;
171
					return;
172
					return;
172
				}
173
				}
173
174
174
				// Make sure that the user isn't dropping a TOC into itself
175
				// Make sure that the user isn't dropping a TOC into itself
175
				if (TocExtensionUtil.isCurrentResource(path, model)) {
176
				if(HelpEditorUtil.isCurrentResource(path, model))
176
					event.detail = DND.DROP_NONE;
177
				{	event.detail = DND.DROP_NONE;
177
					return;
178
					return;
178
				}
179
				}
179
			}
180
			}
(-)src/org/eclipse/pde/internal/ui/editor/toc/details/TocPageFilter.java (-47 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.pde.internal.ui.editor.toc.details;
13
14
import org.eclipse.core.resources.*;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.ViewerFilter;
19
import org.eclipse.pde.internal.ui.editor.toc.TocExtensionUtil;
20
21
public class TocPageFilter extends ViewerFilter {
22
	public boolean select(Viewer viewer, Object parent, Object element) {
23
		if (element instanceof IFile) {
24
			IPath path = ((IFile) element).getFullPath();
25
26
			return TocExtensionUtil.hasValidPageExtension(path);
27
		}
28
29
		if (element instanceof IProject && !((IProject) element).isOpen()) {
30
			return false;
31
		}
32
33
		if (element instanceof IContainer) {
34
			try {
35
				IResource[] resources = ((IContainer) element).members();
36
				for (int i = 0; i < resources.length; i++) {
37
					if (select(viewer, parent, resources[i])) {
38
						return true;
39
					}
40
				}
41
			} catch (CoreException e) {
42
			}
43
		}
44
45
		return false;
46
	}
47
}
(-)src/org/eclipse/pde/internal/ui/editor/toc/details/TocDetails.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 182-188 Link Here
182
		dialog.setAllowMultiple(false);
182
		dialog.setAllowMultiple(false);
183
		dialog.setTitle(PDEUIMessages.TocDetails_browseSelection);
183
		dialog.setTitle(PDEUIMessages.TocDetails_browseSelection);
184
		dialog.setMessage(PDEUIMessages.TocDetails_browseMessage);
184
		dialog.setMessage(PDEUIMessages.TocDetails_browseMessage);
185
		dialog.addFilter(new TocPageFilter());
185
		dialog.addFilter(new HelpEditorFilter());
186
186
187
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
187
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
188
188
(-)src/org/eclipse/pde/internal/ui/editor/toc/details/TocLinkDetails.java (-1 / +1 lines)
Lines 125-131 Link Here
125
		dialog.setAllowMultiple(false);
125
		dialog.setAllowMultiple(false);
126
		dialog.setTitle(PDEUIMessages.TocLinkDetails_browseSelection);
126
		dialog.setTitle(PDEUIMessages.TocLinkDetails_browseSelection);
127
		dialog.setMessage(PDEUIMessages.TocLinkDetails_browseMessage);
127
		dialog.setMessage(PDEUIMessages.TocLinkDetails_browseMessage);
128
		dialog.addFilter(new FileExtensionFilter(TocExtensionUtil.tocExtension));
128
		dialog.addFilter(new FileExtensionFilter(HelpEditorUtil.tocExtension));
129
129
130
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
130
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
131
131
(-)src/org/eclipse/pde/internal/ui/editor/toc/details/TocTopicDetails.java (-6 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-14 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
12
package org.eclipse.pde.internal.ui.editor.toc.details;
11
package org.eclipse.pde.internal.ui.editor.toc.details;
13
12
14
import org.eclipse.core.resources.IFile;
13
import org.eclipse.core.resources.IFile;
Lines 150-159 Link Here
150
149
151
		dialog.setValidator(new FileValidator());
150
		dialog.setValidator(new FileValidator());
152
		dialog.setAllowMultiple(false);
151
		dialog.setAllowMultiple(false);
153
		dialog.setTitle(PDEUIMessages.TocDetails_browseSelection);
152
		dialog.setTitle(PDEUIMessages.TocDetails_browseSelection);  
154
		dialog.setMessage(PDEUIMessages.TocDetails_browseMessage);
153
		dialog.setMessage(PDEUIMessages.TocDetails_browseMessage);  
155
		dialog.addFilter(new TocPageFilter());
154
		dialog.addFilter(new HelpEditorFilter());
156
155
		
157
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
156
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
158
157
159
		if (dialog.open() == Window.OK) {
158
		if (dialog.open() == Window.OK) {
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (+32 lines)
Lines 2405-2410 Link Here
2405
SplashConfigurationSection_msgDecorationTemplateSupport=This template will only work with products built on Eclipse 3.3 and higher
2405
SplashConfigurationSection_msgDecorationTemplateSupport=This template will only work with products built on Eclipse 3.3 and higher
2406
RemoveSplashHandlerBindingAction_msgProgressRemoveProductBindings=Removing product bindings from extension ''{0}'' ...
2406
RemoveSplashHandlerBindingAction_msgProgressRemoveProductBindings=Removing product bindings from extension ''{0}'' ...
2407
CSAbstractPage_msgRegisterThisCheatSheet=Register this cheat sheet
2407
CSAbstractPage_msgRegisterThisCheatSheet=Register this cheat sheet
2408
CtxHelpCommandDetails_command=Command:
2409
CtxHelpCommandDetails_commandDetails=Command Details
2410
CtxHelpCommandDetails_label=Label:
2411
CtxHelpCommandDetails_specifyDisplayLabel=Specify the display label for this command:
2412
CtxHelpCommandDetails_specifyTheCommand=Specify the command to invoke:
2413
CtxHelpContextDetails_contextDetails=Context Details
2414
CtxHelpContextDetails_description=Description:
2415
CtxHelpContextDetails_id=ID:
2416
CtxHelpContextDetails_specifyDescription=Specify the context description that will be displayed to the user:
2417
CtxHelpContextDetails_specifyID=Specify the help context id:
2418
CtxHelpContextDetails_specifyTitle=Override the default title by specifying one here:
2419
CtxHelpContextDetails_title=Title:
2420
CtxHelpDescriptionDetails_description=Description:
2421
CtxHelpDescriptionDetails_specifyDescription=Specify the context description that will be displayed to the user:
2422
CtxHelpPage_contextHelp=Context Help
2423
CtxHelpPage_errorParsing=An error occurred while parsing the context help xml file.
2424
CtxHelpPage_failedToLoad=Failed to load context help contents
2425
CtxHelpTopicDetails_label=Label:
2426
CtxHelpTopicDetails_location=Location:
2427
CtxHelpTopicDetails_specifyLabel=Specify the display label for this topic:
2428
CtxHelpTopicDetails_specifyLocation=Specify the location of an HTML file containing content:
2429
CtxHelpTreeSection_addCommand=Add Command
2430
CtxHelpTreeSection_addContext=Add Context
2431
CtxHelpTreeSection_addTopic=Add Topic
2432
CtxHelpTreeSection_contextHelp=Context Help
2433
CtxHelpTreeSection_defaultCommandName=Help_Command
2434
CtxHelpTreeSection_defaultContextName=Help_Context
2435
CtxHelpTreeSection_defaultTopicName=Help_Topic
2436
CtxHelpTreeSection_editContextHelpStructure=Edit the structure of the context help file in this section.
2437
CtxHelpTreeSection_newCommand=Command
2438
CtxHelpTreeSection_newContext=Context
2439
CtxHelpTreeSection_newTopic=Topic
2408
StateViewPage_requiredBundles=Required Plug-ins
2440
StateViewPage_requiredBundles=Required Plug-ins
2409
StateViewPage_importedPackages=Imported Packages
2441
StateViewPage_importedPackages=Imported Packages
2410
StateViewPage_focusActionToolTip=Focus on selected item
2442
StateViewPage_focusActionToolTip=Focus on selected item
(-)src/org/eclipse/pde/internal/ui/IPDEUIConstants.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 24-29 Link Here
24
	String SIMPLE_CHEAT_SHEET_EDITOR_ID = PLUGIN_ID + ".simpleCheatSheetEditor"; //$NON-NLS-1$
24
	String SIMPLE_CHEAT_SHEET_EDITOR_ID = PLUGIN_ID + ".simpleCheatSheetEditor"; //$NON-NLS-1$
25
	String COMPOSITE_CHEAT_SHEET_EDITOR_ID = PLUGIN_ID + ".compositeCheatSheetEditor"; //$NON-NLS-1$
25
	String COMPOSITE_CHEAT_SHEET_EDITOR_ID = PLUGIN_ID + ".compositeCheatSheetEditor"; //$NON-NLS-1$
26
	String TABLE_OF_CONTENTS_EDITOR_ID = PLUGIN_ID + ".tocEditor"; //$NON-NLS-1$
26
	String TABLE_OF_CONTENTS_EDITOR_ID = PLUGIN_ID + ".tocEditor"; //$NON-NLS-1$
27
	String CONTEXT_HELP_EDITOR_ID = PLUGIN_ID + ".helpContextEditor"; //$NON-NLS-1$
27
	String TARGET_EDITOR_ID = PLUGIN_ID + ".targetEditor"; //$NON-NLS-1$
28
	String TARGET_EDITOR_ID = PLUGIN_ID + ".targetEditor"; //$NON-NLS-1$
28
	String PLUGINS_VIEW_ID = "org.eclipse.pde.ui.PluginsView"; //$NON-NLS-1$
29
	String PLUGINS_VIEW_ID = "org.eclipse.pde.ui.PluginsView"; //$NON-NLS-1$
29
	String DEPENDENCIES_VIEW_ID = "org.eclipse.pde.ui.DependenciesView"; //$NON-NLS-1$
30
	String DEPENDENCIES_VIEW_ID = "org.eclipse.pde.ui.DependenciesView"; //$NON-NLS-1$
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (+64 lines)
Lines 2833-2838 Link Here
2833
2833
2834
	public static String CompilersConfigurationTab_buildPropertiesErrors;
2834
	public static String CompilersConfigurationTab_buildPropertiesErrors;
2835
2835
2836
	public static String CtxHelpCommandDetails_command;
2837
2838
	public static String CtxHelpCommandDetails_commandDetails;
2839
2840
	public static String CtxHelpCommandDetails_label;
2841
2842
	public static String CtxHelpCommandDetails_specifyDisplayLabel;
2843
2844
	public static String CtxHelpCommandDetails_specifyTheCommand;
2845
2846
	public static String CtxHelpContextDetails_contextDetails;
2847
2848
	public static String CtxHelpContextDetails_description;
2849
2850
	public static String CtxHelpContextDetails_id;
2851
2852
	public static String CtxHelpContextDetails_specifyDescription;
2853
2854
	public static String CtxHelpContextDetails_specifyID;
2855
2856
	public static String CtxHelpContextDetails_specifyTitle;
2857
2858
	public static String CtxHelpContextDetails_title;
2859
2860
	public static String CtxHelpDescriptionDetails_description;
2861
2862
	public static String CtxHelpDescriptionDetails_specifyDescription;
2863
2864
	public static String CtxHelpPage_contextHelp;
2865
2866
	public static String CtxHelpPage_errorParsing;
2867
2868
	public static String CtxHelpPage_failedToLoad;
2869
2870
	public static String CtxHelpTopicDetails_label;
2871
2872
	public static String CtxHelpTopicDetails_location;
2873
2874
	public static String CtxHelpTopicDetails_specifyLabel;
2875
2876
	public static String CtxHelpTopicDetails_specifyLocation;
2877
2878
	public static String CtxHelpTreeSection_addCommand;
2879
2880
	public static String CtxHelpTreeSection_addContext;
2881
2882
	public static String CtxHelpTreeSection_addTopic;
2883
2884
	public static String CtxHelpTreeSection_contextHelp;
2885
2886
	public static String CtxHelpTreeSection_defaultCommandName;
2887
2888
	public static String CtxHelpTreeSection_defaultContextName;
2889
2890
	public static String CtxHelpTreeSection_defaultTopicName;
2891
2892
	public static String CtxHelpTreeSection_editContextHelpStructure;
2893
2894
	public static String CtxHelpTreeSection_newCommand;
2895
2896
	public static String CtxHelpTreeSection_newContext;
2897
2898
	public static String CtxHelpTreeSection_newTopic;
2899
2836
	public static String PluginsView_description;
2900
	public static String PluginsView_description;
2837
2901
2838
	public static String TargetProfileWindow_additionalLocations;
2902
	public static String TargetProfileWindow_additionalLocations;
(-)src/org/eclipse/pde/internal/ui/PDELabelProvider.java (-1 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 28-33 Link Here
28
import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
28
import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
29
import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
29
import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
30
import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
30
import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
31
import org.eclipse.pde.internal.core.ictxhelp.ICtxHelpConstants;
31
import org.eclipse.pde.internal.core.ifeature.*;
32
import org.eclipse.pde.internal.core.ifeature.*;
32
import org.eclipse.pde.internal.core.iproduct.IProductFeature;
33
import org.eclipse.pde.internal.core.iproduct.IProductFeature;
33
import org.eclipse.pde.internal.core.iproduct.IProductPlugin;
34
import org.eclipse.pde.internal.core.iproduct.IProductPlugin;
Lines 37-42 Link Here
37
import org.eclipse.pde.internal.core.itoc.ITocConstants;
38
import org.eclipse.pde.internal.core.itoc.ITocConstants;
38
import org.eclipse.pde.internal.core.plugin.ImportObject;
39
import org.eclipse.pde.internal.core.plugin.ImportObject;
39
import org.eclipse.pde.internal.core.text.bundle.*;
40
import org.eclipse.pde.internal.core.text.bundle.*;
41
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
40
import org.eclipse.pde.internal.core.text.toc.TocObject;
42
import org.eclipse.pde.internal.core.text.toc.TocObject;
41
import org.eclipse.pde.internal.core.util.PDETextHelper;
43
import org.eclipse.pde.internal.core.util.PDETextHelper;
42
import org.eclipse.pde.internal.ui.elements.NamedElement;
44
import org.eclipse.pde.internal.ui.elements.NamedElement;
Lines 93-98 Link Here
93
		if (obj instanceof TocObject) {
95
		if (obj instanceof TocObject) {
94
			return getObjectText((TocObject) obj);
96
			return getObjectText((TocObject) obj);
95
		}
97
		}
98
		if (obj instanceof CtxHelpObject) {
99
			return getObjectText((CtxHelpObject) obj);
100
		}
96
		if (obj instanceof FeaturePlugin) {
101
		if (obj instanceof FeaturePlugin) {
97
			return getObjectText((FeaturePlugin) obj);
102
			return getObjectText((FeaturePlugin) obj);
98
		}
103
		}
Lines 288-293 Link Here
288
		return PDETextHelper.translateReadText(obj.getName());
293
		return PDETextHelper.translateReadText(obj.getName());
289
	}
294
	}
290
295
296
	/**
297
	 * @param obj
298
	 */
299
	public String getObjectText(CtxHelpObject obj) {
300
		return PDETextHelper.translateReadText(obj.getName());
301
	}
302
291
	public String getObjectText(FeaturePlugin obj) {
303
	public String getObjectText(FeaturePlugin obj) {
292
		String name = isFullNameModeEnabled() ? obj.getLabel() : obj.getId();
304
		String name = isFullNameModeEnabled() ? obj.getLabel() : obj.getId();
293
		String version = obj.getVersion();
305
		String version = obj.getVersion();
Lines 442-447 Link Here
442
		if (obj instanceof TocObject) {
454
		if (obj instanceof TocObject) {
443
			return getObjectImage((TocObject) obj);
455
			return getObjectImage((TocObject) obj);
444
		}
456
		}
457
		if (obj instanceof CtxHelpObject) {
458
			return getObjectImage((CtxHelpObject) obj);
459
		}
445
		if (obj instanceof ISchemaAttribute) {
460
		if (obj instanceof ISchemaAttribute) {
446
			return getObjectImage((ISchemaAttribute) obj);
461
			return getObjectImage((ISchemaAttribute) obj);
447
		}
462
		}
Lines 717-722 Link Here
717
		}
732
		}
718
	}
733
	}
719
734
735
	/**
736
	 * @param object
737
	 */
738
	private Image getObjectImage(CtxHelpObject object) {
739
		switch (object.getType()) {
740
			case ICtxHelpConstants.TYPE_ROOT : {
741
				return get(PDEPluginImages.DESC_TOC_OBJ);
742
			}
743
			case ICtxHelpConstants.TYPE_CONTEXT : {
744
				return get(PDEPluginImages.DESC_CTXHELP_CONTEXT_OBJ);
745
			}
746
			case ICtxHelpConstants.TYPE_DESCRIPTION : {
747
				return get(PDEPluginImages.DESC_CTXHELP_DESC_OBJ);
748
			}
749
			case ICtxHelpConstants.TYPE_TOPIC : {
750
				return get(PDEPluginImages.DESC_TOC_LEAFTOPIC_OBJ);
751
			}
752
			case ICtxHelpConstants.TYPE_COMMAND : {
753
				return get(PDEPluginImages.DESC_CTXHELP_COMMAND_OBJ);
754
			}
755
			default :
756
				return get(PDEPluginImages.DESC_SIMPLECS_OBJ, F_ERROR);
757
		}
758
	}
759
720
	private Image getObjectImage(ISchemaElement element) {
760
	private Image getObjectImage(ISchemaElement element) {
721
		int flags = 0;
761
		int flags = 0;
722
		if (element instanceof ISchemaObjectReference && ((ISchemaObjectReference) element).getReferencedObject() == null)
762
		if (element instanceof ISchemaObjectReference && ((ISchemaObjectReference) element).getReferencedObject() == null)
(-)src/org/eclipse/pde/internal/ui/PDEPluginImages.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 111-116 Link Here
111
	public static final ImageDescriptor DESC_TOC_LINK_OBJ = create(PATH_OBJ, "toc_link_obj.gif"); //$NON-NLS-1$
111
	public static final ImageDescriptor DESC_TOC_LINK_OBJ = create(PATH_OBJ, "toc_link_obj.gif"); //$NON-NLS-1$
112
	public static final ImageDescriptor DESC_TOC_ANCHOR_OBJ = create(PATH_OBJ, "toc_anchor_obj.gif"); //$NON-NLS-1$
112
	public static final ImageDescriptor DESC_TOC_ANCHOR_OBJ = create(PATH_OBJ, "toc_anchor_obj.gif"); //$NON-NLS-1$
113
113
114
	public static final ImageDescriptor DESC_CTXHELP_CONTEXT_OBJ = create(PATH_OBJ, "ctxhelp_context_obj.gif"); //$NON-NLS-1$
115
	public static final ImageDescriptor DESC_CTXHELP_DESC_OBJ = create(PATH_OBJ, "ctxhelp_desc_obj.gif"); //$NON-NLS-1$
116
	public static final ImageDescriptor DESC_CTXHELP_COMMAND_OBJ = create(PATH_OBJ, "ctxhelp_command_obj.gif"); //$NON-NLS-1$
117
114
	public static final ImageDescriptor DESC_COMGROUP_OBJ = create(PATH_OBJ, "keygroups_obj.gif"); //$NON-NLS-1$
118
	public static final ImageDescriptor DESC_COMGROUP_OBJ = create(PATH_OBJ, "keygroups_obj.gif"); //$NON-NLS-1$
115
	public static final ImageDescriptor DESC_GENCOM_OBJ = create(PATH_OBJ, "command_obj.gif"); //$NON-NLS-1$
119
	public static final ImageDescriptor DESC_GENCOM_OBJ = create(PATH_OBJ, "command_obj.gif"); //$NON-NLS-1$
116
120
(-)src/org/eclipse/pde/internal/ui/wizards/toc/TocHTMLWizardPage.java (-5 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-22 Link Here
16
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.pde.internal.ui.PDEPlugin;
17
import org.eclipse.pde.internal.ui.PDEPlugin;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
19
import org.eclipse.pde.internal.ui.editor.toc.TocExtensionUtil;
19
import org.eclipse.pde.internal.ui.editor.toc.HelpEditorUtil;
20
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
21
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
22
22
Lines 55-63 Link Here
55
			return false;
55
			return false;
56
		}
56
		}
57
57
58
		if (!TocExtensionUtil.hasValidPageExtension(new Path(fLastFilename))) {
58
		if(!HelpEditorUtil.hasValidPageExtension(new Path(fLastFilename)))
59
			String message = NLS.bind(PDEUIMessages.TocHTMLWizardPage_badExtension, TocExtensionUtil.getPageExtensionList());
59
		{	String message = NLS.bind(
60
60
				PDEUIMessages.TocHTMLWizardPage_badExtension, 
61
				HelpEditorUtil.getPageExtensionList());
62
		
61
			setErrorMessage(message);
63
			setErrorMessage(message);
62
			return false;
64
			return false;
63
		}
65
		}
(-)plugin.properties (+1 lines)
Lines 195-200 Link Here
195
composite.cheat.sheat.editor.name = Composite Cheat Sheet Editor
195
composite.cheat.sheat.editor.name = Composite Cheat Sheet Editor
196
196
197
toc.editor = Table of Contents Editor
197
toc.editor = Table of Contents Editor
198
ctxhelp.editor = Context Help Editor
198
199
199
page.name.0 = OSGi Frameworks
200
page.name.0 = OSGi Frameworks
200
201
(-)plugin.xml (+11 lines)
Lines 422-427 Link Here
422
               contentTypeId="org.eclipse.pde.tocFile">
422
               contentTypeId="org.eclipse.pde.tocFile">
423
         </contentTypeBinding>
423
         </contentTypeBinding>
424
      </editor>
424
      </editor>
425
      <editor
426
            class="org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpEditor"
427
            contributorClass="org.eclipse.pde.internal.ui.editor.toc.TocEditorContributor"
428
            default="true"
429
            icon="$nl$/icons/obj16/toc_obj.gif"
430
            id="org.eclipse.pde.ui.ctxHelpEditor"
431
            name="%ctxhelp.editor">
432
         <contentTypeBinding
433
               contentTypeId="org.eclipse.pde.ctxHelpFile">
434
         </contentTypeBinding>
435
      </editor>
425
   </extension>
436
   </extension>
426
   <extension
437
   <extension
427
         point="org.eclipse.ui.views">
438
         point="org.eclipse.ui.views">
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpAbstractDetails.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.pde.core.IModelChangedEvent;
16
import org.eclipse.pde.internal.ui.editor.*;
17
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpTreeSection;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Label;
22
import org.eclipse.ui.forms.IFormPart;
23
import org.eclipse.ui.forms.widgets.*;
24
25
/**
26
 * Abstract details class that acts as the base for the details section of the context
27
 * help editor.  The details section will display a form specific to the current tree
28
 * selection, allowing the user to edit the fields.
29
 * @since 3.4
30
 */
31
public abstract class CtxHelpAbstractDetails extends PDEDetails {
32
33
	/**
34
	 * Number of columns the detail section will have
35
	 */
36
	private static final int NUM_COLUMNS = 3;
37
38
	private CtxHelpTreeSection fMasterSection;
39
	private Section fMainSection;
40
	private String fContextID;
41
42
	public CtxHelpAbstractDetails(CtxHelpTreeSection masterSection, String contextID) {
43
		fMasterSection = masterSection;
44
		fContextID = contextID;
45
		fMainSection = null;
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
50
	 */
51
	public void createContents(Composite parent) {
52
		parent.setLayout(FormLayoutFactory.createDetailsGridLayout(false, 1));
53
		createDetails(parent);
54
		hookListeners();
55
	}
56
57
	/**
58
	 * Create the UI elements for the detail section
59
	 * @param parent parent composite to create the details in
60
	 */
61
	public void createDetails(Composite parent) { // Create the main section
62
		int style = ExpandableComposite.TITLE_BAR;
63
64
		if (getDetailsDescription() != null)
65
			style |= Section.DESCRIPTION;
66
67
		fMainSection = getPage().createUISection(parent, getDetailsTitle(), getDetailsDescription(), style);
68
		// Align the master and details section headers (misalignment caused
69
		// by section toolbar icons)
70
		getPage().alignSectionHeaders(getMasterSection().getSection(), fMainSection);
71
		// Create the container for the main section
72
		Composite sectionClient = getPage().createUISectionContainer(fMainSection, NUM_COLUMNS);
73
		GridData data = new GridData(GridData.FILL_BOTH);
74
		fMainSection.setLayoutData(data);
75
		createFields(sectionClient);
76
77
		// Bind widgets
78
		getManagedForm().getToolkit().paintBordersFor(sectionClient);
79
		fMainSection.setClient(sectionClient);
80
		markDetailsPart(fMainSection);
81
	}
82
83
	/**
84
	 * Subclasses must use this method to create the fields that allow user input.
85
	 * @param parent parent composite
86
	 */
87
	protected abstract void createFields(Composite parent);
88
89
	/**
90
	 * @return the title to display at the top of the details section
91
	 */
92
	protected abstract String getDetailsTitle();
93
94
	/**
95
	 * @return the description to display at the top of the details section
96
	 */
97
	protected abstract String getDetailsDescription();
98
99
	/**
100
	 * Subclasses should add there listeners by overriding this method.
101
	 */
102
	public abstract void hookListeners();
103
104
	/**
105
	 * Subclasses should update the form entries using their CtxHelpObject.  This method
106
	 * should be called from subclasses implementation of {@link #selectionChanged(IFormPart, ISelection)}
107
	 */
108
	public abstract void updateFields();
109
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
112
	 */
113
	public void selectionChanged(IFormPart part, ISelection selection) {
114
		// NO-OP
115
		// Children to override
116
	}
117
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.pde.internal.ui.editor.IContextPart#fireSaveNeeded()
120
	 */
121
	public void fireSaveNeeded() {
122
		markDirty();
123
		getPage().getPDEEditor().fireSaveNeeded(getContextId(), false);
124
	}
125
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.pde.internal.ui.editor.IContextPart#getContextId()
128
	 */
129
	public String getContextId() {
130
		return fContextID;
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.pde.internal.ui.editor.IContextPart#getPage()
135
	 */
136
	public PDEFormPage getPage() {
137
		return (PDEFormPage) getManagedForm().getContainer();
138
	}
139
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.pde.internal.ui.editor.IContextPart#isEditable()
142
	 */
143
	public boolean isEditable() {
144
		return fMasterSection.isEditable();
145
	}
146
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
149
	 */
150
	public void modelChanged(IModelChangedEvent event) {
151
		// NO-OP
152
	}
153
154
	/**
155
	 * @return whether the section is editable
156
	 */
157
	public boolean isEditableElement() {
158
		return fMasterSection.isEditable();
159
	}
160
161
	/**
162
	 * @return the toolkit to use to create the form elements
163
	 */
164
	public FormToolkit getToolkit() {
165
		return getManagedForm().getToolkit();
166
	}
167
168
	/**
169
	 * @return the tree section that controls this details section
170
	 */
171
	public CtxHelpTreeSection getMasterSection() {
172
		return fMasterSection;
173
	}
174
175
	/**
176
	 * Create a new label in the given composite using the appropriate style
177
	 * as defined by the toolkit.
178
	 * @param parent composite to create the label in
179
	 * @param toolkit toolkit that will define the style of the label
180
	 * @param text label text
181
	 */
182
	protected void createLabel(Composite parent, FormToolkit toolkit, String text) {
183
		Label label = toolkit.createLabel(parent, text, SWT.WRAP);
184
		GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
185
		gd.horizontalSpan = NUM_COLUMNS;
186
		label.setLayoutData(gd);
187
	}
188
189
	/**
190
	 * Creates an empty label generating empty space in the parent composite.
191
	 * @param parent composite to create the space in
192
	 */
193
	protected void createSpace(Composite parent) {
194
		createLabel(parent, getManagedForm().getToolkit(), ""); //$NON-NLS-1$
195
	}
196
197
	/**
198
	 * Returns the first object from the selection or <code>null</code>.
199
	 * @param selection selection to get the object from
200
	 * @return first object in the selection or <code>null</code>
201
	 */
202
	protected Object getFirstSelectedObject(ISelection selection) {
203
		// Get the structured selection (obtained from the master tree viewer)
204
		IStructuredSelection structuredSel = ((IStructuredSelection) selection);
205
		// Ensure we have a selection
206
		if (structuredSel == null) {
207
			return null;
208
		}
209
		return structuredSel.getFirstElement();
210
	}
211
212
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpFormOutlinePage.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import java.util.List;
14
import org.eclipse.jface.viewers.ILabelProvider;
15
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpModel;
16
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
17
import org.eclipse.pde.internal.core.util.PDETextHelper;
18
import org.eclipse.pde.internal.ui.editor.FormOutlinePage;
19
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
20
21
/**
22
 * The outline page for the context help editor
23
 * @since 3.4
24
 * @see CtxHelpEditor
25
 */
26
public class CtxHelpFormOutlinePage extends FormOutlinePage {
27
28
	public CtxHelpFormOutlinePage(PDEFormEditor editor) {
29
		super(editor);
30
	}
31
32
	/**
33
	 * Label provider for the outline
34
	 * @author cwindatt
35
	 *
36
	 */
37
	private class CtxHelpLabelProvider extends BasicLabelProvider {
38
		public String getText(Object obj) {
39
			if (obj instanceof CtxHelpObject) {
40
				return PDETextHelper.translateReadText(((CtxHelpObject) obj).getName());
41
			}
42
			return super.getText(obj);
43
		}
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getChildren(java.lang.Object)
48
	 */
49
	protected Object[] getChildren(Object parent) {
50
		if (parent instanceof CtxHelpPage) {
51
			CtxHelpModel model = (CtxHelpModel) fEditor.getAggregateModel();
52
			if (model != null && model.isLoaded()) {
53
				Object[] list = new Object[1];
54
				list[0] = model.getCtxHelpRoot();
55
				return list;
56
			}
57
		} else if (parent instanceof CtxHelpObject) {
58
			List list = ((CtxHelpObject) parent).getChildren();
59
			// List is never null
60
			if (list.size() > 0) {
61
				return list.toArray();
62
			}
63
		}
64
65
		return super.getChildren(parent);
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#createLabelProvider()
70
	 */
71
	public ILabelProvider createLabelProvider() {
72
		return new CtxHelpLabelProvider();
73
	}
74
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.pde.internal.ui.editor.FormOutlinePage#getParentPageId(java.lang.Object)
77
	 */
78
	protected String getParentPageId(Object item) {
79
		return CtxHelpPage.PAGE_ID;
80
	}
81
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpPage.java (+154 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import org.eclipse.jface.text.source.ISourceViewer;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.pde.core.IModelChangedEvent;
17
import org.eclipse.pde.core.IModelChangedListener;
18
import org.eclipse.pde.internal.core.text.*;
19
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpModel;
20
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
21
import org.eclipse.pde.internal.ui.*;
22
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
23
import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
24
import org.eclipse.swt.custom.StyledText;
25
import org.eclipse.ui.forms.IManagedForm;
26
import org.eclipse.ui.forms.editor.FormEditor;
27
import org.eclipse.ui.forms.editor.IFormPage;
28
import org.eclipse.ui.forms.widgets.ScrolledForm;
29
30
/**
31
 * The main page for the context help editor.  Contains a tree displaying the 
32
 * structure of the xml and a details section.  UI elements are handled by 
33
 * CtxHelpBlock.
34
 * @since 3.4
35
 * @see CtxHelpEditor
36
 * @see CtxHelpBlock
37
 */
38
public class CtxHelpPage extends PDEFormPage implements IModelChangedListener {
39
	public static final String PAGE_ID = "ctxHelpPage"; //$NON-NLS-1$
40
41
	private CtxHelpBlock fBlock;
42
43
	public CtxHelpPage(FormEditor editor) {
44
		super(editor, PAGE_ID, PDEUIMessages.TocPage_title);
45
		fBlock = new CtxHelpBlock(this);
46
	}
47
48
	/**
49
	 * @return the CtxHelpBlock containing ui elements
50
	 */
51
	public PDEMasterDetailsBlock getBlock() {
52
		return fBlock;
53
	}
54
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
57
	 */
58
	protected void createFormContent(IManagedForm managedForm) {
59
		ScrolledForm form = managedForm.getForm();
60
		CtxHelpModel model = (CtxHelpModel) getModel();
61
62
		// Ensure the model was loaded properly
63
		if ((model == null) || (model.isLoaded() == false)) {
64
			createFormErrorContent(managedForm, PDEUIMessages.CtxHelpPage_failedToLoad, PDEUIMessages.CtxHelpPage_errorParsing, null);
65
			return;
66
		}
67
68
		// TODO Add Help context
69
		//		PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.TOC_EDITOR);
70
71
		// Create the rest of the actions in the form title area
72
		super.createFormContent(managedForm);
73
		// Form image
74
		form.setImage(PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_CTXHELP_CONTEXT_OBJ));
75
		form.setText(PDEUIMessages.CtxHelpPage_contextHelp);
76
		// Create the master details block
77
		fBlock.createContent(managedForm);
78
		// Force the selection in the masters tree section to load the 
79
		// proper details section
80
		fBlock.getMasterSection().fireSelection();
81
		// Register this page to be informed of model change events
82
		model.addModelChangedListener(this);
83
	}
84
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#dispose()
87
	 */
88
	public void dispose() {
89
		CtxHelpModel model = (CtxHelpModel) getModel();
90
		if (model != null) {
91
			model.removeModelChangedListener(this);
92
		}
93
		super.dispose();
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
98
	 */
99
	public void modelChanged(IModelChangedEvent event) {
100
		fBlock.modelChanged(event);
101
	}
102
103
	/**
104
	 * @return the current selection of the ui block
105
	 */
106
	public ISelection getSelection() {
107
		return fBlock.getSelection();
108
	}
109
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#setActive(boolean)
112
	 */
113
	public void setActive(boolean active) {
114
		super.setActive(active);
115
		if (active) {
116
			IFormPage page = getPDEEditor().findPage(CtxHelpInputContext.CONTEXT_ID);
117
			if (page instanceof CtxHelpSourcePage && ((CtxHelpSourcePage) page).getInputContext().isInSourceMode()) {
118
				ISourceViewer viewer = ((CtxHelpSourcePage) page).getViewer();
119
				if (viewer == null) {
120
					return;
121
				}
122
123
				StyledText text = viewer.getTextWidget();
124
				if (text == null) {
125
					return;
126
				}
127
128
				int offset = text.getCaretOffset();
129
				if (offset < 0) {
130
					return;
131
				}
132
133
				IDocumentRange range = ((CtxHelpSourcePage) page).getRangeElement(offset, true);
134
				if (range instanceof IDocumentAttributeNode) {
135
					range = ((IDocumentAttributeNode) range).getEnclosingElement();
136
				} else if (range instanceof IDocumentTextNode) {
137
					range = ((IDocumentTextNode) range).getEnclosingElement();
138
				}
139
140
				if (range instanceof CtxHelpObject) {
141
					fBlock.getMasterSection().setSelection(new StructuredSelection(range));
142
				}
143
			}
144
		}
145
	}
146
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
149
	 */
150
	protected String getHelpResource() {
151
		// TODO Fix help
152
		return IPDEUIConstants.PLUGIN_DOC_ROOT + "guide/tools/editors/toc_editor/page_toc.htm"; //$NON-NLS-1$
153
	}
154
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpInputContextManager.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import org.eclipse.pde.core.IBaseModel;
14
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
15
import org.eclipse.pde.internal.ui.editor.context.InputContext;
16
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
17
18
/**
19
 * Input context manager for the context help editor.
20
 * @since 3.4
21
 * @see CtxHelpEditor
22
 */
23
public class CtxHelpInputContextManager extends InputContextManager {
24
25
	public CtxHelpInputContextManager(PDEFormEditor editor) {
26
		super(editor);
27
	}
28
29
	/* (non-Javadoc)
30
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContextManager#getAggregateModel()
31
	 */
32
	public IBaseModel getAggregateModel() {
33
		InputContext context = findContext(CtxHelpInputContext.CONTEXT_ID);
34
		if (context == null) {
35
			return null;
36
		}
37
		return context.getModel();
38
	}
39
40
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpContextDetails.java (+143 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpContext;
15
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
17
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpInputContext;
18
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpTreeSection;
19
import org.eclipse.pde.internal.ui.parts.FormEntry;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.ui.forms.IFormPart;
24
25
/**
26
 * Details section for context entries.
27
 * @since 3.4
28
 * @see CtxHelpAbstractDetails
29
 * @see CtxHelpContext
30
 */
31
public class CtxHelpContextDetails extends CtxHelpAbstractDetails {
32
33
	private CtxHelpContext fContext;
34
	private FormEntry fIdEntry;
35
	private FormEntry fTitleEntry;
36
	private FormEntry fDescEntry;
37
38
	public CtxHelpContextDetails(CtxHelpTreeSection masterSection) {
39
		super(masterSection, CtxHelpInputContext.CONTEXT_ID);
40
	}
41
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#createFields(org.eclipse.swt.widgets.Composite)
44
	 */
45
	public void createFields(Composite parent) {
46
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_specifyID);
47
		fIdEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_id, SWT.NONE);
48
		createSpace(parent);
49
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_specifyDescription);
50
		fDescEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_description, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
51
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
52
		data.heightHint = 50;
53
		fDescEntry.getText().setLayoutData(data);
54
		data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
55
		fDescEntry.getLabel().setLayoutData(data);
56
		createSpace(parent);
57
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_specifyTitle);
58
		fTitleEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpContextDetails_title, SWT.NONE);
59
	}
60
61
	/* (non-Javadoc)
62
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsTitle()
63
	 */
64
	protected String getDetailsTitle() {
65
		return PDEUIMessages.CtxHelpContextDetails_contextDetails;
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsDescription()
70
	 */
71
	protected String getDetailsDescription() {
72
		return null;
73
	}
74
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#hookListeners()
77
	 */
78
	public void hookListeners() {
79
		fIdEntry.setFormEntryListener(new FormEntryAdapter(this) {
80
			public void textValueChanged(FormEntry entry) {
81
				if (fContext != null) {
82
					fContext.setID(fIdEntry.getValue());
83
				}
84
			}
85
		});
86
		fDescEntry.setFormEntryListener(new FormEntryAdapter(this) {
87
			public void textValueChanged(FormEntry entry) {
88
				if (fContext != null) {
89
					if (fDescEntry.getValue().trim().length() > 0) {
90
						fContext.setDescription(fDescEntry.getValue());
91
					} else {
92
						// Pass null to delete the description node because it is empty
93
						fContext.setDescription(null);
94
					}
95
				}
96
			}
97
		});
98
		fTitleEntry.setFormEntryListener(new FormEntryAdapter(this) {
99
			public void textValueChanged(FormEntry entry) { // Ensure data object is defined
100
				if (fContext != null) {
101
					fContext.setTitle(fTitleEntry.getValue());
102
				}
103
			}
104
		});
105
	}
106
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#updateFields()
109
	 */
110
	public void updateFields() {
111
		if (fContext != null) {
112
			fIdEntry.setValue(fContext.getId(), true);
113
			fIdEntry.setEditable(isEditableElement());
114
			fDescEntry.setValue(fContext.getDescription(), true);
115
			fDescEntry.setEditable(isEditableElement());
116
			fTitleEntry.setValue(fContext.getTitle(), true);
117
			fTitleEntry.setEditable(isEditableElement());
118
		}
119
	}
120
121
	/* (non-Javadoc)
122
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
123
	 */
124
	public void commit(boolean onSave) {
125
		super.commit(onSave);
126
		// Only required for form entries
127
		fIdEntry.commit();
128
		fDescEntry.commit();
129
		fTitleEntry.commit();
130
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
135
	 */
136
	public void selectionChanged(IFormPart part, ISelection selection) {
137
		Object object = getFirstSelectedObject(selection);
138
		if (object instanceof CtxHelpContext) {
139
			fContext = (CtxHelpContext) object;
140
			updateFields();
141
		}
142
	}
143
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpContentProvider.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import java.util.List;
14
import org.eclipse.jface.viewers.ITreeContentProvider;
15
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpModel;
16
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
17
import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
18
19
/**
20
 * Content provider for the tree section of the context help editor.  Gets the children of 
21
 * each element.
22
 * @since 3.4
23
 * @see CtxHelpTreeSection
24
 */
25
public class CtxHelpContentProvider extends DefaultContentProvider implements ITreeContentProvider {
26
27
	/* (non-Javadoc)
28
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
29
	 */
30
	public Object[] getChildren(Object parentElement) {
31
		if (parentElement instanceof CtxHelpModel) {
32
			CtxHelpObject root = ((CtxHelpModel) parentElement).getCtxHelpRoot();
33
			return new Object[] {root};
34
		} else if (parentElement instanceof CtxHelpObject) {
35
			List list = ((CtxHelpObject) parentElement).getChildren();
36
			return list.toArray();
37
		}
38
		return new Object[0];
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
43
	 */
44
	public Object getParent(Object element) {
45
		if (element instanceof CtxHelpObject) {
46
			return ((CtxHelpObject) element).getParent();
47
		}
48
		return null;
49
	}
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
53
	 */
54
	public boolean hasChildren(Object element) {
55
		return (getChildren(element).length > 0);
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
60
	 */
61
	public Object[] getElements(Object inputElement) {
62
		return getChildren(inputElement);
63
	}
64
65
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpTreeSection.java (+931 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import java.util.*;
14
import java.util.List;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.jface.action.*;
19
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.viewers.*;
21
import org.eclipse.pde.core.IModelChangedEvent;
22
import org.eclipse.pde.internal.core.ictxhelp.ICtxHelpConstants;
23
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
24
import org.eclipse.pde.internal.core.text.ctxhelp.*;
25
import org.eclipse.pde.internal.ui.PDEPlugin;
26
import org.eclipse.pde.internal.ui.PDEUIMessages;
27
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
28
import org.eclipse.pde.internal.ui.editor.TreeSection;
29
import org.eclipse.pde.internal.ui.editor.actions.CollapseAction;
30
import org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractAddAction;
31
import org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpRemoveAction;
32
import org.eclipse.pde.internal.ui.editor.plugin.FormFilteredTree;
33
import org.eclipse.pde.internal.ui.editor.toc.HelpEditorUtil;
34
import org.eclipse.pde.internal.ui.parts.TreePart;
35
import org.eclipse.pde.internal.ui.util.PDELabelUtility;
36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.dnd.DND;
38
import org.eclipse.swt.events.DisposeEvent;
39
import org.eclipse.swt.events.DisposeListener;
40
import org.eclipse.swt.graphics.Cursor;
41
import org.eclipse.swt.widgets.*;
42
import org.eclipse.ui.PartInitException;
43
import org.eclipse.ui.PlatformUI;
44
import org.eclipse.ui.actions.ActionFactory;
45
import org.eclipse.ui.actions.ContributionItemFactory;
46
import org.eclipse.ui.dialogs.PatternFilter;
47
import org.eclipse.ui.forms.widgets.FormToolkit;
48
import org.eclipse.ui.forms.widgets.Section;
49
import org.eclipse.ui.ide.IDE;
50
import org.eclipse.ui.keys.IBindingService;
51
52
/**
53
 * Tree section for the context help editor.  Displays the structure
54
 * of the xml file and adds actions allowing manipulation of the structure.
55
 * @since 3.4
56
 * @see CtxHelpEditor
57
 */
58
public class CtxHelpTreeSection extends TreeSection {
59
	private CtxHelpModel fModel;
60
	private TreeViewer fTree;
61
	private FormFilteredTree fFilteredTree;
62
63
	/* The indices for each button attached to the Tree Viewer.
64
	 * This type of UI form does not permit direct access to each particular
65
	 * button. However, using these indices, one can perform any typical SWT
66
	 * operation on any button.
67
	 */
68
	private static final int F_BUTTON_ADD_CONTEXT = 0;
69
	private static final int F_BUTTON_ADD_TOPIC = 2;
70
	private static final int F_BUTTON_ADD_COMMAND = 3;
71
	private static final int F_BUTTON_REMOVE = 5;
72
	private static final int F_BUTTON_UP = 6;
73
	private static final int F_BUTTON_DOWN = 7;
74
75
	// When one of the move buttons is pressed, a flag is used to determine the direction
76
	private static final int F_UP_FLAG = -1;
77
	private static final int F_DOWN_FLAG = 1;
78
79
	// The actions that will add each type of object
80
	private CtxHelpAbstractAddAction fAddContextAction;
81
	private CtxHelpAbstractAddAction fAddTopicAction;
82
	private CtxHelpAbstractAddAction fAddCommandAction;
83
84
	// The object removal action
85
	private CtxHelpRemoveAction fRemoveObjectAction;
86
87
	// The action for opening a link from the context menu
88
	private OpenLinkAction fOpenLinkAction;
89
90
	// Used to temporarily store the target of a drop operation 
91
	// so that it does not have be be recalculated
92
	private CtxHelpObject fDropTargetParent;
93
	private CtxHelpObject fDropTargetSibling;
94
95
	/** If items are dragged and dropped within this tree, then
96
	 * this flag inhibits reselection on the removal (drag) action,
97
	 * thus ensuring that the selected objects are the ones that were
98
	 * dropped.
99
	 */
100
	private boolean fDragFromHere;
101
102
	/**
103
	 * Action that allows a linked file to be opened in the editor
104
	 * @since 3.4
105
	 */
106
	class OpenLinkAction extends Action {
107
		private CtxHelpTopic fOpenTarget;
108
109
		public OpenLinkAction() {
110
			super(PDEUIMessages.Actions_open_label);
111
		}
112
113
		public void setTarget(CtxHelpTopic target) {
114
			fOpenTarget = target;
115
		}
116
117
		public void run() {
118
			if (fOpenTarget != null) {
119
				open(fOpenTarget);
120
			}
121
		}
122
	}
123
124
	public CtxHelpTreeSection(PDEFormPage formPage, Composite parent) {
125
		super(formPage, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.CtxHelpTreeSection_addContext, null, PDEUIMessages.CtxHelpTreeSection_addTopic, PDEUIMessages.CtxHelpTreeSection_addCommand, null, PDEUIMessages.TocPage_remove, PDEUIMessages.TocPage_up, PDEUIMessages.TocPage_down});
126
	}
127
128
	/* (non-Javadoc)
129
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
130
	 */
131
	protected void createClient(Section section, FormToolkit toolkit) {
132
		fModel = (CtxHelpModel) getPage().getModel();
133
134
		Composite container = createClientContainer(section, 2, toolkit);
135
		createTree(container, toolkit);
136
		toolkit.paintBordersFor(container);
137
138
		section.setText(PDEUIMessages.CtxHelpTreeSection_contextHelp);
139
		section.setDescription(PDEUIMessages.CtxHelpTreeSection_editContextHelpStructure);
140
		section.setClient(container);
141
142
		createCommands();
143
144
		initializeTreeViewer();
145
		createSectionToolbar(section, toolkit);
146
147
		// Create the adapted listener for the filter entry field
148
		fFilteredTree.createUIListenerEntryFilter(this);
149
	}
150
151
	/**
152
	 * Creates the commands used in this section.
153
	 */
154
	private void createCommands() {
155
		fAddContextAction = new CtxHelpAbstractAddAction() {
156
			public void run() {
157
				if (fParentObject != null) {
158
					CtxHelpContext context = fParentObject.getModel().getFactory().createContext();
159
					String id = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultContextName);
160
					context.setID(id);
161
					addChild(context);
162
				}
163
			}
164
		};
165
		fAddContextAction.setText(PDEUIMessages.CtxHelpTreeSection_newContext);
166
		fAddTopicAction = new CtxHelpAbstractAddAction() {
167
			public void run() {
168
				if (fParentObject != null) {
169
					CtxHelpTopic topic = fParentObject.getModel().getFactory().createTopic();
170
					String label = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultTopicName);
171
					topic.setLabel(label);
172
					addChild(topic);
173
				}
174
			}
175
		};
176
		fAddTopicAction.setText(PDEUIMessages.CtxHelpTreeSection_newTopic);
177
		fAddCommandAction = new CtxHelpAbstractAddAction() {
178
			public void run() {
179
				if (fParentObject != null) {
180
					CtxHelpCommand command = fParentObject.getModel().getFactory().createCommand();
181
					String label = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultCommandName);
182
					command.setLabel(label);
183
					addChild(command);
184
				}
185
			}
186
		};
187
		fAddCommandAction.setText(PDEUIMessages.CtxHelpTreeSection_newCommand);
188
189
		fRemoveObjectAction = new CtxHelpRemoveAction();
190
		fOpenLinkAction = new OpenLinkAction();
191
	}
192
193
	/**
194
	 * Adds a link (with hand cursor) for tree 'Collapse All' action,
195
	 * which collapses the tree down to the second level
196
	 * 
197
	 * @param section The section that the toolbar will belong to
198
	 * @param toolkit The toolkit that will be used to make the toolbar
199
	 */
200
	private void createSectionToolbar(Section section, FormToolkit toolkit) {
201
		ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
202
		ToolBar toolbar = toolBarManager.createControl(section);
203
204
		final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND);
205
		toolbar.setCursor(handCursor);
206
		// Cursor needs to be explicitly disposed
207
		toolbar.addDisposeListener(new DisposeListener() {
208
			public void widgetDisposed(DisposeEvent e) {
209
				if ((handCursor != null) && (handCursor.isDisposed() == false)) {
210
					handCursor.dispose();
211
				}
212
			}
213
		});
214
215
		// Add collapse action to the tool bar
216
		toolBarManager.add(new CollapseAction(fTree, PDEUIMessages.ExtensionsPage_collapseAll, 1, fModel.getCtxHelpRoot()));
217
		toolBarManager.update(true);
218
		section.setTextClient(toolbar);
219
	}
220
221
	/**
222
	 * Create the tree widget that will contain the structure
223
	 * 
224
	 * @param container The container of the tree widget
225
	 * @param toolkit The toolkit used to create the tree
226
	 */
227
	private void createTree(Composite container, FormToolkit toolkit) {
228
		TreePart treePart = getTreePart();
229
		createViewerPartControl(container, SWT.MULTI, 2, toolkit);
230
231
		fTree = treePart.getTreeViewer();
232
		fTree.setContentProvider(new CtxHelpContentProvider());
233
		fTree.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
234
235
		PDEPlugin.getDefault().getLabelProvider().connect(this);
236
237
		// Create listener for the outline view 'link with editor' toggle button
238
		fTree.addPostSelectionChangedListener(getPage().getPDEEditor().new PDEFormEditorChangeListener());
239
	}
240
241
	/* (non-Javadoc)
242
	 * @see org.eclipse.pde.internal.ui.editor.TreeSection#createTreeViewer(org.eclipse.swt.widgets.Composite, int)
243
	 */
244
	protected TreeViewer createTreeViewer(Composite parent, int style) {
245
		fFilteredTree = new FormFilteredTree(parent, style, new PatternFilter());
246
		parent.setData("filtered", Boolean.TRUE); //$NON-NLS-1$
247
		return fFilteredTree.getViewer();
248
	}
249
250
	/**
251
	 * Initialize the tree viewer widget and its buttons.
252
	 */
253
	private void initializeTreeViewer() {
254
		if (fModel == null) {
255
			return;
256
		}
257
258
		CtxHelpRoot root = fModel.getCtxHelpRoot();
259
		fTree.setInput(root);
260
261
		// Buttons must be disabled if file is not editable
262
		getTreePart().setButtonEnabled(F_BUTTON_ADD_CONTEXT, isEditable());
263
		getTreePart().setButtonEnabled(F_BUTTON_ADD_COMMAND, isEditable());
264
		getTreePart().setButtonEnabled(F_BUTTON_ADD_TOPIC, isEditable());
265
266
		getTreePart().setButtonEnabled(F_BUTTON_REMOVE, false);
267
		getTreePart().setButtonEnabled(F_BUTTON_UP, false);
268
		getTreePart().setButtonEnabled(F_BUTTON_DOWN, false);
269
	}
270
271
	/* (non-Javadoc)
272
	 * @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object)
273
	 */
274
	public boolean setFormInput(Object object) {
275
		// This method allows the outline view to select items in the tree
276
		// (Invoked by org.eclipse.ui.forms.editor.IFormPage.selectReveal(Object object))
277
		if (object instanceof CtxHelpObject) {
278
			fTree.setSelection(new StructuredSelection(object), true);
279
280
			// Verify that something was actually selected
281
			ISelection selection = fTree.getSelection();
282
			if (selection != null && !selection.isEmpty()) {
283
				return true;
284
			}
285
		}
286
		return false;
287
	}
288
289
	/**
290
	 * @return the selection of the tree
291
	 */
292
	public ISelection getSelection() {
293
		return fTree.getSelection();
294
	}
295
296
	/**
297
	 * @param selection the new selection for the tree section
298
	 */
299
	public void setSelection(ISelection selection) {
300
		fTree.setSelection(selection);
301
	}
302
303
	/**
304
	 * Fire a selection change event and refresh the viewer's selection
305
	 */
306
	public void fireSelection() {
307
		fTree.setSelection(fTree.getSelection());
308
	}
309
310
	/* (non-Javadoc)
311
	 * @see org.eclipse.pde.internal.ui.editor.TreeSection#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
312
	 */
313
	protected void selectionChanged(IStructuredSelection selection) {
314
		getPage().getPDEEditor().setSelection(selection);
315
		updateButtons();
316
	}
317
318
	/**
319
	 * Update the buttons in the section based on the current selection
320
	 */
321
	public void updateButtons() {
322
		if (!fModel.isEditable()) {
323
			return;
324
		}
325
326
		IStructuredSelection selection = (IStructuredSelection) fTree.getSelection();
327
		CtxHelpObject firstSelectedObject = (CtxHelpObject) selection.getFirstElement();
328
329
		// Add Context
330
		getTreePart().setButtonEnabled(F_BUTTON_ADD_CONTEXT, true);
331
332
		// Add Topic
333
		boolean enableAdd = false;
334
		if (firstSelectedObject != null) {
335
			if (firstSelectedObject.canAddSibling(ICtxHelpConstants.TYPE_TOPIC)) {
336
				enableAdd = true;
337
			} else if (firstSelectedObject.canAddChild(ICtxHelpConstants.TYPE_TOPIC)) {
338
				enableAdd = true;
339
			}
340
		}
341
		getTreePart().setButtonEnabled(F_BUTTON_ADD_TOPIC, enableAdd);
342
343
		// Add Command
344
		enableAdd = false;
345
		if (firstSelectedObject != null) {
346
			if (firstSelectedObject.canAddSibling(ICtxHelpConstants.TYPE_COMMAND)) {
347
				enableAdd = true;
348
			} else if (firstSelectedObject.canAddChild(ICtxHelpConstants.TYPE_COMMAND)) {
349
				enableAdd = true;
350
			}
351
		}
352
		getTreePart().setButtonEnabled(F_BUTTON_ADD_COMMAND, enableAdd);
353
354
		// Remove button
355
		getTreePart().setButtonEnabled(F_BUTTON_REMOVE, getRemovableObjectFromSelection(selection).size() > 0);
356
357
		// Up and Down buttons
358
		boolean canMoveUp = true;
359
		boolean canMoveDown = true;
360
		if (firstSelectedObject == null || firstSelectedObject.getType() == ICtxHelpConstants.TYPE_ROOT || firstSelectedObject.getType() == ICtxHelpConstants.TYPE_DESCRIPTION || selection.size() > 1) {
361
			canMoveUp = false;
362
			canMoveDown = false;
363
		} else {
364
			CtxHelpObject parent = firstSelectedObject.getParent();
365
			if (parent != null) {
366
				if (parent.isFirstChildNode(firstSelectedObject, firstSelectedObject.getClass())) {
367
					canMoveUp = false;
368
				}
369
				if (parent.isLastChildNode(firstSelectedObject, firstSelectedObject.getClass())) {
370
					canMoveDown = false;
371
				}
372
			}
373
		}
374
		getTreePart().setButtonEnabled(F_BUTTON_UP, canMoveUp);
375
		getTreePart().setButtonEnabled(F_BUTTON_DOWN, canMoveDown);
376
	}
377
378
	/* (non-Javadoc)
379
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#fillContextMenu(org.eclipse.jface.action.IMenuManager)
380
	 */
381
	protected void fillContextMenu(IMenuManager manager) {
382
		IStructuredSelection selection = (IStructuredSelection) fTree.getSelection();
383
		Object object = selection.getFirstElement();
384
		// Has to be null or a CtxHelpObject object
385
		CtxHelpObject firstSelectedObject = (CtxHelpObject) object;
386
387
		// Populate the "New" sub-menu
388
		if (firstSelectedObject != null) {
389
			MenuManager submenu = new MenuManager(PDEUIMessages.Menus_new_label);
390
			boolean addMenu = false;
391
			if (updateAddContextActionWithSelection(firstSelectedObject)) {
392
				submenu.add(fAddContextAction);
393
				addMenu = true;
394
			}
395
			if (updateAddTopicActionWithSelection(firstSelectedObject)) {
396
				submenu.add(fAddTopicAction);
397
				addMenu = true;
398
			}
399
			if (updateAddCommandActionWithSelection(firstSelectedObject)) {
400
				submenu.add(fAddCommandAction);
401
				addMenu = true;
402
			}
403
			if (addMenu) {
404
				manager.add(submenu);
405
				manager.add(new Separator());
406
			}
407
		}
408
409
		// Add the open link and show in actions
410
		if (firstSelectedObject instanceof CtxHelpTopic && ((CtxHelpTopic) firstSelectedObject).getLocation() != null) {
411
			fOpenLinkAction.setTarget((CtxHelpTopic) firstSelectedObject);
412
			manager.add(fOpenLinkAction);
413
			fillContextMenuShowInAction(manager);
414
			manager.add(new Separator());
415
		}
416
417
		// Add clipboard actions
418
		getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager);
419
		manager.add(new Separator());
420
421
		// Add remove action
422
		if (updateRemoveActionWithSelection(selection)) {
423
			manager.add(fRemoveObjectAction);
424
			manager.add(new Separator());
425
		}
426
427
	}
428
429
	/**
430
	 * Creates and a new submenu in the given menu manager and adds actions to
431
	 * allow a linked file to be opened in various views.
432
	 * @param manager menu manager to add the submenu to
433
	 */
434
	private void fillContextMenuShowInAction(IMenuManager manager) {
435
		String showInLabel = PDEUIMessages.PluginsView_showIn;
436
437
		// Add a label for the keybinding for Show In action, if one exists
438
		IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class);
439
		if (bindingService != null) {
440
			String keyBinding = bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$
441
			if (keyBinding != null) {
442
				showInLabel += '\t' + keyBinding;
443
			}
444
		}
445
446
		IMenuManager showInMenu = new MenuManager(showInLabel);
447
		showInMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getPage().getSite().getWorkbenchWindow()));
448
449
		manager.add(showInMenu);
450
	}
451
452
	/**
453
	 * Updates the add context action if the action should be available for the selection.
454
	 * Updates enablement, parent object and target object.  Returns true if the action
455
	 * should be available to the selection. 
456
	 * @param selectedObject selected object
457
	 * @return true if the action should be available for the current selection, false otherwise
458
	 */
459
	private boolean updateAddContextActionWithSelection(CtxHelpObject selectedObject) {
460
		if (selectedObject != null && selectedObject.canAddSibling(ICtxHelpConstants.TYPE_CONTEXT)) {
461
			fAddContextAction.setParentObject(selectedObject.getParent());
462
			fAddContextAction.setTargetObject(selectedObject);
463
			fAddContextAction.setEnabled(fModel.isEditable());
464
			return true;
465
		} else if (selectedObject != null && selectedObject.canAddChild(ICtxHelpConstants.TYPE_CONTEXT)) {
466
			fAddContextAction.setParentObject(selectedObject);
467
			fAddContextAction.setTargetObject(null);
468
			fAddContextAction.setEnabled(fModel.isEditable());
469
			return true;
470
		} else if (fModel.getCtxHelpRoot().canAddChild(ICtxHelpConstants.TYPE_CONTEXT)) {
471
			fAddContextAction.setParentObject(fModel.getCtxHelpRoot());
472
			fAddContextAction.setTargetObject(null);
473
			fAddContextAction.setEnabled(fModel.isEditable());
474
			return true;
475
		}
476
		return false;
477
	}
478
479
	/**
480
	 * Updates the add topic action if the action should be available for the selection.
481
	 * Updates enablement, parent object and target object.  Returns true if the action
482
	 * should be available to the selection. 
483
	 * @param selectedObject selected object
484
	 * @return true if the action should be available for the current selection, false otherwise
485
	 */
486
	private boolean updateAddTopicActionWithSelection(CtxHelpObject selectedObject) {
487
		if (selectedObject != null) {
488
			if (selectedObject.canAddSibling(ICtxHelpConstants.TYPE_TOPIC)) {
489
				fAddTopicAction.setParentObject(selectedObject.getParent());
490
				fAddTopicAction.setTargetObject(selectedObject);
491
				fAddTopicAction.setEnabled(fModel.isEditable());
492
				return true;
493
			} else if (selectedObject.canAddChild(ICtxHelpConstants.TYPE_TOPIC)) {
494
				fAddTopicAction.setParentObject(selectedObject);
495
				fAddTopicAction.setTargetObject(null);
496
				fAddTopicAction.setEnabled(fModel.isEditable());
497
				return true;
498
			}
499
		}
500
		return false;
501
	}
502
503
	/**
504
	 * Updates the add topic action if the action should be available for the selection.
505
	 * Updates enablement, parent object and target object.  Returns true if the action
506
	 * should be available to the selection. 
507
	 * @param selectedObject selected object
508
	 * @return true if the action should be available for the current selection, false otherwise
509
	 */
510
	private boolean updateAddCommandActionWithSelection(CtxHelpObject selectedObject) {
511
		if (selectedObject != null) {
512
			if (selectedObject.canAddSibling(ICtxHelpConstants.TYPE_COMMAND)) {
513
				fAddCommandAction.setParentObject(selectedObject.getParent());
514
				fAddCommandAction.setTargetObject(selectedObject);
515
				fAddCommandAction.setEnabled(fModel.isEditable());
516
				return true;
517
			} else if (selectedObject.canAddChild(ICtxHelpConstants.TYPE_COMMAND)) {
518
				fAddCommandAction.setParentObject(selectedObject);
519
				fAddCommandAction.setTargetObject(null);
520
				fAddCommandAction.setEnabled(fModel.isEditable());
521
				return true;
522
			}
523
		}
524
		return false;
525
	}
526
527
	/**
528
	 * Updates the remove action if the action should be available for the selection.
529
	 * Updates enablement, parent object and target object.  Returns true if the action
530
	 * should be available to the selection. 
531
	 * @param selectedObject selected object
532
	 * @return true if the action should be available for the current selection, false otherwise
533
	 */
534
	private boolean updateRemoveActionWithSelection(IStructuredSelection selection) {
535
		List objectsToRemove = getRemovableObjectFromSelection(selection);
536
		fRemoveObjectAction.setToRemove((CtxHelpObject[]) objectsToRemove.toArray(new CtxHelpObject[objectsToRemove.size()]));
537
		fRemoveObjectAction.setEnabled(fModel.isEditable());
538
		return objectsToRemove.size() > 0;
539
	}
540
541
	/**
542
	 * Returns a list of objects that is the subset of objects in the selection that
543
	 * can be removed.
544
	 * @param selection the selection
545
	 * @return list of {@link CtxHelpObject}s that can be removed, possibly empty.
546
	 */
547
	private List getRemovableObjectFromSelection(IStructuredSelection selection) {
548
		List objectsToRemove = new ArrayList();
549
		for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
550
			Object currentObject = iterator.next();
551
			if (currentObject instanceof CtxHelpObject && ((CtxHelpObject) currentObject).canBeRemoved()) {
552
				objectsToRemove.add(currentObject);
553
			}
554
		}
555
		return objectsToRemove;
556
	}
557
558
	/* (non-Javadoc)
559
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#doGlobalAction(java.lang.String)
560
	 */
561
	public boolean doGlobalAction(String actionId) {
562
		boolean cutAction = actionId.equals(ActionFactory.CUT.getId());
563
564
		if (cutAction || actionId.equals(ActionFactory.DELETE.getId())) {
565
			updateRemoveActionWithSelection((IStructuredSelection) fTree.getSelection());
566
			fRemoveObjectAction.run();
567
			return !cutAction;
568
		}
569
570
		if (actionId.equals(ActionFactory.PASTE.getId())) {
571
			doPaste();
572
			return true;
573
		}
574
575
		return false;
576
	}
577
578
	/* (non-Javadoc)
579
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canPaste(java.lang.Object, java.lang.Object[])
580
	 */
581
	protected boolean canPaste(Object targetObject, Object[] sourceObjects) {
582
		return canDropCopy(targetObject, sourceObjects, ViewerDropAdapter.LOCATION_ON);
583
	}
584
585
	/* (non-Javadoc)
586
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doPaste(java.lang.Object, java.lang.Object[])
587
	 */
588
	protected void doPaste(Object targetObject, Object[] sourceObjects) {
589
		doDropCopy(targetObject, sourceObjects, ViewerDropAdapter.LOCATION_ON);
590
	}
591
592
	/* (non-Javadoc)
593
	 * @see org.eclipse.pde.internal.ui.editor.TreeSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection)
594
	 */
595
	protected void handleDoubleClick(IStructuredSelection selection) {
596
		Object selected = selection.getFirstElement();
597
		if (selected instanceof CtxHelpTopic) {
598
			open((CtxHelpTopic) selected);
599
		} else if (selected instanceof CtxHelpObject) {
600
			fTree.expandToLevel(selected, 1);
601
		}
602
	}
603
604
	/**
605
	 * Opens the file that is linked in the given topic.
606
	 * @param topic the topic containing a link to a file
607
	 */
608
	public void open(CtxHelpTopic topic) {
609
		IPath resourcePath = topic.getLocation();
610
		if (!isEditable() || resourcePath == null || resourcePath.isEmpty()) {
611
			MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_emptyPath);
612
			return;
613
		}
614
615
		IResource resource = fModel.getUnderlyingResource().getProject().findMember(resourcePath);
616
		if (resource != null && resource instanceof IFile) {
617
			IPath path = resource.getFullPath();
618
			if (HelpEditorUtil.hasValidPageExtension(path)) {
619
				try {
620
					IDE.openEditor(PDEPlugin.getActivePage(), (IFile) resource, true);
621
				} catch (PartInitException e) { //suppress exception
622
				}
623
			} else {
624
				MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.TocPage_invalidHTMLFile);
625
			}
626
		} else {
627
			MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_warning);
628
		}
629
	}
630
631
	/* (non-Javadoc)
632
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#buttonSelected(int)
633
	 */
634
	protected void buttonSelected(int index) {
635
		IStructuredSelection selection = (IStructuredSelection) fTree.getSelection();
636
		Object object = selection.getFirstElement();
637
		CtxHelpObject firstSelectedObject = (CtxHelpObject) object;
638
		switch (index) {
639
			case F_BUTTON_ADD_CONTEXT :
640
				updateAddContextActionWithSelection(firstSelectedObject);
641
				fAddContextAction.run();
642
				break;
643
			case F_BUTTON_ADD_TOPIC :
644
				updateAddTopicActionWithSelection(firstSelectedObject);
645
				fAddTopicAction.run();
646
				break;
647
			case F_BUTTON_ADD_COMMAND :
648
				updateAddCommandActionWithSelection(firstSelectedObject);
649
				fAddCommandAction.run();
650
				break;
651
			case F_BUTTON_REMOVE :
652
				updateRemoveActionWithSelection(selection);
653
				fRemoveObjectAction.run();
654
				break;
655
			case F_BUTTON_UP :
656
				handleMoveAction(F_UP_FLAG);
657
				break;
658
			case F_BUTTON_DOWN :
659
				handleMoveAction(F_DOWN_FLAG);
660
				break;
661
		}
662
	}
663
664
	/**
665
	 * Move an object within the structure.
666
	 * 
667
	 * @param positionFlag The direction that the object will move, either F_UP_FLAG or F_DOWN_FLAG
668
	 */
669
	private void handleMoveAction(int positionFlag) {
670
		IStructuredSelection sel = (IStructuredSelection) fTree.getSelection();
671
672
		Object object = sel.getFirstElement();
673
		if (object == null) {
674
			return;
675
		} else if (object instanceof CtxHelpObject) {
676
			CtxHelpObject ctxHelpObject = (CtxHelpObject) object;
677
			CtxHelpObject parent = ctxHelpObject.getParent();
678
			if (parent != null) {
679
				parent.moveChild(ctxHelpObject, positionFlag);
680
				fTree.setSelection(new StructuredSelection(ctxHelpObject), true);
681
			}
682
		}
683
684
	}
685
686
	/* (non-Javadoc)
687
	 * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
688
	 */
689
	public void refresh() {
690
		CtxHelpModel model = (CtxHelpModel) getPage().getModel();
691
		fTree.setInput(model);
692
		fTree.expandToLevel(2);
693
		fTree.setSelection(new StructuredSelection(model.getCtxHelpRoot()), true);
694
		getManagedForm().fireSelectionChanged(this, fTree.getSelection());
695
		super.refresh();
696
	}
697
698
	/* (non-Javadoc)
699
	 * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
700
	 */
701
	public void dispose() {
702
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
703
		super.dispose();
704
	}
705
706
	/* (non-Javadoc)
707
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#isDragAndDropEnabled()
708
	 */
709
	protected boolean isDragAndDropEnabled() {
710
		// TODO DND turned off because the inserted element would often be placed in the wrong location in the xml
711
		return false;
712
	}
713
714
	/* (non-Javadoc)
715
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#getSupportedDNDOperations()
716
	 */
717
	public int getSupportedDNDOperations() {
718
		return DND.DROP_MOVE | DND.DROP_COPY;
719
	}
720
721
	/* (non-Javadoc)
722
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDropCopy(java.lang.Object, java.lang.Object[], int)
723
	 */
724
	public void doDropCopy(Object targetObject, Object[] sourceObjects, int targetLocation) {
725
		if (fDropTargetParent != null) {
726
			if (fDropTargetSibling != null) {
727
				if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
728
					for (int i = 0; i < sourceObjects.length; i++) {
729
						fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i], fDropTargetSibling, true);
730
					}
731
				} else {
732
					for (int i = sourceObjects.length - 1; i >= 0; i--) {
733
						fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i], fDropTargetSibling, false);
734
					}
735
				}
736
			} else {
737
				for (int i = 0; i < sourceObjects.length; i++) {
738
					fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i]);
739
				}
740
			}
741
		}
742
		fDropTargetParent = null;
743
		fDropTargetSibling = null;
744
	}
745
746
	/* (non-Javadoc)
747
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDropMove(java.lang.Object, java.lang.Object[], int)
748
	 */
749
	public void doDropMove(Object targetObject, Object[] sourceObjects, int targetLocation) {
750
		doDropCopy(targetObject, sourceObjects, targetLocation);
751
	}
752
753
	/* (non-Javadoc)
754
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDropCopy(java.lang.Object, java.lang.Object[], int)
755
	 */
756
	public boolean canDropCopy(Object targetObject, Object[] sourceObjects, int targetLocation) {
757
		// Add as a child of the root
758
		if (targetObject == null || !(targetObject instanceof CtxHelpObject || ((CtxHelpObject) targetObject).getType() == ICtxHelpConstants.TYPE_ROOT)) {
759
			for (int i = 0; i < sourceObjects.length; i++) {
760
				if (!(sourceObjects[i] instanceof CtxHelpObject) || !fModel.getCtxHelpRoot().canAddChild(((CtxHelpObject) sourceObjects[i]).getType())) {
761
					return false;
762
				}
763
			}
764
			fDropTargetParent = fModel.getCtxHelpRoot();
765
			fDropTargetSibling = null;
766
			return true;
767
		}
768
769
		CtxHelpObject dropTarget = (CtxHelpObject) targetObject;
770
771
		// Add as a child of the target
772
		if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
773
			boolean result = true;
774
			for (int i = 0; i < sourceObjects.length; i++) {
775
				if (!(sourceObjects[i] instanceof CtxHelpObject) || !dropTarget.canAddChild(((CtxHelpObject) sourceObjects[i]).getType())) {
776
					result = false;
777
					break;
778
				}
779
			}
780
			// If adding as a child works, do so, otherwise try as a sibling
781
			if (result) {
782
				fDropTargetParent = dropTarget;
783
				fDropTargetSibling = null;
784
				return true;
785
			}
786
		}
787
788
		// Add as a sibling of the target
789
		for (int i = 0; i < sourceObjects.length; i++) {
790
			if (!(sourceObjects[i] instanceof CtxHelpObject) || !dropTarget.canAddSibling(((CtxHelpObject) sourceObjects[i]).getType())) {
791
				return false;
792
			}
793
		}
794
		fDropTargetParent = dropTarget.getParent();
795
		fDropTargetSibling = dropTarget;
796
		return true;
797
	}
798
799
	/* (non-Javadoc)
800
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDropMove(java.lang.Object, java.lang.Object[], int)
801
	 */
802
	public boolean canDropMove(Object targetObject, Object[] sourceObjects, int targetLocation) {
803
		// Same as drop copy operation
804
		return canDropCopy(targetObject, sourceObjects, targetLocation);
805
	}
806
807
	/* (non-Javadoc)
808
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDragCopy(java.lang.Object[])
809
	 */
810
	public boolean canDragCopy(Object[] sourceObjects) {
811
		// Allow anything to be drag copied
812
		return true;
813
	}
814
815
	/* (non-Javadoc)
816
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDragMove(java.lang.Object[])
817
	 */
818
	public boolean canDragMove(Object[] sourceObjects) {
819
		for (int i = 0; i < sourceObjects.length; i++) {
820
			if (!(sourceObjects[i] instanceof CtxHelpObject) || !((CtxHelpObject) sourceObjects[i]).canBeRemoved()) {
821
				return false;
822
			}
823
		}
824
		fDragFromHere = true;
825
		return true;
826
	}
827
828
	/* (non-Javadoc)
829
	 * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDragRemove(java.lang.Object[])
830
	 */
831
	public void doDragRemove(Object[] sourceObjects) {
832
		updateRemoveActionWithSelection(new StructuredSelection(sourceObjects));
833
		fRemoveObjectAction.run();
834
		fDragFromHere = false;
835
	}
836
837
	/* (non-Javadoc)
838
	 * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
839
	 */
840
	public void modelChanged(IModelChangedEvent event) {
841
		// No need to call super, world changed event handled here
842
		if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
843
			handleModelEventWorldChanged(event);
844
		} else if (event.getChangeType() == IModelChangedEvent.INSERT) {
845
			handleModelInsertType(event);
846
		} else if (event.getChangeType() == IModelChangedEvent.REMOVE) {
847
			handleModelRemoveType(event);
848
		} else if ((event.getChangeType() == IModelChangedEvent.CHANGE) && (event.getChangedProperty().equals(IDocumentElementNode.F_PROPERTY_CHANGE_TYPE_SWAP))) {
849
			handleModelChangeTypeSwap(event);
850
		} else if (event.getChangeType() == IModelChangedEvent.CHANGE) {
851
			handleModelChangeType(event);
852
		}
853
	}
854
855
	/**
856
	 * Handles the swap event
857
	 * @param event the swap event
858
	 */
859
	private void handleModelChangeTypeSwap(IModelChangedEvent event) {
860
		Object[] objects = event.getChangedObjects();
861
		CtxHelpObject object = (CtxHelpObject) objects[0];
862
863
		if (object != null) {
864
			fTree.refresh(object);
865
		}
866
	}
867
868
	/**
869
	 * The model is stale, refresh the UI
870
	 * @param event The world-change event
871
	 */
872
	private void handleModelEventWorldChanged(IModelChangedEvent event) {
873
		markStale();
874
	}
875
876
	/**
877
	 * Handle insertions in the model
878
	 * @param event the insertion event
879
	 */
880
	private void handleModelInsertType(IModelChangedEvent event) {
881
		Object[] objects = event.getChangedObjects();
882
		for (int i = 0; i < objects.length; i++) {
883
			CtxHelpObject object = (CtxHelpObject) objects[i];
884
			if (object != null) {
885
				if (object.getType() != ICtxHelpConstants.TYPE_ROOT) {
886
					fTree.refresh(object.getParent());
887
					// Select the new object in the tree, unless it is a description node
888
					if (!(object instanceof CtxHelpDescription)) {
889
						fTree.setSelection(new StructuredSelection(object), true);
890
					}
891
				}
892
			}
893
		}
894
	}
895
896
	/**
897
	 * Handle removals in the model
898
	 * @param event the removal event
899
	 */
900
	private void handleModelRemoveType(IModelChangedEvent event) {
901
		Object[] objects = event.getChangedObjects();
902
		for (int i = 0; i < objects.length; i++) {
903
			if (objects[i] != null) {
904
				CtxHelpObject object = (CtxHelpObject) objects[i];
905
				fTree.remove(object);
906
				CtxHelpObject nextSelection = fRemoveObjectAction.getNextSelection();
907
				if (nextSelection != null) {
908
					fTree.refresh(object.getParent());
909
					if (!fDragFromHere) {
910
						fTree.setSelection(new StructuredSelection(nextSelection), true);
911
					}
912
					fRemoveObjectAction.clearNextSelection();
913
				}
914
			}
915
		}
916
	}
917
918
	/**
919
	 * Handle an update to an object's properties
920
	 * @param event the update event
921
	 */
922
	private void handleModelChangeType(IModelChangedEvent event) {
923
		Object[] objects = event.getChangedObjects();
924
		CtxHelpObject object = (CtxHelpObject) objects[0];
925
926
		if (object != null) {
927
			fTree.update(object, null);
928
		}
929
	}
930
931
}
(-)src/org/eclipse/pde/internal/ui/editor/toc/details/HelpEditorFilter.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.pde.internal.ui.editor.toc.details;
13
14
import org.eclipse.core.resources.*;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.jface.viewers.ViewerFilter;
19
import org.eclipse.pde.internal.ui.editor.toc.HelpEditorUtil;
20
21
public class HelpEditorFilter extends ViewerFilter {
22
	public boolean select(Viewer viewer, Object parent, Object element) {
23
		if (element instanceof IFile) {
24
			IPath path = ((IFile) element).getFullPath();
25
26
			return HelpEditorUtil.hasValidPageExtension(path);
27
		}
28
29
		if (element instanceof IProject && !((IProject) element).isOpen()) {
30
			return false;
31
		}
32
33
		if (element instanceof IContainer) {
34
			try {
35
				IResource[] resources = ((IContainer) element).members();
36
				for (int i = 0; i < resources.length; i++) {
37
					if (select(viewer, parent, resources[i])) {
38
						return true;
39
					}
40
				}
41
			} catch (CoreException e) {
42
			}
43
		}
44
45
		return false;
46
	}
47
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpAbstractAddAction.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
15
16
/**
17
 * Abstract action that allows new nodes to be added to the context help
18
 * model.
19
 * @since 3.4
20
 */
21
public abstract class CtxHelpAbstractAddAction extends Action {
22
23
	protected CtxHelpObject fParentObject;
24
25
	//The target object to insert after
26
	protected CtxHelpObject fTargetObject;
27
28
	/**
29
	 * Set the parent object that this action will add
30
	 * objects to.
31
	 * 
32
	 * @param parent The new parent object for this action
33
	 */
34
	public void setParentObject(CtxHelpObject parent) {
35
		fParentObject = parent;
36
	}
37
38
	/**
39
	 * Set the target object that this action will add
40
	 * objects after.
41
	 * 
42
	 * @param target The new target object for this action
43
	 */
44
	public void setTargetObject(CtxHelpObject target) {
45
		fTargetObject = target;
46
	}
47
48
	/**
49
	 * Returns the names of the children of the parent object.  Used
50
	 * to find a new name that doesn't conflict.  Will return an empty
51
	 * array if the parent is not set.
52
	 * @return children names or an empty array
53
	 */
54
	public String[] getChildNames() {
55
		if (fParentObject != null) {
56
			int numChildren = fParentObject.getChildren().size();
57
			CtxHelpObject[] ctxHelpObjects = (CtxHelpObject[]) fParentObject.getChildren().toArray(new CtxHelpObject[numChildren]);
58
59
			String[] ctxHelpObjectNames = new String[ctxHelpObjects.length];
60
61
			for (int i = 0; i < numChildren; ++i) {
62
				ctxHelpObjectNames[i] = ctxHelpObjects[i].getName();
63
			}
64
			return ctxHelpObjectNames;
65
		}
66
		return new String[0];
67
	}
68
69
	/**
70
	 * Add the child to the parent object. If a target object is specified,
71
	 * add the child as a sibling after that object.
72
	 * 
73
	 * @param child The object to add to the parent
74
	 */
75
	protected void addChild(CtxHelpObject child) {
76
		if (fTargetObject == null) {
77
			fParentObject.addChild(child);
78
		} else {
79
			fParentObject.addChild(child, fTargetObject, false);
80
		}
81
	}
82
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpCommandDetails.java (+118 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpCommand;
15
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
17
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpInputContext;
18
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpTreeSection;
19
import org.eclipse.pde.internal.ui.parts.FormEntry;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.ui.forms.IFormPart;
23
24
/**
25
 * Details section for command entries.
26
 * @since 3.4
27
 * @see CtxHelpAbstractDetails
28
 * @see CtxHelpCommand
29
 */
30
public class CtxHelpCommandDetails extends CtxHelpAbstractDetails {
31
32
	private CtxHelpCommand fCommand;
33
	private FormEntry fLabelEntry;
34
	private FormEntry fSerialEntry;
35
36
	public CtxHelpCommandDetails(CtxHelpTreeSection masterSection) {
37
		super(masterSection, CtxHelpInputContext.CONTEXT_ID);
38
	}
39
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#createFields(org.eclipse.swt.widgets.Composite)
42
	 */
43
	public void createFields(Composite parent) {
44
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpCommandDetails_specifyDisplayLabel);
45
		fLabelEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpCommandDetails_label, SWT.NONE);
46
		createSpace(parent);
47
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpCommandDetails_specifyTheCommand);
48
		fSerialEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpCommandDetails_command, SWT.NONE);
49
	}
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsTitle()
53
	 */
54
	protected String getDetailsTitle() {
55
		return PDEUIMessages.CtxHelpCommandDetails_commandDetails;
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsDescription()
60
	 */
61
	protected String getDetailsDescription() {
62
		return null;
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#hookListeners()
67
	 */
68
	public void hookListeners() {
69
		fLabelEntry.setFormEntryListener(new FormEntryAdapter(this) {
70
			public void textValueChanged(FormEntry entry) {
71
				if (fCommand != null) {
72
					fCommand.setLabel(fLabelEntry.getValue());
73
				}
74
			}
75
		});
76
		fSerialEntry.setFormEntryListener(new FormEntryAdapter(this) {
77
			public void textValueChanged(FormEntry entry) { // Ensure data object is defined
78
				if (fCommand != null) {
79
					fCommand.setSerialization(fSerialEntry.getValue());
80
				}
81
			}
82
		});
83
	}
84
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#updateFields()
87
	 */
88
	public void updateFields() {
89
		if (fCommand != null) {
90
			fLabelEntry.setValue(fCommand.getLabel(), true);
91
			fLabelEntry.setEditable(isEditableElement());
92
			fSerialEntry.setValue(fCommand.getSerialization(), true);
93
			fSerialEntry.setEditable(isEditableElement());
94
		}
95
	}
96
97
	/* (non-Javadoc)
98
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
99
	 */
100
	public void commit(boolean onSave) {
101
		super.commit(onSave);
102
		// Only required for form entries
103
		fLabelEntry.commit();
104
		fSerialEntry.commit();
105
106
	}
107
108
	/* (non-Javadoc)
109
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
110
	 */
111
	public void selectionChanged(IFormPart part, ISelection selection) {
112
		Object object = getFirstSelectedObject(selection);
113
		if (object instanceof CtxHelpCommand) {
114
			fCommand = (CtxHelpCommand) object;
115
			updateFields();
116
		}
117
	}
118
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpSourcePage.java (+127 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import org.eclipse.jface.viewers.*;
14
import org.eclipse.pde.internal.core.text.*;
15
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpModel;
16
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
17
import org.eclipse.pde.internal.ui.PDEPlugin;
18
import org.eclipse.pde.internal.ui.PDEUIMessages;
19
import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
20
import org.eclipse.pde.internal.ui.editor.XMLSourcePage;
21
22
/**
23
 * Source page for the context help editor.  Displays the
24
 * xml source.
25
 * @since 3.4
26
 * @see CtxHelpEditor
27
 */
28
public class CtxHelpSourcePage extends XMLSourcePage {
29
30
	public CtxHelpSourcePage(PDEFormEditor editor, String id, String title) {
31
		super(editor, id, title);
32
	}
33
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.pde.internal.ui.editor.PDEProjectionSourcePage#isQuickOutlineEnabled()
36
	 */
37
	public boolean isQuickOutlineEnabled() {
38
		return true;
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineComparator()
43
	 */
44
	public ViewerComparator createOutlineComparator() {
45
		return null;
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineContentProvider()
50
	 */
51
	public ITreeContentProvider createOutlineContentProvider() {
52
		return new CtxHelpContentProvider();
53
	}
54
55
	/* (non-Javadoc)
56
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#createOutlineLabelProvider()
57
	 */
58
	public ILabelProvider createOutlineLabelProvider() {
59
		return PDEPlugin.getDefault().getLabelProvider();
60
	}
61
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.ui.part.EditorPart#setPartName(java.lang.String)
64
	 */
65
	protected void setPartName(String partName) {
66
		super.setPartName(PDEUIMessages.EditorSourcePage_name);
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#isSelectionListener()
71
	 */
72
	protected boolean isSelectionListener() {
73
		return true;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#updateSelection(java.lang.Object)
78
	 */
79
	public void updateSelection(Object object) {
80
		if ((object instanceof IDocumentElementNode) && !((IDocumentElementNode) object).isErrorNode()) {
81
			setSelectedObject(object);
82
			setHighlightRange((IDocumentElementNode) object, true);
83
			setSelectedRange((IDocumentElementNode) object, false);
84
		}
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#findRange()
89
	 */
90
	protected IDocumentRange findRange() {
91
		if (getSelection() instanceof IDocumentElementNode) {
92
			return (IDocumentElementNode) getSelection();
93
		}
94
95
		return null;
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#getRangeElement(int, boolean)
100
	 */
101
	public IDocumentRange getRangeElement(int offset, boolean searchChildren) {
102
		CtxHelpObject root = ((CtxHelpModel) getInputContext().getModel()).getCtxHelpRoot();
103
		return findNode(root, offset, searchChildren);
104
	}
105
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.pde.internal.ui.editor.PDESourcePage#synchronizeOutlinePage(int)
108
	 */
109
	protected void synchronizeOutlinePage(int offset) {
110
		IDocumentRange rangeElement = getRangeElement(offset, true);
111
		updateHighlightRange(rangeElement);
112
		// TODO: MP: TEO: LOW: Generalize for parent - search children = true and handle attributes
113
		if (rangeElement instanceof IDocumentAttributeNode) {
114
			rangeElement = ((IDocumentAttributeNode) rangeElement).getEnclosingElement();
115
		}
116
		updateOutlinePageSelection(rangeElement);
117
	}
118
119
	/* (non-Javadoc)
120
	 * @see org.eclipse.ui.editors.text.TextEditor#initializeEditor()
121
	 */
122
	protected void initializeEditor() {
123
		super.initializeEditor();
124
		// TODO Fix help context
125
		//		setHelpContextId(IHelpContextIds.TOC_EDITOR);
126
	}
127
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpDescriptionDetails.java (+110 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpDescription;
15
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
17
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpInputContext;
18
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpTreeSection;
19
import org.eclipse.pde.internal.ui.parts.FormEntry;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.ui.forms.IFormPart;
24
25
/**
26
 * Details section for description entries.
27
 * @since 3.4
28
 * @see CtxHelpAbstractDetails
29
 * @see CtxHelpDescription
30
 */
31
public class CtxHelpDescriptionDetails extends CtxHelpAbstractDetails {
32
33
	private CtxHelpDescription fDescription;
34
	private FormEntry fDescEntry;
35
36
	public CtxHelpDescriptionDetails(CtxHelpTreeSection masterSection) {
37
		super(masterSection, CtxHelpInputContext.CONTEXT_ID);
38
	}
39
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#createFields(org.eclipse.swt.widgets.Composite)
42
	 */
43
	public void createFields(Composite parent) {
44
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpDescriptionDetails_specifyDescription);
45
		fDescEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpDescriptionDetails_description, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
46
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
47
		data.heightHint = 50;
48
		fDescEntry.getText().setLayoutData(data);
49
		data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
50
		fDescEntry.getLabel().setLayoutData(data);
51
	}
52
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsTitle()
55
	 */
56
	protected String getDetailsTitle() {
57
		return PDEUIMessages.TocTopicDetails_title;
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsDescription()
62
	 */
63
	protected String getDetailsDescription() {
64
		return null;
65
	}
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#hookListeners()
69
	 */
70
	public void hookListeners() {
71
		fDescEntry.setFormEntryListener(new FormEntryAdapter(this) {
72
			public void textValueChanged(FormEntry entry) {
73
				if (fDescription != null) {
74
					fDescription.setDescription(fDescEntry.getValue());
75
				}
76
			}
77
		});
78
	}
79
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#updateFields()
82
	 */
83
	public void updateFields() {
84
		if (fDescription != null) {
85
			fDescEntry.setValue(fDescription.getDescription(), true);
86
			fDescEntry.setEditable(isEditableElement());
87
		}
88
	}
89
90
	/* (non-Javadoc)
91
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
92
	 */
93
	public void commit(boolean onSave) {
94
		super.commit(onSave);
95
		// Only required for form entries
96
		fDescEntry.commit();
97
98
	}
99
100
	/* (non-Javadoc)
101
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
102
	 */
103
	public void selectionChanged(IFormPart part, ISelection selection) {
104
		Object object = getFirstSelectedObject(selection);
105
		if (object instanceof CtxHelpDescription) {
106
			fDescription = (CtxHelpDescription) object;
107
			updateFields();
108
		}
109
	}
110
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpEditor.java (+270 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.jdt.ui.JavaUI;
19
import org.eclipse.jface.viewers.*;
20
import org.eclipse.pde.internal.core.text.ctxhelp.*;
21
import org.eclipse.pde.internal.ui.IPDEUIConstants;
22
import org.eclipse.pde.internal.ui.PDEPlugin;
23
import org.eclipse.pde.internal.ui.editor.*;
24
import org.eclipse.pde.internal.ui.editor.context.InputContext;
25
import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
26
import org.eclipse.ui.*;
27
import org.eclipse.ui.forms.editor.IFormPage;
28
import org.eclipse.ui.part.*;
29
30
/**
31
 * Main UI class for the context help editor.  This editor provides a convenient way to
32
 * explore and edit the xml files containing context help entries.  The editor will
33
 * have two pages, one displaying the xml source, the other displaying a form editor.
34
 * @since 3.4
35
 * @see CtxHelpSourcePage
36
 * @see CtxHelpPage
37
 */
38
public class CtxHelpEditor extends MultiSourceEditor {
39
40
	public CtxHelpEditor() {
41
		super();
42
	}
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
46
	 */
47
	protected String getEditorID() {
48
		return IPDEUIConstants.CONTEXT_HELP_EDITOR_ID;
49
	}
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getAdapter(java.lang.Class)
53
	 */
54
	public Object getAdapter(Class adapter) {
55
		if (isShowInApplicable()) {
56
			if (adapter == IShowInSource.class) {
57
				return getShowInSource();
58
			} else if (adapter == IShowInTargetList.class) {
59
				return getShowInTargetList();
60
			}
61
		}
62
		return super.getAdapter(adapter);
63
	}
64
65
	/**
66
	 * @return whether there is a selection that requires the "Show In" menu to be available
67
	 */
68
	private boolean isShowInApplicable() {
69
		if (getSelection().isEmpty()) {
70
			return false;
71
		}
72
		if (getSelection() instanceof IStructuredSelection) {
73
			IStructuredSelection selection = (IStructuredSelection) getSelection();
74
			for (Iterator iter = selection.iterator(); iter.hasNext();) {
75
				Object obj = iter.next();
76
				if (obj instanceof CtxHelpTopic && ((CtxHelpTopic) obj).getLocation() != null) {
77
					return true;
78
				}
79
			}
80
		}
81
		return false;
82
	}
83
84
	/**
85
	 * Returns the <code>IShowInSource</code> for this editor.
86
	 * @return the <code>IShowInSource</code> 
87
	 */
88
	private IShowInSource getShowInSource() {
89
		return new IShowInSource() {
90
			public ShowInContext getShowInContext() {
91
				ArrayList resourceList = new ArrayList();
92
				IStructuredSelection selection = (IStructuredSelection) getSelection();
93
				IStructuredSelection resources;
94
				if (selection.isEmpty()) {
95
					resources = null;
96
				} else {
97
					IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot();
98
					for (Iterator iter = selection.iterator(); iter.hasNext();) {
99
						Object obj = iter.next();
100
						if (obj instanceof CtxHelpTopic) {
101
							IPath path = ((CtxHelpTopic) obj).getLocation();
102
							if (path != null && !path.isEmpty()) {
103
								CtxHelpModel model = (CtxHelpModel) getAggregateModel();
104
								IPath pluginPath = model.getUnderlyingResource().getProject().getFullPath();
105
								IResource resource = root.findMember(pluginPath.append(path));
106
								if (resource != null) {
107
									resourceList.add(resource);
108
								}
109
							}
110
						}
111
					}
112
					resources = new StructuredSelection(resourceList);
113
				}
114
				return new ShowInContext(null, resources);
115
			}
116
		};
117
	}
118
119
	/**
120
	 * Returns the <code>IShowInTargetList</code> for this editor.
121
	 * @return the <code>IShowInTargetList</code> 
122
	 */
123
	private IShowInTargetList getShowInTargetList() {
124
		return new IShowInTargetList() {
125
			public String[] getShowInTargetIds() {
126
				return new String[] {JavaUI.ID_PACKAGES, IPageLayout.ID_RES_NAV};
127
			}
128
		};
129
	}
130
131
	/* (non-Javadoc)
132
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#isSaveAsAllowed()
133
	 */
134
	public boolean isSaveAsAllowed() {
135
		return true;
136
	}
137
138
	/* (non-Javadoc)
139
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getContextIDForSaveAs()
140
	 */
141
	public String getContextIDForSaveAs() {
142
		return CtxHelpInputContext.CONTEXT_ID;
143
	}
144
145
	/* (non-Javadoc)
146
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#addEditorPages()
147
	 */
148
	protected void addEditorPages() {
149
		try {
150
			addPage(new CtxHelpPage(this));
151
		} catch (PartInitException e) {
152
			PDEPlugin.logException(e);
153
		}
154
		addSourcePage(CtxHelpInputContext.CONTEXT_ID);
155
	}
156
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createContentOutline()
159
	 */
160
	protected ISortableContentOutlinePage createContentOutline() {
161
		return new CtxHelpFormOutlinePage(this);
162
	}
163
164
	/* (non-Javadoc)
165
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createInputContextManager()
166
	 */
167
	protected InputContextManager createInputContextManager() {
168
		return new CtxHelpInputContextManager(this);
169
	}
170
171
	/* (non-Javadoc)
172
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createResourceContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IFileEditorInput)
173
	 */
174
	protected void createResourceContexts(InputContextManager contexts, IFileEditorInput input) {
175
		contexts.putContext(input, new CtxHelpInputContext(this, input, true));
176
		contexts.monitorFile(input.getFile());
177
	}
178
179
	/* (non-Javadoc)
180
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createStorageContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.ui.IStorageEditorInput)
181
	 */
182
	protected void createStorageContexts(InputContextManager contexts, IStorageEditorInput input) {
183
		contexts.putContext(input, new CtxHelpInputContext(this, input, true));
184
	}
185
186
	/* (non-Javadoc)
187
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#createSystemFileContexts(org.eclipse.pde.internal.ui.editor.context.InputContextManager, org.eclipse.pde.internal.ui.editor.SystemFileEditorInput)
188
	 */
189
	protected void createSystemFileContexts(InputContextManager contexts, SystemFileEditorInput input) {
190
		File file = (File) input.getAdapter(File.class);
191
		if (file != null) {
192
			IEditorInput in = new SystemFileEditorInput(file);
193
			contexts.putContext(in, new CtxHelpInputContext(this, in, true));
194
		}
195
	}
196
197
	/* (non-Javadoc)
198
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#editorContextAdded(org.eclipse.pde.internal.ui.editor.context.InputContext)
199
	 */
200
	public void editorContextAdded(InputContext context) {
201
		// Add the source page
202
		addSourcePage(context.getId());
203
	}
204
205
	/* (non-Javadoc)
206
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
207
	 */
208
	protected InputContext getInputContext(Object object) {
209
		return fInputContextManager.findContext(CtxHelpInputContext.CONTEXT_ID);
210
	}
211
212
	/* (non-Javadoc)
213
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#contextRemoved(org.eclipse.pde.internal.ui.editor.context.InputContext)
214
	 */
215
	public void contextRemoved(InputContext context) {
216
		close(false);
217
	}
218
219
	/* (non-Javadoc)
220
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileAdded(org.eclipse.core.resources.IFile)
221
	 */
222
	public void monitoredFileAdded(IFile monitoredFile) {
223
		// NO-OP
224
	}
225
226
	/* (non-Javadoc)
227
	 * @see org.eclipse.pde.internal.ui.editor.context.IInputContextListener#monitoredFileRemoved(org.eclipse.core.resources.IFile)
228
	 */
229
	public boolean monitoredFileRemoved(IFile monitoredFile) {
230
		return true;
231
	}
232
233
	/* (non-Javadoc)
234
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getSelection()
235
	 */
236
	public ISelection getSelection() {
237
		IFormPage formPage = getActivePageInstance();
238
		if ((formPage != null) && (formPage instanceof CtxHelpPage)) {
239
			// Synchronizes the selection made in the master tree view with the
240
			// selection in the outline view when the link with editor button
241
			// is toggled on
242
			return ((CtxHelpPage) formPage).getSelection();
243
		}
244
		return super.getSelection();
245
	}
246
247
	/* (non-Javadoc)
248
	 * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#canCut(org.eclipse.jface.viewers.ISelection)
249
	 */
250
	public boolean canCut(ISelection selection) {
251
		if (selection instanceof IStructuredSelection) {
252
			IStructuredSelection sel = (IStructuredSelection) selection;
253
			for (Iterator iter = sel.iterator(); iter.hasNext();) {
254
				Object obj = iter.next();
255
				if (obj instanceof CtxHelpObject && ((CtxHelpObject) obj).canBeRemoved()) {
256
					return canCopy(selection);
257
				}
258
			}
259
		}
260
		return false;
261
	}
262
263
	/* (non-Javadoc)
264
	 * @see org.eclipse.pde.internal.ui.editor.MultiSourceEditor#createSourcePage(org.eclipse.pde.internal.ui.editor.PDEFormEditor, java.lang.String, java.lang.String, java.lang.String)
265
	 */
266
	protected PDESourcePage createSourcePage(PDEFormEditor editor, String title, String name, String contextId) {
267
		return new CtxHelpSourcePage(editor, title, name);
268
	}
269
270
}
(-)src/org/eclipse/pde/internal/ui/editor/toc/HelpEditorUtil.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.toc;
12
13
import java.util.HashSet;
14
import java.util.Locale;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.IWorkspaceRoot;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.pde.core.IBaseModel;
22
import org.eclipse.pde.core.IModel;
23
import org.eclipse.pde.internal.core.itoc.ITocConstants;
24
import org.eclipse.pde.internal.ui.util.XMLRootElementMatcher;
25
26
public class HelpEditorUtil {
27
	public static final String[] pageExtensions = {"htm","shtml","html","xhtml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
28
	public static final String tocExtension = "xml"; //$NON-NLS-1$
29
	private static HashSet pageExtensionSet = new HashSet(pageExtensions.length);
30
31
	private static void populateHashSet()
32
	{	for(int i = 0; i < pageExtensions.length; ++i)
33
		{	pageExtensionSet.add(pageExtensions[i]);
34
		}
35
	}
36
	
37
	public static boolean hasValidPageExtension(IPath path)
38
	{	String fileExtension = path.getFileExtension();	
39
		if(fileExtension != null)
40
		{	fileExtension = fileExtension.toLowerCase(Locale.ENGLISH);
41
			if(pageExtensionSet.isEmpty())
42
			{	populateHashSet();
43
			}
44
			
45
			return pageExtensionSet.contains(fileExtension);
46
		}
47
48
		return false;
49
	}
50
51
	private static boolean hasValidTocExtension(IPath path)
52
	{	String fileExtension = path.getFileExtension();
53
		return fileExtension != null && fileExtension.equals(tocExtension); 
54
	}
55
56
	/**
57
	 * @param file
58
	 */
59
	public static boolean isTOCFile(IPath path) {
60
		if(!hasValidTocExtension(path))
61
			return false;
62
		
63
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
64
65
		IResource resource = root.findMember(path);
66
		if(resource != null && resource instanceof IFile)
67
		{	return XMLRootElementMatcher.fileMatchesElement((IFile)resource, ITocConstants.ELEMENT_TOC);
68
		}
69
70
		return XMLRootElementMatcher.fileMatchesElement(path.toFile(), ITocConstants.ELEMENT_TOC);
71
	}
72
73
	public static boolean isCurrentResource(IPath path, IBaseModel model)
74
	{	if(model instanceof IModel)
75
		{	IPath workspacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
76
			IPath fullPath;	
77
78
			if(workspacePath.isPrefixOf(path))
79
			{	fullPath = ((IModel)model).getUnderlyingResource().getLocation();	
80
			}
81
			else
82
			{	fullPath = ((IModel)model).getUnderlyingResource().getFullPath();
83
			}
84
85
			return fullPath.equals(path);
86
		}
87
88
		return false;
89
	}
90
91
	public static String getPageExtensionList() {
92
		StringBuffer buf = new StringBuffer();
93
94
		for(int i = 0; i < pageExtensions.length; ++i)
95
		{	buf.append('.');
96
			buf.append(pageExtensions[i]);
97
			if(i != pageExtensions.length - 1)
98
			{	buf.append(", "); //$NON-NLS-1$
99
			}
100
		}
101
102
		return buf.toString();
103
	}
104
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpBlock.java (+114 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import org.eclipse.jface.viewers.ISelection;
14
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.pde.core.IModelChangedEvent;
16
import org.eclipse.pde.core.IModelChangedListener;
17
import org.eclipse.pde.internal.core.text.ctxhelp.*;
18
import org.eclipse.pde.internal.ui.editor.*;
19
import org.eclipse.pde.internal.ui.editor.ctxhelp.details.*;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.forms.*;
22
23
/**
24
 * Block containing the UI elements for the context editor.  Extends from PDEMasterDetailsBlock
25
 * which splits the editor into two areas, a tree section and a details section.
26
 * @since 3.4
27
 * @see CtxHelpTreeSection
28
 * @see CtxHelpAbstractDetails
29
 */
30
public class CtxHelpBlock extends PDEMasterDetailsBlock implements IModelChangedListener, IDetailsPageProvider {
31
32
	private CtxHelpTreeSection fMasterSection;
33
34
	public CtxHelpBlock(PDEFormPage page) {
35
		super(page);
36
	}
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock#createMasterSection(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
40
	 */
41
	protected PDESection createMasterSection(IManagedForm managedForm, Composite parent) {
42
		fMasterSection = new CtxHelpTreeSection(getPage(), parent);
43
		return fMasterSection;
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
48
	 */
49
	protected void registerPages(DetailsPart detailsPart) {
50
		// Only static pages to be defined.  Do not cache pages
51
		detailsPart.setPageLimit(0);
52
		detailsPart.registerPage(CtxHelpContextDetails.class, new CtxHelpContextDetails(fMasterSection));
53
		detailsPart.registerPage(CtxHelpDescriptionDetails.class, new CtxHelpDescriptionDetails(fMasterSection));
54
		detailsPart.registerPage(CtxHelpTopicDetails.class, new CtxHelpTopicDetails(fMasterSection));
55
		detailsPart.registerPage(CtxHelpCommandDetails.class, new CtxHelpCommandDetails(fMasterSection));
56
		detailsPart.setPageProvider(this);
57
	}
58
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
61
	 */
62
	public void modelChanged(IModelChangedEvent event) {
63
		if (fMasterSection != null) {
64
			fMasterSection.modelChanged(event);
65
		}
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.ui.forms.IDetailsPageProvider#getPage(java.lang.Object)
70
	 */
71
	public IDetailsPage getPage(Object key) {
72
		// No dynamic pages.  Static pages already registered
73
		return null;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.ui.forms.IDetailsPageProvider#getPageKey(java.lang.Object)
78
	 */
79
	public Object getPageKey(Object object) {
80
		ISelection selection = getSelection();
81
		if (!(selection instanceof IStructuredSelection) || ((IStructuredSelection) selection).size() > 1) {
82
			return object.getClass();
83
		}
84
85
		if (object instanceof CtxHelpContext) {
86
			return CtxHelpContextDetails.class;
87
		} else if (object instanceof CtxHelpDescription) {
88
			return CtxHelpDescriptionDetails.class;
89
		} else if (object instanceof CtxHelpTopic) {
90
			return CtxHelpTopicDetails.class;
91
		} else if (object instanceof CtxHelpCommand) {
92
			return CtxHelpCommandDetails.class;
93
		}
94
95
		return object.getClass();
96
	}
97
98
	/**
99
	 * @return the current selection of the tree section
100
	 */
101
	public ISelection getSelection() {
102
		if (fMasterSection != null) {
103
			return fMasterSection.getSelection();
104
		}
105
		return null;
106
	}
107
108
	/**
109
	 * @return the tree section
110
	 */
111
	public CtxHelpTreeSection getMasterSection() {
112
		return fMasterSection;
113
	}
114
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpTopicDetails.java (+184 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.window.Window;
18
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpTopic;
19
import org.eclipse.pde.internal.ui.PDEPlugin;
20
import org.eclipse.pde.internal.ui.PDEUIMessages;
21
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
22
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpInputContext;
23
import org.eclipse.pde.internal.ui.editor.ctxhelp.CtxHelpTreeSection;
24
import org.eclipse.pde.internal.ui.editor.toc.details.HelpEditorFilter;
25
import org.eclipse.pde.internal.ui.parts.FormEntry;
26
import org.eclipse.pde.internal.ui.util.FileValidator;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
30
import org.eclipse.ui.forms.IFormPart;
31
import org.eclipse.ui.forms.events.HyperlinkEvent;
32
import org.eclipse.ui.model.WorkbenchContentProvider;
33
import org.eclipse.ui.model.WorkbenchLabelProvider;
34
35
/**
36
 * Details section for topic entries.
37
 * @since 3.4
38
 * @see CtxHelpAbstractDetails
39
 * @see CtxHelpTopic
40
 */
41
public class CtxHelpTopicDetails extends CtxHelpAbstractDetails {
42
43
	private CtxHelpTopic fTopic;
44
	private FormEntry fLabelEntry;
45
	private FormEntry fLinkEntry;
46
47
	public CtxHelpTopicDetails(CtxHelpTreeSection masterSection) {
48
		super(masterSection, CtxHelpInputContext.CONTEXT_ID);
49
	}
50
51
	/* (non-Javadoc)
52
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#createFields(org.eclipse.swt.widgets.Composite)
53
	 */
54
	public void createFields(Composite parent) {
55
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpTopicDetails_specifyLabel);
56
		fLabelEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpTopicDetails_label, SWT.NONE);
57
		createSpace(parent);
58
		createLabel(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpTopicDetails_specifyLocation);
59
		fLinkEntry = new FormEntry(parent, getManagedForm().getToolkit(), PDEUIMessages.CtxHelpTopicDetails_location, PDEUIMessages.GeneralInfoSection_browse, isEditable());
60
	}
61
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsTitle()
64
	 */
65
	protected String getDetailsTitle() {
66
		return PDEUIMessages.TocTopicDetails_title;
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#getDetailsDescription()
71
	 */
72
	protected String getDetailsDescription() {
73
		return null;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#hookListeners()
78
	 */
79
	public void hookListeners() {
80
		fLabelEntry.setFormEntryListener(new FormEntryAdapter(this) {
81
			public void textValueChanged(FormEntry entry) {
82
				if (fTopic != null) {
83
					fTopic.setLabel(fLabelEntry.getValue());
84
				}
85
			}
86
		});
87
		fLinkEntry.setFormEntryListener(new FormEntryAdapter(this) {
88
			public void textValueChanged(FormEntry entry) { // Ensure data object is defined
89
				if (fTopic != null) {
90
					// TODO Do we need better testing for path validity?
91
					fTopic.setLocation(new Path(fLinkEntry.getValue()));
92
				}
93
			}
94
95
			public void browseButtonSelected(FormEntry entry) {
96
				handleBrowse();
97
			}
98
99
			public void linkActivated(HyperlinkEvent e) {
100
				handleOpen();
101
			}
102
		});
103
	}
104
105
	/**
106
	 * Handle when the browse button is pressed.  Open up a file selection dialog.
107
	 */
108
	private void handleBrowse() {
109
		ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getPage().getSite().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
110
111
		dialog.setValidator(new FileValidator());
112
		dialog.setAllowMultiple(false);
113
		dialog.setTitle(PDEUIMessages.TocDetails_browseSelection);
114
		dialog.setMessage(PDEUIMessages.TocDetails_browseMessage);
115
		dialog.addFilter(new HelpEditorFilter());
116
117
		dialog.setInput(PDEPlugin.getWorkspace().getRoot());
118
119
		if (dialog.open() == Window.OK) {
120
			IFile file = (IFile) dialog.getFirstResult();
121
			setPathEntry(file);
122
		}
123
	}
124
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#updateFields()
127
	 */
128
	public void updateFields() {
129
		if (fTopic != null) {
130
			fLabelEntry.setValue(fTopic.getLabel(), true);
131
			fLabelEntry.setEditable(isEditableElement());
132
			if (fTopic.getLocation() == null) {
133
				fLinkEntry.setValue("", true); //$NON-NLS-1$
134
			} else {
135
				fLinkEntry.setValue(fTopic.getLocation().toPortableString(), true);
136
			}
137
			fLinkEntry.setEditable(isEditableElement());
138
		}
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
143
	 */
144
	public void commit(boolean onSave) {
145
		super.commit(onSave);
146
		// Only required for form entries
147
		fLabelEntry.commit();
148
		fLinkEntry.commit();
149
150
	}
151
152
	/* (non-Javadoc)
153
	 * @see org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractDetails#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
154
	 */
155
	public void selectionChanged(IFormPart part, ISelection selection) {
156
		Object object = getFirstSelectedObject(selection);
157
		if (object instanceof CtxHelpTopic) {
158
			fTopic = (CtxHelpTopic) object;
159
			updateFields();
160
		}
161
	}
162
163
	/**
164
	 * Sets the text of the form entry used to supply a link
165
	 * @param file
166
	 */
167
	protected void setPathEntry(IFile file) {
168
		IPath path = file.getFullPath();
169
		if (file.getProject().equals(fTopic.getModel().getUnderlyingResource().getProject())) {
170
			fLinkEntry.setValue(path.removeFirstSegments(1).toString());
171
		} else {
172
			fLinkEntry.setValue(".." + path.toString()); //$NON-NLS-1$
173
		}
174
	}
175
176
	/**
177
	 * Handle when the link is pressed.  Try opening the file at the specified path.
178
	 */
179
	protected void handleOpen() {
180
		getMasterSection().open(fTopic);
181
		// TODO Consider having a wizard open to create a new file if the path does not exist
182
	}
183
184
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/CtxHelpInputContext.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.pde.core.IBaseModel;
19
import org.eclipse.pde.internal.core.text.AbstractEditingModel;
20
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpModel;
21
import org.eclipse.pde.internal.ui.editor.*;
22
import org.eclipse.pde.internal.ui.editor.context.XMLInputContext;
23
import org.eclipse.ui.*;
24
25
/**
26
 * The input context for the context help editor, based on an xml file containing
27
 * help context ids.
28
 * @since 3.4
29
 */
30
public class CtxHelpInputContext extends XMLInputContext {
31
32
	public static final String CONTEXT_ID = "ctxhelp-context"; //$NON-NLS-1$	
33
34
	public CtxHelpInputContext(PDEFormEditor editor, IEditorInput input, boolean primary) {
35
		super(editor, input, primary);
36
		create();
37
	}
38
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#createModel(org.eclipse.ui.IEditorInput)
41
	 */
42
	protected IBaseModel createModel(IEditorInput input) throws CoreException {
43
		if (input instanceof IStorageEditorInput) {
44
			boolean isReconciling = input instanceof IFileEditorInput;
45
			IDocument document = getDocumentProvider().getDocument(input);
46
47
			CtxHelpModel model = new CtxHelpModel(document, isReconciling);
48
49
			if (input instanceof IFileEditorInput) {
50
				IFile file = ((IFileEditorInput) input).getFile();
51
				model.setUnderlyingResource(file);
52
				model.setCharset(file.getCharset());
53
			} else if (input instanceof SystemFileEditorInput) {
54
				File file = (File) ((SystemFileEditorInput) input).getAdapter(File.class);
55
				model.setInstallLocation(file.getParent());
56
				model.setCharset(getDefaultCharset());
57
			} else if (input instanceof JarEntryEditorInput) {
58
				File file = (File) ((JarEntryEditorInput) input).getAdapter(File.class);
59
				model.setInstallLocation(file.toString());
60
				model.setCharset(getDefaultCharset());
61
			} else {
62
				model.setCharset(getDefaultCharset());
63
			}
64
65
			model.load();
66
67
			return model;
68
		}
69
70
		return null;
71
	}
72
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#getId()
75
	 */
76
	public String getId() {
77
		return CONTEXT_ID;
78
	}
79
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.pde.internal.ui.editor.context.XMLInputContext#reorderInsertEdits(java.util.ArrayList)
82
	 */
83
	protected void reorderInsertEdits(ArrayList ops) {
84
		// NO-OP
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#doRevert()
89
	 */
90
	public void doRevert() {
91
		fEditOperations.clear();
92
		fOperationTable.clear();
93
		fMoveOperations.clear();
94
		AbstractEditingModel model = (AbstractEditingModel) getModel();
95
		model.reconciled(model.getDocument());
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.pde.internal.ui.editor.context.InputContext#getPartitionName()
100
	 */
101
	protected String getPartitionName() {
102
		return "___ctxhelp_partition"; //$NON-NLS-1$
103
	}
104
}
(-)src/org/eclipse/pde/internal/ui/editor/ctxhelp/details/CtxHelpRemoveAction.java (+98 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.ctxhelp.details;
12
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject;
15
import org.eclipse.pde.internal.ui.PDEUIMessages;
16
17
/**
18
 * The action used to remove one or more elements from the context help xml.
19
 * @since 3.4
20
 */
21
public class CtxHelpRemoveAction extends Action {
22
23
	private CtxHelpObject[] fObjects;
24
25
	//The next object to be selected after the
26
	//selected object is removed
27
	private CtxHelpObject fObjectToSelect;
28
29
	public CtxHelpRemoveAction() {
30
		// Adds the 'Delete' keybinding to the action when displayed
31
		// in a context menu
32
		setActionDefinitionId("org.eclipse.ui.edit.delete"); //$NON-NLS-1$
33
		setText(PDEUIMessages.TocPage_remove);
34
	}
35
36
	/**
37
	 * Sets the objects to be removed when this action is run.
38
	 * @param objects objects to remove
39
	 */
40
	public void setToRemove(CtxHelpObject[] objects) {
41
		fObjects = objects;
42
	}
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.jface.action.Action#run()
46
	 */
47
	public void run() {
48
		if (fObjects == null)
49
			return;
50
51
		for (int i = 0; i < fObjects.length; ++i) {
52
			if (fObjects[i] != null && fObjects[i].canBeRemoved()) {
53
				CtxHelpObject parent = fObjects[i].getParent();
54
				if (parent != null) {
55
					determineNextSelection(parent, i);
56
					parent.removeChild(fObjects[i]);
57
				}
58
			}
59
		}
60
	}
61
62
	/**
63
	 * Determine the next object that should be selected
64
	 * after the designated object has been removed
65
	 * 
66
	 * @param parent The parent of the deleted object
67
	 */
68
	private void determineNextSelection(CtxHelpObject parent, int index) {
69
		// Select the next sibling
70
		fObjectToSelect = parent.getNextSibling(fObjects[index]);
71
		if (fObjectToSelect == null) {
72
			// No next sibling
73
			// Select the previous sibling
74
			fObjectToSelect = parent.getPreviousSibling(fObjects[index]);
75
			if (fObjectToSelect == null) {
76
				// No previous sibling
77
				// Select the parent
78
				fObjectToSelect = parent;
79
			}
80
		}
81
	}
82
83
	/**
84
	 * Returns the object that should be selected after the action is run.
85
	 * @return the object to select or <code>null</code>
86
	 */
87
	public CtxHelpObject getNextSelection() {
88
		return fObjectToSelect;
89
	}
90
91
	/**
92
	 * Clears the next selection returned by {@link #getNextSelection()}.
93
	 */
94
	public void clearNextSelection() {
95
		fObjectToSelect = null;
96
	}
97
98
}
(-)src/org/eclipse/pde/internal/core/itoc/ITocConstants.java (-21 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-19 Link Here
14
/**
14
/**
15
 * ITocConstants
15
 * ITocConstants
16
 * This interface contains all of the constants relevant to the TOC editor
16
 * This interface contains all of the constants relevant to the TOC editor
17
 * @since 3.4
17
 */
18
 */
18
public interface ITocConstants {
19
public interface ITocConstants {
19
20
Lines 33-45 Link Here
33
34
34
	public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$		
35
	public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$		
35
36
36
	public static final String ATTRIBUTE_TOPIC = ELEMENT_TOPIC; //$NON-NLS-1$
37
	public static final String ATTRIBUTE_TOPIC = ELEMENT_TOPIC;
37
38
38
	public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$		
39
	public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$		
39
40
40
	public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
41
	public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
41
42
42
	public static final String ATTRIBUTE_TOC = ELEMENT_TOC; //$NON-NLS-1$		
43
	public static final String ATTRIBUTE_TOC = ELEMENT_TOC;
43
44
44
	// Types
45
	// Types
45
46
Lines 51-72 Link Here
51
52
52
	public static final int TYPE_LINK = 3;
53
	public static final int TYPE_LINK = 3;
53
54
54
	// Enablement Elements
55
56
	public static final String ELEMENT_ENABLEMENT = "enablement"; //$NON-NLS-1$
57
58
	public static final String ELEMENT_TEST = "test"; //$NON-NLS-1$
59
60
	// Enablement Attributes
61
62
	public static final String ATTRIBUTE_PROPERTY = "property"; //$NON-NLS-1$		
63
64
	public static final String ATTRIBUTE_ARGS = "args"; //$NON-NLS-1$
65
66
	// Enablement Types
67
68
	public static final int TYPE_ENABLEMENT = 4;
69
70
	public static final int TYPE_TEST = 5;
71
72
}
55
}
(-)META-INF/MANIFEST.MF (+2 lines)
Lines 22-27 Link Here
22
 org.eclipse.pde.internal.core.icheatsheet;x-friends:="org.eclipse.pde.ui",
22
 org.eclipse.pde.internal.core.icheatsheet;x-friends:="org.eclipse.pde.ui",
23
 org.eclipse.pde.internal.core.icheatsheet.comp;x-friends:="org.eclipse.pde.ui",
23
 org.eclipse.pde.internal.core.icheatsheet.comp;x-friends:="org.eclipse.pde.ui",
24
 org.eclipse.pde.internal.core.icheatsheet.simple;x-friends:="org.eclipse.pde.ui",
24
 org.eclipse.pde.internal.core.icheatsheet.simple;x-friends:="org.eclipse.pde.ui",
25
 org.eclipse.pde.internal.core.ictxhelp;x-friends:="org.eclipse.pde.ui",
25
 org.eclipse.pde.internal.core.ifeature;x-friends:="org.eclipse.pde.ui",
26
 org.eclipse.pde.internal.core.ifeature;x-friends:="org.eclipse.pde.ui",
26
 org.eclipse.pde.internal.core.iproduct;x-friends:="org.eclipse.pde.ui",
27
 org.eclipse.pde.internal.core.iproduct;x-friends:="org.eclipse.pde.ui",
27
 org.eclipse.pde.internal.core.ischema;x-friends:="org.eclipse.pde.ui",
28
 org.eclipse.pde.internal.core.ischema;x-friends:="org.eclipse.pde.ui",
Lines 39-44 Link Here
39
 org.eclipse.pde.internal.core.text.build;x-friends:="org.eclipse.pde.ui",
40
 org.eclipse.pde.internal.core.text.build;x-friends:="org.eclipse.pde.ui",
40
 org.eclipse.pde.internal.core.text.bundle;x-friends:="org.eclipse.pde.ui",
41
 org.eclipse.pde.internal.core.text.bundle;x-friends:="org.eclipse.pde.ui",
41
 org.eclipse.pde.internal.core.text.cheatsheet.simple;x-friends:="org.eclipse.pde.ui",
42
 org.eclipse.pde.internal.core.text.cheatsheet.simple;x-friends:="org.eclipse.pde.ui",
43
 org.eclipse.pde.internal.core.text.ctxhelp;x-friends:="org.eclipse.pde.ui",
42
 org.eclipse.pde.internal.core.text.plugin;x-friends:="org.eclipse.pde.ui",
44
 org.eclipse.pde.internal.core.text.plugin;x-friends:="org.eclipse.pde.ui",
43
 org.eclipse.pde.internal.core.text.toc;x-friends:="org.eclipse.pde.ui",
45
 org.eclipse.pde.internal.core.text.toc;x-friends:="org.eclipse.pde.ui",
44
 org.eclipse.pde.internal.core.util;x-friends:="org.eclipse.pde.ui",
46
 org.eclipse.pde.internal.core.util;x-friends:="org.eclipse.pde.ui",
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpDescription.java (+82 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
/**
14
 * Represents a description entry in context help.  There may be one description
15
 * element for each context.  A description element will contain a CDATA string
16
 * explaining the context that the user will see in dynamic help.  Descriptions
17
 * are leaf objects.
18
 * 
19
 * @since 3.4
20
 * @see CtxHelpObject
21
 * @see CtxHelpModel
22
 * @see CtxHelpDocumentFactory
23
 */
24
public class CtxHelpDescription extends CtxHelpObject {
25
26
	private static final long serialVersionUID = 1L;
27
28
	public CtxHelpDescription(CtxHelpModel model) {
29
		super(model, ELEMENT_DESCRIPTION);
30
	}
31
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.pde.internal.core.text.toc.TocObject#canBeParent()
34
	 */
35
	public boolean canBeParent() {
36
		return false;
37
	}
38
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getType()
41
	 */
42
	public int getType() {
43
		return TYPE_DESCRIPTION;
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getName()
48
	 */
49
	public String getName() {
50
		return getDescription();
51
	}
52
53
	/**
54
	 * @return the XML content of this element containing the description or <code>null</code>
55
	 */
56
	public String getDescription() {
57
		return getXMLContent();
58
	}
59
60
	/**
61
	 * Sets the XML content of this element to the given description string.
62
	 * Passing <code>null</code> will set the content to be empty.
63
	 * @param description new content
64
	 */
65
	public void setDescription(String description) {
66
		setXMLContent(description);
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddChild(org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject)
71
	 */
72
	public boolean canAddChild(int objectType) {
73
		return false;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddSibling(int)
78
	 */
79
	public boolean canAddSibling(int objectType) {
80
		return objectType == TYPE_COMMAND || objectType == TYPE_TOPIC;
81
	}
82
}
(-)src/org/eclipse/pde/internal/core/ictxhelp/ICtxHelpConstants.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.ictxhelp;
12
13
/**
14
 * Interface containing constants used for the context help editor.
15
 * 
16
 * @since 3.4
17
 */
18
public interface ICtxHelpConstants {
19
20
	// Elements
21
22
	public static final String ELEMENT_ROOT = "contexts"; //$NON-NLS-1$
23
24
	public static final String ELEMENT_CONTEXT = "context"; //$NON-NLS-1$
25
26
	public static final String ELEMENT_DESCRIPTION = "description"; //$NON-NLS-1$
27
28
	public static final String ELEMENT_TOPIC = "topic"; //$NON-NLS-1$
29
30
	public static final String ELEMENT_COMMAND = "command"; //$NON-NLS-1$
31
32
	// Attributes
33
34
	public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
35
36
	public static final String ATTRIBUTE_TITLE = "title"; //$NON-NLS-1$	
37
38
	public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$		
39
40
	public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
41
42
	public static final String ATTRIBUTE_SERIAL = "serialization"; //$NON-NLS-1$	
43
44
	public static final String ATTRIBUTE_FILTER = "filter"; //$NON-NLS-1$	
45
46
	// Types
47
48
	public static final int TYPE_ROOT = 0;
49
50
	public static final int TYPE_CONTEXT = 1;
51
52
	public static final int TYPE_DESCRIPTION = 2;
53
54
	public static final int TYPE_TOPIC = 3;
55
56
	public static final int TYPE_COMMAND = 4;
57
58
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpModel.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import org.eclipse.jface.text.IDocument;
14
import org.eclipse.pde.core.IModel;
15
import org.eclipse.pde.core.IWritable;
16
import org.eclipse.pde.internal.core.NLResourceHelper;
17
import org.eclipse.pde.internal.core.text.XMLEditingModel;
18
import org.xml.sax.helpers.DefaultHandler;
19
20
/**
21
 * Model describing the elements of a context help xml file.
22
 * 
23
 * @since 3.4
24
 * @see CtxHelpRoot
25
 * @see CtxHelpDocumentFactory
26
 * @see CtxHelpDocumentHandler
27
 */
28
public class CtxHelpModel extends XMLEditingModel {
29
30
	private CtxHelpDocumentHandler fHandler;
31
	private CtxHelpDocumentFactory fFactory;
32
	private CtxHelpRoot fRoot;
33
34
	public CtxHelpModel(IDocument document, boolean isReconciling) {
35
		super(document, isReconciling);
36
	}
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.pde.internal.core.text.XMLEditingModel#createDocumentHandler(org.eclipse.pde.core.IModel, boolean)
40
	 */
41
	protected DefaultHandler createDocumentHandler(IModel model, boolean reconciling) {
42
		if (fHandler == null) {
43
			fHandler = new CtxHelpDocumentHandler(this, reconciling);
44
		}
45
		return fHandler;
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.pde.internal.core.text.AbstractEditingModel#createNLResourceHelper()
50
	 */
51
	protected NLResourceHelper createNLResourceHelper() {
52
		// Not needed
53
		return null;
54
	}
55
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.pde.internal.core.icheatsheet.simple.ITocModel#getFactory()
58
	 */
59
	public CtxHelpDocumentFactory getFactory() {
60
		if (fFactory == null) {
61
			fFactory = new CtxHelpDocumentFactory(this);
62
		}
63
		return fFactory;
64
	}
65
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.pde.internal.core.icheatsheet.simple.ITocModel#getToc()
68
	 */
69
	public CtxHelpRoot getCtxHelpRoot() {
70
		if (fRoot == null) {
71
			fRoot = getFactory().createRoot();
72
		}
73
		return fRoot;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.pde.internal.core.text.XMLEditingModel#getRoot()
78
	 */
79
	protected IWritable getRoot() {
80
		return getCtxHelpRoot();
81
	}
82
83
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpDocumentFactory.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import org.eclipse.pde.internal.core.ictxhelp.ICtxHelpConstants;
14
import org.eclipse.pde.internal.core.text.*;
15
16
/**
17
 * Handles the creation of document nodes representing the types of elements that
18
 * can exist in a context help xml file.
19
 * 
20
 * @since 3.4
21
 * @see CtxHelpObject
22
 * @see CtxHelpModel
23
 * @see CtxHelpDocumentHandler
24
 */
25
public class CtxHelpDocumentFactory extends DocumentNodeFactory implements IDocumentNodeFactory {
26
	private CtxHelpModel fModel;
27
28
	public CtxHelpDocumentFactory(CtxHelpModel model) {
29
		fModel = model;
30
	}
31
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.pde.internal.core.text.IDocumentNodeFactory#createDocumentNode(java.lang.String, org.eclipse.pde.internal.core.text.IDocumentElementNode)
34
	 */
35
	public IDocumentElementNode createDocumentNode(String name, IDocumentElementNode parent) {
36
		if (isRoot(name)) { // Root
37
			return createRoot();
38
		}
39
		if (isContext(name)) { // Context
40
			return createContext();
41
		}
42
		if (isDescription(name)) { // Link
43
			return createDescription();
44
		}
45
		if (isTopic(name)) { // Anchor
46
			return createTopic();
47
		}
48
		if (isCommand(name)) { // Anchor
49
			return createCommand();
50
		}
51
		return super.createDocumentNode(name, parent);
52
	}
53
54
	private boolean isRoot(String name) {
55
		return name.equals(ICtxHelpConstants.ELEMENT_ROOT);
56
	}
57
58
	private boolean isContext(String name) {
59
		return name.equals(ICtxHelpConstants.ELEMENT_CONTEXT);
60
	}
61
62
	private boolean isDescription(String name) {
63
		return name.equals(ICtxHelpConstants.ELEMENT_DESCRIPTION);
64
	}
65
66
	private boolean isTopic(String name) {
67
		return name.equals(ICtxHelpConstants.ELEMENT_TOPIC);
68
	}
69
70
	private boolean isCommand(String name) {
71
		return name.equals(ICtxHelpConstants.ELEMENT_COMMAND);
72
	}
73
74
	/**
75
	 * @return a new root object based on the current model
76
	 */
77
	public CtxHelpRoot createRoot() {
78
		return new CtxHelpRoot(fModel);
79
	}
80
81
	/**
82
	 * @return a new context object based on the current model
83
	 */
84
	public CtxHelpContext createContext() {
85
		return new CtxHelpContext(fModel);
86
	}
87
88
	/**
89
	 * @return a new description object based on the current model
90
	 */
91
	public CtxHelpDescription createDescription() {
92
		return new CtxHelpDescription(fModel);
93
	}
94
95
	/**
96
	 * @return a new topic object based on the current model
97
	 */
98
	public CtxHelpTopic createTopic() {
99
		return new CtxHelpTopic(fModel);
100
	}
101
102
	/**
103
	 * @return a new command object based on the current model
104
	 */
105
	public CtxHelpCommand createCommand() {
106
		return new CtxHelpCommand(fModel);
107
	}
108
109
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpCommand.java (+96 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
/**
14
 * Represents a command entry in context help.  Commands are used to launch
15
 * actions when clicked on by the user.  Commands are leaf objects.
16
 * 
17
 * @since 3.4
18
 * @see CtxHelpObject
19
 * @see CtxHelpModel
20
 * @see CtxHelpDocumentFactory
21
 */
22
public class CtxHelpCommand extends CtxHelpObject {
23
24
	private static final long serialVersionUID = 1L;
25
26
	public CtxHelpCommand(CtxHelpModel model) {
27
		super(model, ELEMENT_COMMAND);
28
	}
29
30
	/* (non-Javadoc)
31
	 * @see org.eclipse.pde.internal.core.text.toc.TocObject#canBeParent()
32
	 */
33
	public boolean canBeParent() {
34
		return false;
35
	}
36
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getType()
39
	 */
40
	public int getType() {
41
		return TYPE_COMMAND;
42
	}
43
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getName()
46
	 */
47
	public String getName() {
48
		return getLabel();
49
	}
50
51
	/**
52
	 * @return the value of the label attribute or <code>null</code> if the attribute does not exist
53
	 */
54
	public String getLabel() {
55
		return getXMLAttributeValue(ATTRIBUTE_LABEL);
56
	}
57
58
	/**
59
	 * Set the label attribute, passing <code>null</code> will set the
60
	 * attribute to be empty.
61
	 * @param label new value
62
	 */
63
	public void setLabel(String label) {
64
		setXMLAttribute(ATTRIBUTE_LABEL, label);
65
	}
66
67
	/**
68
	 * @return the value of the serialization attribute or <code>null</code> if the attribute does not exist
69
	 */
70
	public String getSerialization() {
71
		return getXMLAttributeValue(ATTRIBUTE_SERIAL);
72
	}
73
74
	/**
75
	 * Set the serialization attribute, passing <code>null</code> will set the
76
	 * attribute to be empty.
77
	 * @param serialization new value
78
	 */
79
	public void setSerialization(String serialization) {
80
		setXMLAttribute(ATTRIBUTE_HREF, serialization);
81
	}
82
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddChild(org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject)
85
	 */
86
	public boolean canAddChild(int objectType) {
87
		return false;
88
	}
89
90
	/* (non-Javadoc)
91
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddSibling(int)
92
	 */
93
	public boolean canAddSibling(int objectType) {
94
		return objectType == TYPE_COMMAND || objectType == TYPE_TOPIC;
95
	}
96
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpTopic.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.Path;
15
16
/**
17
 * Represents a topic entry in context help.  Topics are used to open related
18
 * help in other files.  Topics are leaf objects.
19
 * 
20
 * @since 3.4
21
 * @see CtxHelpObject
22
 * @see CtxHelpModel
23
 * @see CtxHelpDocumentFactory
24
 */
25
public class CtxHelpTopic extends CtxHelpObject {
26
27
	private static final long serialVersionUID = 1L;
28
29
	public CtxHelpTopic(CtxHelpModel model) {
30
		super(model, ELEMENT_TOPIC);
31
	}
32
33
	/* (non-Javadoc)
34
	 * @see org.eclipse.pde.internal.core.text.toc.TocObject#canBeParent()
35
	 */
36
	public boolean canBeParent() {
37
		return false;
38
	}
39
40
	/* (non-Javadoc)
41
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getType()
42
	 */
43
	public int getType() {
44
		return TYPE_TOPIC;
45
	}
46
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getName()
49
	 */
50
	public String getName() {
51
		return getLabel();
52
	}
53
54
	/**
55
	 * @return the value of the label attribute or <code>null</code> if the attribute does not exist
56
	 */
57
	public String getLabel() {
58
		return getXMLAttributeValue(ATTRIBUTE_LABEL);
59
	}
60
61
	/**
62
	 * Set the label attribute, passing <code>null</code> will set the
63
	 * attribute to be empty.
64
	 * @param label new value
65
	 */
66
	public void setLabel(String label) {
67
		setXMLAttribute(ATTRIBUTE_LABEL, label);
68
	}
69
70
	/**
71
	 * @return the value of the href attribute as a path or <code>null</code>
72
	 */
73
	public IPath getLocation() {
74
		String value = getXMLAttributeValue(ATTRIBUTE_HREF);
75
		if (value != null) {
76
			return new Path(value);
77
		}
78
		return null;
79
	}
80
81
	/**
82
	 * Set the href (link) attribute, passing <code>null</code> will set the
83
	 * attribute to be empty.
84
	 * @param path new value
85
	 */
86
	public void setLocation(IPath path) {
87
		if (path == null) {
88
			setXMLAttribute(ATTRIBUTE_HREF, null);
89
		} else {
90
			setXMLAttribute(ATTRIBUTE_HREF, path.toPortableString());
91
		}
92
	}
93
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddChild(org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject)
96
	 */
97
	public boolean canAddChild(int objectType) {
98
		return false;
99
	}
100
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddSibling(int)
103
	 */
104
	public boolean canAddSibling(int objectType) {
105
		return objectType == TYPE_COMMAND || objectType == TYPE_TOPIC;
106
	}
107
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpDocumentHandler.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import org.eclipse.jface.text.IDocument;
14
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
15
import org.eclipse.pde.internal.core.text.NodeDocumentHandler;
16
17
/**
18
 * Document handler for context help xml files.
19
 * 
20
 * @since 3.4
21
 * @see CtxHelpObject
22
 * @see CtxHelpModel
23
 * @see CtxHelpDocumentFactory
24
 */
25
public class CtxHelpDocumentHandler extends NodeDocumentHandler {
26
27
	private CtxHelpModel fModel;
28
29
	public CtxHelpDocumentHandler(CtxHelpModel model, boolean reconciling) {
30
		super(reconciling, model.getFactory());
31
		fModel = model;
32
	}
33
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.pde.internal.core.text.DocumentHandler#getDocument()
36
	 */
37
	protected IDocument getDocument() {
38
		return fModel.getDocument();
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.pde.internal.core.text.NodeDocumentHandler#getRootNode()
43
	 */
44
	protected IDocumentElementNode getRootNode() {
45
		return (IDocumentElementNode) fModel.getRoot();
46
	}
47
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpRoot.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
/**
14
 * Represents the root "contexts" entry in a context help xml file.  There may
15
 * be only one root node in the file and all other nodes must be inside the root.
16
 * The root may contain many context elements.
17
 * 
18
 * @since 3.4
19
 * @see CtxHelpObject
20
 * @see CtxHelpModel
21
 * @see CtxHelpDocumentFactory
22
 */
23
public class CtxHelpRoot extends CtxHelpObject {
24
25
	private static final long serialVersionUID = 1L;
26
27
	public CtxHelpRoot(CtxHelpModel model) {
28
		super(model, ELEMENT_ROOT);
29
		setInTheModel(true);
30
	}
31
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.pde.internal.core.text.plugin.PluginDocumentNode#isRoot()
34
	 */
35
	public boolean isRoot() {
36
		return true;
37
	}
38
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getType()
41
	 */
42
	public int getType() {
43
		return TYPE_ROOT;
44
	}
45
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canBeParent()
48
	 */
49
	public boolean canBeParent() {
50
		return true;
51
	}
52
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#getName()
55
	 */
56
	public String getName() {
57
		return ELEMENT_ROOT;
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddChild(org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject)
62
	 */
63
	public boolean canAddChild(int objectType) {
64
		return objectType == TYPE_CONTEXT;
65
	}
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddSibling(int)
69
	 */
70
	public boolean canAddSibling(int objectType) {
71
		return false;
72
	}
73
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpContext.java (+135 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
14
15
/**
16
 * Represents a context entry in context help.  Contexts have a specific id
17
 * that allows UI elements to be associated with a list of commands and topics
18
 * that are stored in the context.  Contexts may have one optional description
19
 * element and as many topic and command elements as needed.
20
 * 
21
 * @since 3.4
22
 * @see CtxHelpObject
23
 * @see CtxHelpModel
24
 * @see CtxHelpDocumentFactory
25
 */
26
public class CtxHelpContext extends CtxHelpObject {
27
28
	private static final long serialVersionUID = 1L;
29
30
	public CtxHelpContext(CtxHelpModel model) {
31
		super(model, ELEMENT_CONTEXT);
32
	}
33
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.pde.internal.core.text.toc.TocObject#canBeParent()
36
	 */
37
	public boolean canBeParent() {
38
		return true;
39
	}
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getType()
43
	 */
44
	public int getType() {
45
		return TYPE_CONTEXT;
46
	}
47
48
	/* (non-Javadoc)
49
	 * @see org.eclipse.pde.internal.core.toc.TocObject#getName()
50
	 */
51
	public String getName() {
52
		return getId();
53
	}
54
55
	/**
56
	 * @return the value of the id attribute or <code>null</code> if the attribute does not exist
57
	 */
58
	public String getId() {
59
		return getXMLAttributeValue(ATTRIBUTE_ID);
60
	}
61
62
	/**
63
	 * Set the id attribute, passing <code>null</code> will set the
64
	 * attribute to be empty.
65
	 * @param id new value
66
	 */
67
	public void setID(String id) {
68
		setXMLAttribute(ATTRIBUTE_ID, id);
69
	}
70
71
	/**
72
	 * @return the value of the title attribute or <code>null</code> if the attribute does not exist
73
	 */
74
	public String getTitle() {
75
		return getXMLAttributeValue(ATTRIBUTE_TITLE);
76
	}
77
78
	/**
79
	 * Set the title attribute, passing <code>null</code> will set the
80
	 * attribute to be empty.
81
	 * @param title new value
82
	 */
83
	public void setTitle(String title) {
84
		setXMLAttribute(ATTRIBUTE_TITLE, title);
85
	}
86
87
	/**
88
	 * Searches for a child description node and returns the string contents of that node.
89
	 * Returns <code>null</code> if no description node exists.
90
	 * @return description associated with this context or <code>null</code> no description exists
91
	 */
92
	public String getDescription() {
93
		IDocumentElementNode node = getChildNode(CtxHelpDescription.class);
94
		if (node instanceof CtxHelpDescription) {
95
			return ((CtxHelpDescription) node).getDescription();
96
		}
97
		return null;
98
	}
99
100
	/**
101
	 * Set the description to be associated with this context.  Searches for a child description node
102
	 * and updates the content with the given string.  If a description node does not exist, one will
103
	 * be created.  Passing <code>null</code> will remove any description node if one exists.
104
	 * @param description new value
105
	 */
106
	public void setDescription(String description) {
107
		IDocumentElementNode node = getChildNode(CtxHelpDescription.class);
108
		if (node instanceof CtxHelpDescription) {
109
			if (description == null) {
110
				removeChildNode(node, true);
111
			} else {
112
				((CtxHelpDescription) node).setDescription(description);
113
			}
114
		} else if (description != null) {
115
			CtxHelpDescription newDescription = getModel().getFactory().createDescription();
116
			newDescription.setDescription(description);
117
			addChildNode(newDescription, 0, true);
118
		}
119
	}
120
121
	/* (non-Javadoc)
122
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddChild(org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject)
123
	 */
124
	public boolean canAddChild(int objectType) {
125
		return objectType == TYPE_TOPIC || objectType == TYPE_COMMAND;
126
	}
127
128
	/* (non-Javadoc)
129
	 * @see org.eclipse.pde.internal.core.text.ctxhelp.CtxHelpObject#canAddSibling(int)
130
	 */
131
	public boolean canAddSibling(int objectType) {
132
		return objectType == TYPE_CONTEXT;
133
	}
134
135
}
(-)text/org/eclipse/pde/internal/core/text/ctxhelp/CtxHelpObject.java (+196 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.pde.internal.core.text.ctxhelp;
12
13
import java.io.Serializable;
14
import java.util.ArrayList;
15
import java.util.List;
16
import org.eclipse.pde.core.IModel;
17
import org.eclipse.pde.internal.core.ictxhelp.ICtxHelpConstants;
18
import org.eclipse.pde.internal.core.text.DocumentObject;
19
import org.eclipse.pde.internal.core.text.IDocumentElementNode;
20
21
/**
22
 * All modeled objects of a context help xml file must extend from this
23
 * abstract class.
24
 * 
25
 * @since 3.4
26
 * @see CtxHelpModel
27
 * @see CtxHelpDocumentFactory
28
 */
29
public abstract class CtxHelpObject extends DocumentObject implements ICtxHelpConstants, Serializable {
30
31
	private static final long serialVersionUID = 1L;
32
33
	/**
34
	 * Constructs the CtxHelpObject and initializes its attributes.
35
	 * 
36
	 * @param model The model to associate with this CtxHelpObject
37
	 * @param tagName The xml tag name for this object
38
	 */
39
	public CtxHelpObject(CtxHelpModel model, String tagName) {
40
		super(model, tagName);
41
	}
42
43
	/**
44
	 * @return the children of the object or an empty List if none exist.
45
	 */
46
	public List getChildren() {
47
		//Create a copy of the child list instead of 
48
		//returning the list itself. That way, our list
49
		//of children cannot be altered from outside
50
		ArrayList list = new ArrayList();
51
52
		// Add children of this topic
53
		IDocumentElementNode[] childNodes = getChildNodes();
54
		if (childNodes.length > 0) {
55
			for (int i = 0; i < childNodes.length; ++i) {
56
				if (childNodes[i] instanceof CtxHelpObject) {
57
					list.add(childNodes[i]);
58
				}
59
			}
60
		}
61
62
		return list;
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.pde.internal.core.text.DocumentElementNode#isLeafNode()
67
	 */
68
	public boolean isLeafNode() {
69
		return !canBeParent();
70
	}
71
72
	/**
73
	 * @return true iff this object is capable of containing children.
74
	 */
75
	public abstract boolean canBeParent();
76
77
	public abstract boolean canAddChild(int objectType);
78
79
	public abstract boolean canAddSibling(int objectType);
80
81
	//	public abstract boolean canAddSibling(int objectType);
82
83
	public void addChild(CtxHelpObject newObject, CtxHelpObject targetSibling, boolean insertBefore) {
84
		if (canAddChild(newObject.getType())) {
85
			int currentIndex = indexOf(targetSibling);
86
			if (!insertBefore) {
87
				currentIndex++;
88
			}
89
			addChildNode(newObject, currentIndex, true);
90
		}
91
	}
92
93
	public void addChild(CtxHelpObject newObject) {
94
		if (canAddChild(newObject.getType())) {
95
			addChildNode(newObject, true);
96
		}
97
	}
98
99
	/**
100
	 * @return the root model object that is an ancestor to this object.
101
	 */
102
	public CtxHelpModel getModel() {
103
		final IModel sharedModel = getSharedModel();
104
		if (sharedModel instanceof CtxHelpModel) {
105
			return (CtxHelpModel) sharedModel;
106
		}
107
		return null;
108
	}
109
110
	/**
111
	 * @return the root element that is an ancestor to this object.
112
	 */
113
	public CtxHelpRoot getRoot() {
114
		final CtxHelpModel model = getModel();
115
		if (model != null) {
116
			return model.getCtxHelpRoot();
117
		}
118
		return null;
119
	}
120
121
	/**
122
	 * @return the identifier for this object to be used when displaying the element to the user
123
	 */
124
	public abstract String getName();
125
126
	/**
127
	 * Get the concrete type of this object, must be one of the TYPE constants defined in ICtxHelpConstants.
128
	 * @see ICtxHelpConstants
129
	 */
130
	public abstract int getType();
131
132
	/**
133
	 * @return the parent of this object, or <code>null</code> if there is no parent.
134
	 */
135
	public CtxHelpObject getParent() {
136
		IDocumentElementNode parent = getParentNode();
137
		return parent instanceof CtxHelpObject ? (CtxHelpObject) parent : null;
138
	}
139
140
	/**
141
	 * Check if the object is a direct or indirect descendant
142
	 * of the object parameter.
143
	 * 
144
	 * @param obj The object to find in this object's ancestry
145
	 * @return true iff obj is an ancestor of this object
146
	 */
147
	public boolean descendsFrom(CtxHelpObject obj) {
148
		if (this.equals(obj)) {
149
			return true;
150
		}
151
		if (getParent() != null && obj.canBeParent()) {
152
			return getParent().descendsFrom(obj);
153
		}
154
		return false;
155
	}
156
157
	/**
158
	 * @param ctxHelpObject the child used to locate a sibling
159
	 * @return the object preceding the specified one in the list of children
160
	 */
161
	public CtxHelpObject getPreviousSibling(CtxHelpObject ctxHelpObject) {
162
		return (CtxHelpObject) getPreviousSibling(ctxHelpObject, CtxHelpObject.class);
163
	}
164
165
	/**
166
	 * @param ctxHelpObject the child used to locate a sibling
167
	 * @return the object proceeding the specified one in the list of children
168
	 */
169
	public CtxHelpObject getNextSibling(CtxHelpObject ctxHelpObject) {
170
		return (CtxHelpObject) getNextSibling(ctxHelpObject, CtxHelpObject.class);
171
	}
172
173
	/**
174
	 * @return true iff a this object can be removed
175
	 */
176
	public boolean canBeRemoved() {
177
		if (getType() == TYPE_ROOT) { //Semantic Rule: The root element can never be removed
178
			return false;
179
		}
180
		return true;
181
	}
182
183
	public void removeChild(CtxHelpObject object) {
184
		if (object.canBeRemoved()) {
185
			removeChildNode(object, true);
186
		}
187
	}
188
189
	/* (non-Javadoc)
190
	 * @see org.eclipse.pde.internal.core.toc.TocObject#moveChild(org.eclipse.pde.internal.core.toc.TocObject, int)
191
	 */
192
	public void moveChild(CtxHelpObject object, int newRelativeIndex) {
193
		moveChildNode(object, newRelativeIndex, true);
194
	}
195
196
}
(-)plugin.xml (+14 lines)
Lines 181-186 Link Here
181
            </parameter>
181
            </parameter>
182
         </describer>
182
         </describer>
183
      </content-type>
183
      </content-type>
184
      <content-type
185
            base-type="org.eclipse.core.runtime.xml"
186
            file-extensions="xml"
187
            id="ctxHelpFile"
188
            name="%contextHelp"
189
            priority="high">
190
         <describer
191
               class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber">
192
            <parameter
193
                  name="element"
194
                  value="contexts">
195
            </parameter>
196
         </describer>
197
      </content-type>
184
    </extension>
198
    </extension>
185
   
199
   
186
   
200
   
(-)plugin.properties (+1 lines)
Lines 23-28 Link Here
23
bundleManifest = Bundle Manifest File
23
bundleManifest = Bundle Manifest File
24
target.profile.content = Target Profile File
24
target.profile.content = Target Profile File
25
tableOfContents = Table of Contents File
25
tableOfContents = Table of Contents File
26
contextHelp = Context Help File
26
27
27
#Cheatsheets  
28
#Cheatsheets  
28
cheatsheet.category.pde = Plug-in Development
29
cheatsheet.category.pde = Plug-in Development

Return to bug 215091