Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2007-01-24 18:37:30 +0000
committerChris Goldthorpe2007-01-24 18:37:30 +0000
commitddfe7cea9e1a98302de446610a6a42e474b1a844 (patch)
tree47ed26171680fe8dfca5108907dbb390449aa99e /org.eclipse.ui.cheatsheets
parent1f0ba98c8421130ed8c2e1e6c320c9058216e095 (diff)
downloadeclipse.platform.ua-ddfe7cea9e1a98302de446610a6a42e474b1a844.tar.gz
eclipse.platform.ua-ddfe7cea9e1a98302de446610a6a42e474b1a844.tar.xz
eclipse.platform.ua-ddfe7cea9e1a98302de446610a6a42e474b1a844.zip
Open cheat sheet from URL, initial implementation.
Diffstat (limited to 'org.eclipse.ui.cheatsheets')
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java29
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java5
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties7
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetCategoryBasedSelectionAction.java25
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java4
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheet.java11
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java16
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserStatusUtility.java4
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java163
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetElement.java15
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetView.java4
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java64
-rw-r--r--org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/ViewUtilities.java44
13 files changed, 288 insertions, 103 deletions
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
index 553f91823..afd9f04a7 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/cheatsheets/OpenCheatSheetAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,17 +12,13 @@ package org.eclipse.ui.cheatsheets;
import java.net.URL;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
-import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
-import org.eclipse.ui.internal.cheatsheets.Messages;
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
+import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
/**
* Action for opening a cheat sheet. The cheat sheet can be specified
@@ -112,22 +108,10 @@ public final class OpenCheatSheetAction extends Action {
* @see IAction#run()
*/
public void run() {
- IWorkbench workbench = CheatSheetPlugin.getPlugin().getWorkbench();
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- IWorkbenchPage page = window.getActivePage();
+ CheatSheetView view = ViewUtilities.showCheatSheetView();
- CheatSheetView view = (CheatSheetView) page.findView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID);
if (view == null) {
- try {
- view = (CheatSheetView)page.showView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID);
- page.activate(view);
- } catch (PartInitException pie) {
- String message = Messages.LAUNCH_SHEET_ERROR;
- IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, pie);
- CheatSheetPlugin.getPlugin().getLog().log(status);
- org.eclipse.jface.dialogs.ErrorDialog.openError(window.getShell(), Messages.CHEAT_SHEET_ERROR_OPENING, null, pie.getStatus());
- return;
- }
+ return;
}
// Depending on which constructor was used open the cheat sheet view from a
// URL, an XML string or based on the id
@@ -138,6 +122,11 @@ public final class OpenCheatSheetAction extends Action {
} else {
view.setInput(id);
}
+ IWorkbench workbench = CheatSheetPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ IWorkbenchPage page = window.getActivePage();
page.bringToTop(view);
}
+
+
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
index 8308732f5..19bea88a0 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -49,6 +49,8 @@ public final class Messages extends NLS {
public static String ERROR_APPLYING_STATE_DATA;
public static String CHEATSHEET_STATE_RESTORE_FAIL_TITLE;
public static String CHEATSHEET_STATE_RESET_CONFIRM;
+ public static String CHEATSHEET_FROM_URL_WITH_EXEC;
+ public static String CHEATSHEET_FROM_URL_WITH_EXEC_TITLE;
public static String ERROR_APPLYING_STATE_DATA_LOG;
public static String INITIAL_VIEW_DIRECTIONS;
public static String ERROR_LOADING_CHEATSHEET_CONTENT;
@@ -114,6 +116,7 @@ public final class Messages extends NLS {
public static String SELECTION_DIALOG_FILEPICKER_BROWSE;
public static String SELECTION_DIALOG_OPEN_REGISTERED;
public static String SELECTION_DIALOG_OPEN_FROM_FILE;
+ public static String SELECTION_DIALOG_OPEN_FROM_URL;
public static String COMPOSITE_PAGE_REVIEW_TASK;
public static String COMPOSITE_PAGE_GOTO_TASK;
public static String COMPOSITE_PAGE_START_TASK;
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
index 3bb105d68..e6dbf7413 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/Messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2003, 2006 IBM Corporation and others.
+# Copyright (c) 2003, 2007 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -149,6 +149,11 @@ SELECTION_DIALOG_FILEPICKER_TITLE = Select Cheat Sheet Content File
SELECTION_DIALOG_FILEPICKER_BROWSE = &Browse...
SELECTION_DIALOG_OPEN_REGISTERED = Select a cheat sheet from the &list:
SELECTION_DIALOG_OPEN_FROM_FILE = Select a cheat sheet from a &file:
+SELECTION_DIALOG_OPEN_FROM_URL = Enter the &URL of a cheat sheet:
+
+
+CHEATSHEET_FROM_URL_WITH_EXEC = This cheat sheet contains actions and/or commands and may not work on all versions of Eclipse.
+CHEATSHEET_FROM_URL_WITH_EXEC_TITLE = Open cheat sheet from URL
# Composite Cheatsheets
ERROR_MULTIPLE_ERRORS = Multiple errors detected.
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetCategoryBasedSelectionAction.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetCategoryBasedSelectionAction.java
index 777418496..299645c57 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetCategoryBasedSelectionAction.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/actions/CheatSheetCategoryBasedSelectionAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,17 +10,13 @@
*******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.actions;
-import java.io.File;
-import java.net.MalformedURLException;
-
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.PlatformUI;
-
-import org.eclipse.ui.cheatsheets.*;
import org.eclipse.ui.internal.cheatsheets.dialogs.CheatSheetCategoryBasedSelectionDialog;
-import org.eclipse.ui.internal.cheatsheets.registry.*;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionElement;
+import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader;
/**
* Action to programmatically open the CheatSheet selection dialog.
@@ -63,25 +59,12 @@ public class CheatSheetCategoryBasedSelectionAction extends Action {
CheatSheetCategoryBasedSelectionDialog dialog = new CheatSheetCategoryBasedSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), cheatSheets);
- if(dialog.open() != Window.OK || dialog.getResult().length != 1) {
+ if(dialog.open() != Window.OK || !dialog.getStatus().isOK()) {
notifyResult(false);
return;
}
notifyResult(true);
-
- CheatSheetElement result = (CheatSheetElement)dialog.getResult()[0];
-
- if (result.isRegistered()) {
- new OpenCheatSheetAction(result.getID()).run();
- } else {
- File contentFile = new File(result.getContentFile());
- try {
- new OpenCheatSheetAction(result.getID(), result.getID() ,contentFile.toURL()).run();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
}
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
index 3b5c493ac..78de00d4e 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/composite/views/CheatsheetTaskEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -63,7 +63,7 @@ public class CheatsheetTaskEditor extends TaskEditor {
if (id == null) {
id = task.getId();
}
- viewer.setInput(id, task.getName(), url, stateManager);
+ viewer.setInput(id, task.getName(), url, stateManager, false);
} catch (MalformedURLException e) {
String message = NLS.bind(Messages.ERROR_OPENING_FILE_IN_PARSER, (new Object[] {path}));
viewer.showError(message);
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheet.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheet.java
index 62962584c..94a8d23b9 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheet.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheet.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@ public class CheatSheet implements ICheatSheet {
protected String title;
private Item introItem;
private ArrayList items;
+ private boolean containsCommandOrAction;
/**
* Creates a new cheat sheet.
@@ -90,4 +91,12 @@ public class CheatSheet implements ICheatSheet {
}
items.addAll(c);
}
+
+ public void setContainsCommandOrAction(boolean containsCommandOrAction) {
+ this.containsCommandOrAction = containsCommandOrAction;
+ }
+
+ public boolean isContainsCommandOrAction() {
+ return containsCommandOrAction;
+ }
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
index b326a5c26..434835e6a 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/CheatSheetParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -74,6 +74,10 @@ public class CheatSheetParser implements IStatusContainer {
public static final int ANY = 3;
private IStatus status;
+
+ private int commandCount;
+
+ private int actionCount;
/**
@@ -215,6 +219,13 @@ public class CheatSheetParser implements IStatusContainer {
String[] params = null;
+ if (executable instanceof CheatSheetCommand) {
+ commandCount++;
+ }
+ if (executable instanceof Action) {
+ actionCount++;
+ }
+
NamedNodeMap attributes = executableNode.getAttributes();
if (attributes != null) {
for (int x = 0; x < attributes.getLength(); x++) {
@@ -857,6 +868,8 @@ public class CheatSheetParser implements IStatusContainer {
public ICheatSheet parse(ParserInput input, int cheatSheetKind) {
status = Status.OK_STATUS;
+ commandCount = 0;
+ actionCount = 0;
if(input == null) {
return null;
}
@@ -1013,6 +1026,7 @@ public class CheatSheetParser implements IStatusContainer {
return null;
}
+ cheatSheet.setContainsCommandOrAction(actionCount != 0 || commandCount != 0);
return cheatSheet;
}
throw new CheatSheetParserException(Messages.ERROR_PARSING_CHEATSHEET_CONTENTS);
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserStatusUtility.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserStatusUtility.java
index 77aa0e9be..a53116729 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserStatusUtility.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/data/ParserStatusUtility.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,7 @@ import org.eclipse.ui.internal.cheatsheets.Messages;
public class ParserStatusUtility {
- private final static int PARSER_ERROR = 1001; // TODO is there another number that would be more meaningful
+ public final static int PARSER_ERROR = 1001; // TODO is there another number that would be more meaningful
/**
* Modify an existing IStatus to add information about a new error/warning.
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
index 69fd75005..d765ddbd6 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/dialogs/CheatSheetCategoryBasedSelectionDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,14 +10,20 @@
*******************************************************************************/
package org.eclipse.ui.internal.cheatsheets.dialogs;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -30,6 +36,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ModifyEvent;
@@ -44,26 +51,31 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.activities.ITriggerPoint;
import org.eclipse.ui.activities.WorkbenchActivityHelper;
-import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.ui.cheatsheets.OpenCheatSheetAction;
import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
import org.eclipse.ui.internal.cheatsheets.Messages;
+import org.eclipse.ui.internal.cheatsheets.data.ParserStatusUtility;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionElement;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetCollectionSorter;
import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
+import org.eclipse.ui.internal.cheatsheets.state.DefaultStateManager;
+import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
+import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchAdapter;
/**
* Dialog to allow the user to select a cheat sheet from a list.
*/
-public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
+public class CheatSheetCategoryBasedSelectionDialog extends TrayDialog //extends SelectionDialog
implements ISelectionChangedListener {
private static final String CHEAT_SHEET_SELECTION_HELP_ID = "org.eclipse.ui.cheatsheets.cheatSheetSelection"; //$NON-NLS-1$
@@ -83,7 +95,11 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
private Button selectFileRadio;
+ private Button selectUrlRadio;
+
private Text selectFileText;
+
+ private Text selectUrlText;
private ActivityViewerFilter activityViewerFilter = new ActivityViewerFilter();
@@ -97,12 +113,22 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
private final static String STORE_SELECTED_CHEATSHEET_ID = "CheatSheetCategoryBasedSelectionDialog.STORE_SELECTED_CHEATSHEET_ID"; //$NON-NLS-1$
- private final static String STORE_RADIO_SETTING = "CheatSheetCategoryBasedSelectionDialog.STORE_RADIO_SETTING"; //$NON-NLS-1$
+ private final static String STORE_RADIO_SETTING = "CheatSheetCategoryBasedSelectionDialog.STORE_RADIO_SELECTION"; //$NON-NLS-1$
private final static String STORE_CHEATSHEET_FILENAME = "CheatSheetCategoryBasedSelectionDialog.STORE_CHEATSHEET_FILENAME"; //$NON-NLS-1$
+ private final static String STORE_CHEATSHEET_URL = "CheatSheetCategoryBasedSelectionDialog.STORE_CHEATSHEET_URL"; //$NON-NLS-1$
+
+ private static final int RADIO_REGISTERED = 1;
+ private static final int RADIO_FILE = 2;
+ private static final int RADIO_URL = 3;
+
private Button browseFileButton;
+ private String title;
+
+ private IStatus status = Status.OK_STATUS;
+
private static class ActivityViewerFilter extends ViewerFilter {
private boolean hasEncounteredFilteredItem = false;
@@ -173,8 +199,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
this.cheatsheetCategories = cheatsheetCategories;
- setTitle(Messages.CHEAT_SHEET_SELECTION_DIALOG_TITLE);
- setMessage(Messages.CHEAT_SHEET_SELECTION_DIALOG_MSG);
+ this.title = Messages.CHEAT_SHEET_SELECTION_DIALOG_TITLE;
setShellStyle(getShellStyle() | SWT.RESIZE);
}
@@ -184,10 +209,10 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
*/
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
+ if (title != null) {
+ newShell.setText(title);
+ }
newShell.setImage(CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.CHEATSHEET_VIEW));
- //TODO need to add help context id
- // WorkbenchHelp.setHelp(newShell,
- // IHelpContextIds.WELCOME_PAGE_SELECTION_DIALOG);
}
/*
@@ -273,7 +298,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
}
});
- // Create radio button
+ // Create radio button for select from file
selectFileRadio = new Button(outerContainer, SWT.RADIO);
selectFileRadio.setText(Messages.SELECTION_DIALOG_OPEN_FROM_FILE);
@@ -295,6 +320,13 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
browseFileButton.setText(Messages.SELECTION_DIALOG_FILEPICKER_BROWSE);
setButtonLayoutData(browseFileButton);
+ // Create radio button for select from URL
+ selectUrlRadio = new Button(outerContainer, SWT.RADIO);
+ selectUrlRadio.setText(Messages.SELECTION_DIALOG_OPEN_FROM_URL);
+ selectUrlText = new Text(outerContainer, SWT.BORDER);
+ GridData suTextData = new GridData(GridData.FILL_HORIZONTAL);
+ selectUrlText.setLayoutData(suTextData);
+
restoreWidgetValues();
restoreFileSettings();
@@ -306,6 +338,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
selectFileText.addModifyListener(new FileTextListener());
browseFileButton.addSelectionListener(new BrowseListener());
selectRegisteredRadio.addSelectionListener(new RadioSelectionListener());
+ selectUrlRadio.addSelectionListener(new RadioSelectionListener());
checkRadioButtons();
return outerContainer;
}
@@ -360,6 +393,7 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
showAllButton.setEnabled(selectRegisteredRadio.getSelection());
}
treeViewer.getTree().setEnabled(selectRegisteredRadio.getSelection());
+ selectUrlText.setEnabled(selectUrlRadio.getSelection());
setOkButton();
}
@@ -484,8 +518,10 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
private void setOkButton() {
if (selectRegisteredRadio.getSelection()) {
enableOKButton(currentSelection != null);
- } else {
+ } else if (selectFileRadio.getSelection() ){
enableOKButton(selectFileText.getText().length() > 0);
+ } else {
+ enableOKButton(selectUrlText.getText().length() > 0);
}
}
@@ -495,8 +531,10 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
protected void okPressed() {
if (selectFileRadio.getSelection()) {
setResultFromFile();
- } else {
+ } else if (selectRegisteredRadio.getSelection() ){
setResultFromTree();
+ } else {
+ setResultFromUrl();
}
// save our selection state
@@ -507,14 +545,12 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
private void setResultFromTree() {
if (currentSelection != null) {
- ArrayList result = new ArrayList(1);
ITriggerPoint triggerPoint = PlatformUI.getWorkbench()
.getActivitySupport().getTriggerPointManager()
.getTriggerPoint(ICheatSheetResource.TRIGGER_POINT_ID);
if (WorkbenchActivityHelper.allowUseOf(triggerPoint,
currentSelection)) {
- result.add(currentSelection);
- setResult(result);
+ new OpenCheatSheetAction(currentSelection.getID()).run();
}
}
}
@@ -527,17 +563,58 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
if (extensionIndex > 0) {
id = id.substring(0, extensionIndex);
}
+ // Use the id as the name
+ URL url = null;
+ boolean opened = false;
+
+ try {
+ File contentFile = new File(selectFileText.getText());
+ url = contentFile.toURL();
+ new OpenCheatSheetAction(id, id ,url).run();
+ opened = true;
+ } catch (MalformedURLException e) {
+ opened = false;
+ }
+ if (!opened) {
+ String message = NLS.bind(Messages.ERROR_OPENING_FILE, (new Object[] {selectFileText.getText()}));
+ status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, ParserStatusUtility.PARSER_ERROR, message, null);
+ CheatSheetView view = ViewUtilities.showCheatSheetView();
+ view.getCheatSheetViewer().showError(message);
+ }
+ }
+
+ private void setResultFromUrl() {
+ // Use the filename without extension as the id of this cheatsheet
+ IPath filePath = new Path(selectUrlText.getText());
+ String id = filePath.lastSegment();
+ int extensionIndex = id.indexOf('.');
+ if (extensionIndex > 0) {
+ id = id.substring(0, extensionIndex);
+ }
// Use the id as the name
- CheatSheetElement element = new CheatSheetElement(id);
- element.setID(id);
- element.setContentFile(selectFileText.getText());
- setSelectionResult(new Object[]{element});
+ URL url = null;
+ boolean opened = false;
+ CheatSheetView view = ViewUtilities.showCheatSheetView();
+ if (view == null) {
+ return;
+ }
+ try {
+ url = new URL(selectUrlText.getText());
+ view.getCheatSheetViewer().setInput(id, id, url, new DefaultStateManager(), true);
+ opened = true;
+ } catch (MalformedURLException e) {
+ opened = false;
+ }
+ if (!opened) {
+ String message = NLS.bind(Messages.ERROR_OPENING_FILE, (new Object[] {selectUrlText.getText()}));
+ status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, ParserStatusUtility.PARSER_ERROR, message, null);
+ view.getCheatSheetViewer().showError(message);
+ }
}
/**
- * Set self's widgets to the values that they held last time this page was
- * open
- *
+ * Set's widgets to the values that they held last time this page was
+ * opened
*/
protected void restoreWidgetValues() {
String[] expandedCategoryPaths = settings
@@ -554,12 +631,22 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
* Restores the state of the radio button and file name fields
*/
private void restoreFileSettings() {
- boolean isFileSelected = settings.getBoolean(STORE_RADIO_SETTING);
- selectFileRadio.setSelection(isFileSelected);
- selectRegisteredRadio.setSelection(!isFileSelected);
+ int radioSetting = 0;
+ try {
+ radioSetting = settings.getInt(STORE_RADIO_SETTING);
+ }
+ catch(NumberFormatException n) {
+ }
+ selectFileRadio.setSelection(radioSetting == RADIO_FILE);
+ selectRegisteredRadio.setSelection(radioSetting == RADIO_REGISTERED);
+ selectUrlRadio.setSelection(radioSetting == RADIO_URL);
String fileName = settings.get(STORE_CHEATSHEET_FILENAME);
if (fileName != null) {
selectFileText.setText(fileName);
+ }
+ String url = settings.get(STORE_CHEATSHEET_URL);
+ if (url != null) {
+ selectUrlText.setText(url);
}
}
@@ -641,8 +728,19 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
* Stores the state of the radio button and file name fields
*/
private void storeFileSettings() {
- settings.put(STORE_RADIO_SETTING, selectFileRadio.getSelection());
- settings.put(STORE_CHEATSHEET_FILENAME, selectFileText.getText());
+ int radioSetting = 0;
+ if (selectRegisteredRadio.getSelection()) {
+ radioSetting = 1;
+ }
+ if (selectFileRadio.getSelection()) {
+ radioSetting = 2;
+ }
+ if (selectUrlRadio.getSelection()) {
+ radioSetting = 3;
+ }
+ settings.put(STORE_RADIO_SETTING, radioSetting);
+ settings.put(STORE_CHEATSHEET_FILENAME, selectFileText.getText());
+ settings.put(STORE_CHEATSHEET_URL, selectUrlText.getText());
}
/* (non-Javadoc)
@@ -658,4 +756,15 @@ public class CheatSheetCategoryBasedSelectionDialog extends SelectionDialog
}
return section;
}
+
+ private Label createMessageArea(Composite composite) {
+ Label label = new Label(composite, SWT.NONE);
+ label.setText(Messages.CHEAT_SHEET_SELECTION_DIALOG_MSG);
+ label.setFont(composite.getFont());
+ return label;
+ }
+
+ public IStatus getStatus() {
+ return status ;
+ }
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetElement.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetElement.java
index d5bc0a64e..bef87cb20 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetElement.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/registry/CheatSheetElement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,6 +32,7 @@ public class CheatSheetElement extends WorkbenchAdapter implements IAdaptable, I
private boolean composite;
private boolean registered = false;
private String contentXml;
+ private String href;
/**
* Create a new instance of this class
@@ -63,7 +64,7 @@ public class CheatSheetElement extends WorkbenchAdapter implements IAdaptable, I
}
/**
- * Answer the contentFile parameter of this element
+ * Get the content File path of this element
*
* @return java.lang.String
*/
@@ -114,7 +115,7 @@ public class CheatSheetElement extends WorkbenchAdapter implements IAdaptable, I
/**
* Set the contentFile parameter of this element
*
- * @param value the URL of the content file
+ * @param value the path of the content file
*/
public void setContentFile(String value) {
contentFile = value;
@@ -224,4 +225,12 @@ public class CheatSheetElement extends WorkbenchAdapter implements IAdaptable, I
return contentXml;
}
+ public void setHref(String contentPath) {
+ this.href = contentPath;
+ }
+
+ public String getHref() {
+ return href;
+ }
+
}
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetView.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetView.java
index 28a84ccca..a2bac53b8 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetView.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2006 IBM Corporation and others.
+ * Copyright (c) 2003, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -193,7 +193,7 @@ public class CheatSheetView extends ViewPart {
} else {
contentMemento.putString(ICheatSheetResource.MEMENTO_ID, element.getID());
contentMemento.putString(ICheatSheetResource.MEMENTO_NAME, element.getLabel(null));
- contentMemento.putString(ICheatSheetResource.MEMENTO_URL, element.getContentFile());
+ contentMemento.putString(ICheatSheetResource.MEMENTO_URL, element.getHref());
}
// Make sure the current cheat sheet is saved
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
index 0a88c5569..088771665 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetViewer.java
@@ -121,6 +121,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
private String restorePath;
private int dialogReturnCode;
+ private boolean isRestricted;
/**
* The constructor.
@@ -579,6 +580,17 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
control.layout(true);
}
+ private void showStartPage() {
+ setCollapseExpandButtonEnabled(false);
+ internalDispose();
+
+ howToBegin = new Label(control, SWT.WRAP);
+ howToBegin.setText(Messages.INITIAL_VIEW_DIRECTIONS);
+ howToBegin.setLayoutData(new GridData(GridData.FILL_BOTH));
+ currentPage = null;
+ control.layout(true);
+ }
+
private void createErrorPage(IStatus status) {
setCollapseExpandButtonEnabled(false);
currentPage = new ErrorPage(status);
@@ -622,9 +634,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
}
});
- howToBegin = new Label(control, SWT.WRAP);
- howToBegin.setText(Messages.INITIAL_VIEW_DIRECTIONS);
- howToBegin.setLayoutData(new GridData(GridData.FILL_BOTH));
+ showStartPage();
Display display = parent.getDisplay();
@@ -858,7 +868,21 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
control.setRedraw(false);
if (model instanceof CheatSheet) {
- currentPage = new CheatSheetPage((CheatSheet)model, viewItemList, this);
+ CheatSheet cheatSheetModel = (CheatSheet)model;
+
+ if (isRestricted && cheatSheetModel.isContainsCommandOrAction()) {
+ boolean isOK = MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.CHEATSHEET_FROM_URL_WITH_EXEC_TITLE,
+ Messages.CHEATSHEET_FROM_URL_WITH_EXEC);
+
+ if (!isOK) {
+ control.setRedraw(true);
+ showStartPage();
+ return true;
+ }
+ }
+
+ currentPage = new CheatSheetPage(cheatSheetModel, viewItemList, this);
setCollapseExpandButtonEnabled(true);
} else if (model instanceof CompositeCheatSheetModel) {
CompositeCheatSheetModel compositeCheatSheetModel = ((CompositeCheatSheetModel)model);
@@ -927,6 +951,15 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
return false;
}
+ /*
+ * Show the collapse/expand button if we have access to the toolbar
+ */
+ private void setCollapseExpandButtonEnabled(boolean enable) {
+ if (expandRestoreAction != null) {
+ expandRestoreAction.setEnabled(enable);
+ }
+ }
+
/**
* Returns whether or not the currently active item requires opening a
* modal dialog.
@@ -1134,7 +1167,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
if (contentURL == null) {
try {
- contentURL = new URL(element.getContentFile());
+ contentURL = new URL(element.getHref());
} catch (MalformedURLException mue) {
}
}
@@ -1184,6 +1217,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
invalidCheatSheetId = true;
} else {
invalidCheatSheetId = false;
+ this.isRestricted = false;
}
}
@@ -1200,7 +1234,7 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
* @see org.eclipse.ui.cheatsheets.ICheatSheetViewer#setInput(java.lang.String, java.lang.String, java.net.URL)
*/
public void setInput(String id, String name, URL url) {
- setInput(id, name, url, new DefaultStateManager());
+ setInput(id, name, url, new DefaultStateManager(), false);
}
public void setInputFromXml(String id, String name, String xml, String basePath) {
@@ -1210,23 +1244,26 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
CheatSheetElement element = new CheatSheetElement(name);
element.setID(id);
element.setContentXml(xml);
- element.setContentFile(basePath);
+ element.setHref(basePath);
nullCheatSheetId = false;
invalidCheatSheetId = false;
+ isRestricted = false;
setContent(element, new NoSaveStateManager());
}
- public void setInput(String id, String name, URL url, ICheatSheetStateManager inputStateManager) {
+ public void setInput(String id, String name, URL url,
+ ICheatSheetStateManager inputStateManager, boolean isRestricted) {
if (id == null || name == null || url == null) {
throw new IllegalArgumentException();
}
CheatSheetElement element = new CheatSheetElement(name);
element.setID(id);
- element.setContentFile(url.toString());
+ element.setHref(url.toString());
nullCheatSheetId = false;
invalidCheatSheetId = false;
+ this.isRestricted = isRestricted;
setContent(element, inputStateManager);
}
@@ -1295,15 +1332,6 @@ public class CheatSheetViewer implements ICheatSheetViewer, IMenuContributor {
}
}
- /*
- * Show the collapse/expand button if we have access to the toolbar
- */
- private void setCollapseExpandButtonEnabled(boolean enable) {
- if (expandRestoreAction != null) {
- expandRestoreAction.setEnabled(enable);
- }
- }
-
public void showError(String message) {
internalDispose();
if(howToBegin != null) {
diff --git a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/ViewUtilities.java b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/ViewUtilities.java
index 8ea5b36af..43557c701 100644
--- a/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/ViewUtilities.java
+++ b/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/ViewUtilities.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,14 +11,24 @@
package org.eclipse.ui.internal.cheatsheets.views;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
+import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource;
+import org.eclipse.ui.internal.cheatsheets.Messages;
+
/**
* Contains static functions used in cheat sheet display
*/
public class ViewUtilities {
- /*
- * Ampersands need to be escaped before being passed to a Label
- */
+ /**
+ * Escape any ampersands used in a label
+ **/
public static String escapeForLabel(String message) {
// Make the most common case - i.e. no ampersand the
// most efficient
@@ -38,5 +48,31 @@ public class ViewUtilities {
result.append(message.substring(next));
return result.toString();
}
+
+ /**
+ * Get the cheaetSheetView, opening it if necessary and making visible
+ * @return The cheat sheet view, or null if it could not be opened.
+ */
+ public static CheatSheetView showCheatSheetView() {
+ CheatSheetView view;
+ IWorkbench workbench = CheatSheetPlugin.getPlugin().getWorkbench();
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ IWorkbenchPage page = window.getActivePage();
+
+ view = (CheatSheetView) page.findView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID);
+ if (view == null) {
+ try {
+ view = (CheatSheetView)page.showView(ICheatSheetResource.CHEAT_SHEET_VIEW_ID);
+ page.activate(view);
+ } catch (PartInitException pie) {
+ String message = Messages.LAUNCH_SHEET_ERROR;
+ IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, pie);
+ CheatSheetPlugin.getPlugin().getLog().log(status);
+ org.eclipse.jface.dialogs.ErrorDialog.openError(window.getShell(), Messages.CHEAT_SHEET_ERROR_OPENING, null, pie.getStatus());
+ return null;
+ }
+ }
+ return view;
+ }
}

Back to the top