krysalis-version/src/java/org/krysalis/version/eclipse/plugin/editor ConstraintEditor.java,NONE,1.1 ConstraintContentOutlineDragListener.java,NONE,1.1 ConstraintMarkerResolutionGenerator.java,NONE,1.1 AddSentenceResolution.java,NONE,1.1 ConstraintContentOutlinePage.java,NONE,1.1
[email protected] Fri, 21 Mar 2003 15:33:00 -0800
| Newsgroups | gmane.comp.krysalis.sandbox |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/editor
In directory sc8-pr-cvs1:/tmp/cvs-serv22996/src/java/org/krysalis/version/eclipse/plugin/editor
Added Files:
ConstraintEditor.java
ConstraintContentOutlineDragListener.java
ConstraintMarkerResolutionGenerator.java
AddSentenceResolution.java ConstraintContentOutlinePage.java
Log Message:
Constraint changes
--- NEW FILE: ConstraintEditor.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.editor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.krysalis.version.eclipse.plugin.util.IConstraintConstants;
/**
* This class implements the ConstraintEditor. Since the constraint editor is
* mostly just a text editor, there is very little implemented in this actual
* class. It can be regarded as simply decorating the text editor with a
* content outline.
*/
public class ConstraintEditor extends TextEditor
{
protected ConstraintContentOutlinePage page;
private final static String ATT_1 = IConstraintConstants.PREFIX + "attribute1"; //$NON-NLS-1$
private final static String ATT_2 = IConstraintConstants.PREFIX + "attribute2"; //$NON-NLS-1$
private final static String ATT_3 = IConstraintConstants.PREFIX + "attribute3"; //$NON-NLS-1$
private final static String ATT_4 = IConstraintConstants.PREFIX + "attribute4"; //$NON-NLS-1$
private final static String ATT_5 = IConstraintConstants.PREFIX + "attribute5"; //$NON-NLS-1$
/**
* Creates a new ConstraintEditor.
*/
public ConstraintEditor()
{
super();
}
/** (non-Javadoc)
* Method declared on IEditorPart
*/
public void doSave(IProgressMonitor monitor)
{
super.doSave(monitor);
if (page != null)
page.update();
}
/** (non-Javadoc)
* Method declared on IAdaptable
*/
public Object getAdapter(Class key)
{
System.out.println("ConstraintEditor::getAdapter");
if (key.equals(IContentOutlinePage.class))
{
System.out.println("ConstraintEditor::getAdapter For Outline");
IEditorInput input = getEditorInput();
if (input instanceof IFileEditorInput)
{
page = new ConstraintContentOutlinePage(((IFileEditorInput) input).getFile());
System.out.println("returning outline");
return page;
}
}
return super.getAdapter(key);
}
/** (non-Javadoc)
* Method declared on AbstractTextEditor
*/
protected void editorContextMenuAboutToShow(IMenuManager parentMenu)
{
super.editorContextMenuAboutToShow(parentMenu);
/*
parentMenu.add(new Separator());
IMenuManager subMenu = new MenuManager(MessageUtil.getString("Add"));
parentMenu.add(subMenu);
if (subMenu != null)
{
// Add constraint actions with various attributes
Object[][] att = new Object[][] { { IConstraintConstants.MARKER_ATT_ID, new Integer(1234)}
};
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "1", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + " id=1234")); //$NON-NLS-1$ //$NON-NLS-2$
att = new Object[][] { { IConstraintConstants.MARKER_ATT_LEVEL, new Integer(7)}
};
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "2", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + " level=7")); //$NON-NLS-1$ //$NON-NLS-2$
att = new Object[][] { { IConstraintConstants.MARKER_ATT_LEVEL, new Integer(7)}, {
IConstraintConstants.MARKER_ATT_DEPT, "infra" }
}; //$NON-NLS-1$
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "3", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + " level=7, department=infra")); //$NON-NLS-1$ //$NON-NLS-2$
att = new Object[][] { { IConstraintConstants.MARKER_ATT_CODE, "red" }
}; //$NON-NLS-1$
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "4", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + " code=red")); //$NON-NLS-1$ //$NON-NLS-2$
att = new Object[][] { { IConstraintConstants.MARKER_ATT_LANG, "english" }
}; //$NON-NLS-1$
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "5", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + " language=english")); //$NON-NLS-1$ //$NON-NLS-2$
att = new Object[][] { { IConstraintConstants.MARKER_ATT_ID, new Integer(1234)}, {
IConstraintConstants.MARKER_ATT_LEVEL, new Integer(7)
}, {
IConstraintConstants.MARKER_ATT_DEPT, "infra" }, //$NON-NLS-1$
{
IConstraintConstants.MARKER_ATT_CODE, "red" }, //$NON-NLS-1$
{
IConstraintConstants.MARKER_ATT_LANG, "english" }
}; //$NON-NLS-1$
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "6", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example") + //$NON-NLS-1$
" id=1234, level=7, department=infra, code=red, language=english")); //$NON-NLS-1$
att = new Object[0][0];
subMenu.add(new AddConstraintMarkerAction(this, MessageUtil.getString("Add_constraint_marker_action_label") + "7", //$NON-NLS-1$ //$NON-NLS-2$
att, MessageUtil.getString("Constraint_marker_message_example")
+ " No attributes specified")); //$NON-NLS-1$ //$NON-NLS-2$
}*/
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: ConstraintContentOutlineDragListener.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.editor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.ui.part.PluginTransfer;
import org.eclipse.ui.part.PluginTransferData;
import org.krysalis.version.eclipse.plugin.actions.ConstraintDropActionDelegate;
import org.krysalis.version.eclipse.plugin.util.MarkElement;
/**
* A drag listener for the constraint editor's content outline page.
* Allows dragging of content segments into views that support
* the <code>TextTransfer</code> or <code>PluginTransfer</code> transfer types.
*/
public class ConstraintContentOutlineDragListener extends DragSourceAdapter
{
private ConstraintContentOutlinePage page;
/**
* Creates a new drag listener for the given page.
*/
public ConstraintContentOutlineDragListener(ConstraintContentOutlinePage page)
{
this.page = page;
}
/* (non-Javadoc)
* Method declared on DragSourceListener
*/
public void dragSetData(DragSourceEvent event)
{
if (PluginTransfer.getInstance().isSupportedType(event.dataType))
{
byte[] segmentData = getSegmentText().getBytes();
event.data = new PluginTransferData(ConstraintDropActionDelegate.ID, segmentData);
return;
}
if (TextTransfer.getInstance().isSupportedType(event.dataType))
{
event.data = getSegmentText();
return;
}
}
/**
* Returns the text of the currently selected constraint segment.
*/
private String getSegmentText()
{
StringBuffer result = new StringBuffer();
ISelection selection = page.getSelection();
if (selection instanceof org.eclipse.jface.viewers.IStructuredSelection)
{
Object[] selected = ((IStructuredSelection) selection).toArray();
result.append("\n"); //$NON-NLS-1$
for (int i = 0; i < selected.length; i++)
{
if (selected[i] instanceof MarkElement)
{
result.append(((MarkElement) selected[i]).getLabel(selected[i]));
result.append("\n"); //$NON-NLS-1$
}
}
}
return result.toString();
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: ConstraintMarkerResolutionGenerator.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.editor;
import org.eclipse.core.resources.IMarker;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
/**
* Creates resolutions for constraint markers.
*/
public class ConstraintMarkerResolutionGenerator implements IMarkerResolutionGenerator
{
/*(non-Javadoc)
* Method declared on IMarkerResolutionGenerator.
*/
public IMarkerResolution[] getResolutions(IMarker marker)
{
return new IMarkerResolution[] { new AddSentenceResolution()};
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: AddSentenceResolution.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.editor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
import org.krysalis.version.eclipse.plugin.util.MessageUtil;
/**
* A resolution which inserts a sentence into the Constraint file
*/
public class AddSentenceResolution implements IMarkerResolution {
/* (non-Javadoc)
* Method declared on IMarkerResolution.
*/
public String getLabel() {
return MessageUtil.getString("Add_Sentence"); //$NON-NLS-1$
}
/* (non-Javadoc)
* Method declared on IMarkerResolution.
*/
public void run(IMarker marker) {
// Se if there is an open editor on the file containing the marker
IWorkbenchWindow w = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (w == null)
return;
IWorkbenchPage page = w.getActivePage();
if (page == null)
return;
IFileEditorInput input = new FileEditorInput((IFile)marker.getResource());
IEditorPart editorPart = page.findEditor(input);
if (editorPart == null) {
// open an editor
try {
editorPart = page.openEditor((IFile)marker.getResource());
} catch (PartInitException e) {
MessageDialog.openError(
w.getShell(),
MessageUtil.getString("Resolution_Error"), //$NON-NLS-1$
MessageUtil.getString("Unable_to_open_file_editor")); //$NON-NLS-1$
}
}
if (editorPart == null || !(editorPart instanceof ConstraintEditor))
return;
// insert the sentence
ConstraintEditor editor = (ConstraintEditor)editorPart;
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
String s = MessageUtil.getString("Simple_sentence"); //$NON-NLS-1$
try {
doc.replace(marker.getAttribute(IMarker.CHAR_START, -1), 0, s);
} catch (BadLocationException e) {
// ignore
return;
}
// delete the marker
try {
marker.delete();
} catch (CoreException e) {
e.printStackTrace();
// ignore
}
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: ConstraintContentOutlinePage.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Patchy *
* Software License version 1.1_01, a copy of which has been included *
* at the bottom of this file. *
*****************************************************************************/
package org.krysalis.version.eclipse.plugin.editor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.part.PluginTransfer;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
import org.krysalis.version.eclipse.plugin.model.ConstraintModelFactory;
import org.krysalis.version.eclipse.plugin.util.IConstraintConstants;
import org.krysalis.version.eclipse.plugin.util.MessageUtil;
/**
* Content outline page for the constraint editor.
*/
public class ConstraintContentOutlinePage extends ContentOutlinePage
{
protected IFile input;
class OutlineAction extends Action
{
private Shell shell;
public OutlineAction(String label)
{
super(label);
getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener()
{
public void selectionChanged(SelectionChangedEvent event)
{
setEnabled(!event.getSelection().isEmpty());
}
});
}
public void setShell(Shell shell)
{
this.shell = shell;
}
public void run()
{
MessageDialog.openInformation(shell, MessageUtil.getString("Constraint_Outline"), //$NON-NLS-1$
MessageUtil.getString("ConstraintOutlineActionExecuted")); //$NON-NLS-1$
}
}
/**
* Creates a new ConstraintContentOutlinePage.
*/
public ConstraintContentOutlinePage(IFile input)
{
super();
this.input = input;
}
/**
* Creates the control and registers the popup menu for this page
* Menu id "org.krysalis.version.constraint.outline"
*/
public void createControl(Composite parent)
{
System.out.println("ConstraintContentOutlinePage::createControl");
super.createControl(parent);
WorkbenchHelp.setHelp(getControl(), IConstraintConstants.CONTENT_OUTLINE_PAGE_CONTEXT);
TreeViewer viewer = getTreeViewer();
viewer.setContentProvider(new WorkbenchContentProvider());
viewer.setLabelProvider(new WorkbenchLabelProvider());
viewer.setInput(getContentOutline(input));
initDragAndDrop();
// Configure the context menu.
/*MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
Menu menu = menuMgr.createContextMenu(viewer.getTree());
viewer.getTree().setMenu(menu);
// Be sure to register it so that other plug-ins can add actions.
getSite().registerContextMenu("org.krysalis.version.constraint.outline", menuMgr, viewer); //$NON-NLS-1$
getSite().getActionBars().setGlobalActionHandler(IConstraintConstants.RETARGET2, new OutlineAction(MessageUtil.getString("Outline_Action2"))); //$NON-NLS-1$
OutlineAction action = new OutlineAction(MessageUtil.getString("Outline_Action3")); //$NON-NLS-1$
action.setToolTipText(MessageUtil.getString("Constraint_Outline_Action3")); //$NON-NLS-1$
getSite().getActionBars().setGlobalActionHandler(IConstraintConstants.LABELRETARGET3, action);
action = new OutlineAction(MessageUtil.getString("Outline_Action4")); //$NON-NLS-1$
getSite().getActionBars().setGlobalActionHandler(IConstraintConstants.ACTION_SET_RETARGET4, action);
action = new OutlineAction(MessageUtil.getString("Outline_Action5")); //$NON-NLS-1$
action.setToolTipText(MessageUtil.getString("Constraint_Outline_Action5")); //$NON-NLS-1$
getSite().getActionBars().setGlobalActionHandler(IConstraintConstants.ACTION_SET_LABELRETARGET5, action);*/
}
/**
* Gets the content outline for a given input element.
* Returns the outline (a list of MarkElements), or null
* if the outline could not be generated.
*/
private IAdaptable getContentOutline(IAdaptable input)
{
return ConstraintModelFactory.getInstance().getContentOutline(input);
}
/**
* Initializes drag and drop for this content outline page.
*/
private void initDragAndDrop()
{
int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), PluginTransfer.getInstance()};
getTreeViewer().addDragSupport(ops, transfers, new ConstraintContentOutlineDragListener(this));
}
/**
* Forces the page to update its contents.
*
* @see ConstraintEditor#doSave(IProgressMonitor)
*/
public void update()
{
getControl().setRedraw(false);
getTreeViewer().setInput(getContentOutline(input));
getTreeViewer().expandAll();
getControl().setRedraw(true);
}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003 Nicola Ken Barozzi. All rights reserved.
This Licence is compatible with the BSD licence as described and
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
"This product includes software developed for project
Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.
4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].
5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.
6. This software may contain voluntary contributions made by many
individuals, who decided to donate the code to this project in
respect of this licence.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!
Get cracking and register here for some mind boggling fun and
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en