* Note that each page has its own views; views are never shared between
* pages.
*
*
* @return a list of visible views
*
* @deprecated use #getViewReferences() instead.
*/
virtual std::vector GetViews() = 0;
/**
* Returns the workbench window of this page.
*
* @return the workbench window
*/
virtual IWorkbenchWindow::Pointer GetWorkbenchWindow() = 0;
/**
* Hides the given view. The view must belong to this page.
*
* @param view
* the view to hide
*/
virtual void HideView(IViewPart::Pointer view) = 0;
/**
* Hides the given view that belongs to the reference, if any.
*
* @param view
* the references whos view is to be hidden
* @since 3.0
*/
virtual void HideView(IViewReference::Pointer view) = 0;
/**
* Returns whether the specified part is visible.
*
* @param part
* the part to test
* @return boolean true
if part is visible
*/
virtual bool IsPartVisible(IWorkbenchPart::Pointer part) = 0;
/**
* Reuses the specified editor by setting its new input.
*
* @param editor
* the editor to be reused
* @param input
* the new input for the reusable editor
*/
virtual void ReuseEditor(IReusableEditor::Pointer editor, IEditorInput::Pointer input) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open on the target input that editor
* is activated; otherwise, a new editor is opened. Two editor inputs,
* input1 and input2, are considered the same if
*
*
* input1.equals(input2) == true
*
.
*
*
* The editor type is determined by mapping editorId
to an
* editor extension registered with the workbench. An editor id is passed
* rather than an editor object to prevent the accidental creation of more
* than one editor for the same input. It also guarantees a consistent
* lifecycle for editors, regardless of whether they are created by the user
* or restored from saved data.
*
*
* @param input
* the editor input
* @param editorId
* the id of the editor extension to use
* @return an open and active editor, or null
if an external
* editor was opened
* @exception PartInitException
* if the editor could not be created or initialized
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorId) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open on the target input that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* Object.equals(Object)
* and IEditorInput
. If activate == true
the editor
* will be activated.
*
* The editor type is determined by mapping editorId
to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
*
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if true
the editor will be activated
* @return an open editor, or null
if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input, const std::string& editorId,
bool activate) = 0;
/**
* Opens an editor on the given input.
*
* If this page already has an editor open that matches the given input
* and/or editor id (as specified by the matchFlags argument), that editor
* is brought to the front; otherwise, a new editor is opened. Two editor
* inputs are considered the same if they equal. See
* Object.equals(Object)
* and IEditorInput
. If activate == true
the editor
* will be activated.
*
* The editor type is determined by mapping editorId
to an editor
* extension registered with the workbench. An editor id is passed rather than
* an editor object to prevent the accidental creation of more than one editor
* for the same input. It also guarantees a consistent lifecycle for editors,
* regardless of whether they are created by the user or restored from saved
* data.
*
*
* @param input the editor input
* @param editorId the id of the editor extension to use
* @param activate if true
the editor will be activated
* @param matchFlags a bit mask consisting of zero or more of the MATCH_* constants OR-ed together
* @return an open editor, or null
if an external editor was opened
* @exception PartInitException if the editor could not be created or initialized
*
* @see #MATCH_NONE
* @see #MATCH_INPUT
* @see #MATCH_ID
* @since 3.2
*/
virtual IEditorPart::Pointer OpenEditor(IEditorInput::Pointer input,
const std::string& editorId, bool activate, int matchFlags) = 0;
/**
* Removes the property change listener.
*
* @param listener
* the property change listener to remove
* @since 2.0
*/
//virtual void removePropertyChangeListener(IPropertyChangeListener listener);
/**
* Changes the visible views, their layout, and the visible action sets
* within the page to match the current perspective descriptor. This is a
* rearrangement of components and not a replacement. The contents of the
* current perspective descriptor are unaffected.
*
* For more information on perspective change see
* setPerspective()
.
*
*/
virtual void ResetPerspective() = 0;
/**
* Saves the contents of all dirty editors belonging to this workbench page.
* If there are no dirty editors this method returns without effect.
*
* If confirm
is true
the user is prompted to
* confirm the command.
*
*
* Note that as of 3.2, this method also saves views that implement
* ISaveablePart and are dirty.
*
*
* @param confirm true
to ask the user before saving unsaved
* changes (recommended), and false
to save
* unsaved changes without asking
* @return true
if the command succeeded, and
* false
if the operation was canceled by the user or
* an error occurred while saving
*/
virtual bool SaveAllEditors(bool confirm) = 0;
/**
* Saves the contents of the given editor if dirty. If not, this method
* returns without effect.
*
* If confirm
is true
the user is prompted to
* confirm the command. Otherwise, the save happens without prompt.
*
*
* The editor must belong to this workbench page.
*
*
* @param editor
* the editor to close
* @param confirm
* true
to ask the user before saving unsaved
* changes (recommended), and false
to save
* unsaved changes without asking
* @return true
if the command succeeded, and
* false
if the editor was not saved
*/
virtual bool SaveEditor(IEditorPart::Pointer editor, bool confirm) = 0;
/**
* Saves the visible views, their layout, and the visible action sets for
* this page to the current perspective descriptor. The contents of the
* current perspective descriptor are overwritten.
*/
virtual void SavePerspective() = 0;
/**
* Saves the visible views, their layout, and the visible action sets for
* this page to the given perspective descriptor. The contents of the given
* perspective descriptor are overwritten and it is made the current one for
* this page.
*
* @param perspective
* the perspective descriptor to save to
*/
virtual void SavePerspectiveAs(IPerspectiveDescriptor::Pointer perspective) = 0;
/**
* Changes the visible views, their layout, and the visible action sets
* within the page to match the given perspective descriptor. This is a
* rearrangement of components and not a replacement. The contents of the
* old perspective descriptor are unaffected.
*
* When a perspective change occurs the old perspective is deactivated
* (hidden) and cached for future reference. Then the new perspective is
* activated (shown). The views within the page are shared by all existing
* perspectives to make it easy for the user to switch between one
* perspective and another quickly without loss of context.
*
*
* During activation the action sets are modified. If an action set is
* specified in the new perspective which is not visible in the old one it
* will be created. If an old action set is not specified in the new
* perspective it will be disposed.
*
*
* The visible views and their layout within the page also change. If a view
* is specified in the new perspective which is not visible in the old one a
* new instance of the view will be created. If an old view is not specified
* in the new perspective it will be hidden. This view may reappear if the
* user selects it from the View menu or if they switch to a perspective
* (which may be the old one) where the view is visible.
*
*
* The open editors are not modified by this method.
*
*
* @param perspective
* the perspective descriptor
*/
virtual void SetPerspective(IPerspectiveDescriptor::Pointer perspective) = 0;
/**
* Shows the view identified by the given view id in this page and gives it
* focus. If there is a view identified by the given view id (and with no
* secondary id) already open in this page, it is given focus.
*
* @param viewId
* the id of the view extension to use
* @return the shown view
* @exception PartInitException
* if the view could not be initialized
*/
virtual IViewPart::Pointer ShowView(const std::string& viewId) = 0;
/**
* Shows a view in this page with the given id and secondary id. The
* behaviour of this method varies based on the supplied mode. If
* VIEW_ACTIVATE
is supplied, the view is focus. If
* VIEW_VISIBLE
is supplied, then it is made visible but not
* given focus. Finally, if VIEW_CREATE
is supplied the view
* is created and will only be made visible if it is not created in a folder
* that already contains visible views.
*
* This allows multiple instances of a particular view to be created. They
* are disambiguated using the secondary id. If a secondary id is given, the
* view must allow multiple instances by having specified
* allowMultiple="true" in its extension.
*
*
* @param viewId
* the id of the view extension to use
* @param secondaryId
* the secondary id to use, or null
for no
* secondary id
* @param mode
* the activation mode. Must be {@link #VIEW_ACTIVATE},
* {@link #VIEW_VISIBLE} or {@link #VIEW_CREATE}
* @return a view
* @exception PartInitException
* if the view could not be initialized
* @exception IllegalArgumentException
* if the supplied mode is not valid
* @since 3.0
*/
virtual IViewPart::Pointer ShowView(const std::string& viewId, const std::string& secondaryId, int mode) = 0;
/**
* Returns true
if the editor is pinned and should not be
* reused.
*
* @param editor
* the editor to test
* @return boolean whether the editor is pinned
*/
virtual bool IsEditorPinned(IEditorPart::Pointer editor) = 0;
/**
* Returns the perspective shortcuts associated with the current
* perspective. Returns an empty array if there is no current perspective.
*
* @see IPageLayout#addPerspectiveShortcut(String)
* @return an array of perspective identifiers
* @since 3.1
*/
virtual std::vector GetPerspectiveShortcuts() = 0;
/**
* Returns the show view shortcuts associated with the current perspective.
* Returns an empty array if there is no current perspective.
*
* @see IPageLayout#addShowViewShortcut(String)
* @return an array of view identifiers
* @since 3.1
*/
virtual std::vector GetShowViewShortcuts() = 0;
/**
* Returns the descriptors for the perspectives that are open in this page,
* in the order in which they were opened.
*
* @return the open perspective descriptors, in order of opening
* @since 3.1
*/
virtual std::vector GetOpenPerspectives() = 0;
/**
* Returns the descriptors for the perspectives that are open in this page,
* in the order in which they were activated (oldest first).
*
* @return the open perspective descriptors, in order of activation
* @since 3.1
*/
virtual std::vector GetSortedPerspectives() = 0;
+ /**
+ * Closes current perspective. If last perspective, then entire page
+ * is closed.
+ *
+ * @param saveParts
+ * whether the page's parts should be saved if closed
+ * @param closePage
+ * whether the page itself should be closed if last perspective
+ */
+ virtual void CloseCurrentPerspective(bool saveParts, bool closePage) = 0;
+
/**
* Closes the specified perspective in this page. If the last perspective in
* this page is closed, then all editors are closed. Views that are not
* shown in other perspectives are closed as well. If saveParts
* is true
, the user will be prompted to save any unsaved
* changes for parts that are being closed. The page itself is closed if
* closePage
is true
.
*
* @param desc
* the descriptor of the perspective to be closed
* @param saveParts
* whether the page's parts should be saved if closed
* @param closePage
* whether the page itself should be closed if last perspective
* @since 3.1
*/
virtual void ClosePerspective(IPerspectiveDescriptor::Pointer desc,
bool saveParts, bool closePage) = 0;
/**
* Closes all perspectives in this page. All editors are closed, prompting
* to save any unsaved changes if saveEditors
is
* true
. The page itself is closed if closePage
* is true
.
*
* @param saveEditors
* whether the page's editors should be saved
* @param closePage
* whether the page itself should be closed
* @since 3.1
*/
virtual void CloseAllPerspectives(bool saveEditors, bool closePage) = 0;
/**
* Find the part reference for the given part. A convenience method to
* quickly go from part to part reference.
*
* @param part
* The part to search for. It can be null
.
* @return The reference for the given part, or null
if no
* reference can be found.
* @since 3.2
*/
virtual IWorkbenchPartReference::Pointer GetReference(IWorkbenchPart::Pointer part) = 0;
};
} // namespace berry
#endif /*BERRYIWORKBENCHPAGE_H_*/
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.cpp
index 26372149c8..389115762b 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.cpp
@@ -1,593 +1,606 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryPerspectiveRegistry.h"
#include "berryWorkbench.h"
#include "berryWorkbenchPlugin.h"
#include "berryPerspectiveRegistryReader.h"
#include
namespace berry
{
const std::string PerspectiveRegistry::EXT = "_persp.xml";
const std::string PerspectiveRegistry::ID_DEF_PERSP = "PerspectiveRegistry.DEFAULT_PERSP";
const std::string PerspectiveRegistry::PERSP = "_persp";
const char PerspectiveRegistry::SPACE_DELIMITER = ' ';
PerspectiveRegistry::PerspectiveRegistry()
{
//IExtensionTracker tracker = PlatformUI.getWorkbench() .getExtensionTracker();
//tracker.registerHandler(this, null);
//this->InitializePreferenceChangeListener();
//WorkbenchPlugin::GetDefault()->GetPreferenceStore()->AddPropertyChangeListener(
// preferenceListener);
}
void PerspectiveRegistry::AddPerspective(PerspectiveDescriptor::Pointer desc)
{
if (desc == 0)
{
return;
}
this->Add(desc);
}
-PerspectiveDescriptor::Pointer PerspectiveRegistry::CreatePerspective(const std::string& label,
- PerspectiveDescriptor::Pointer originalDescriptor)
+IPerspectiveDescriptor::Pointer PerspectiveRegistry::CreatePerspective(const std::string& label,
+ IPerspectiveDescriptor::Pointer originalDescriptor)
{
// Sanity check to avoid invalid or duplicate labels.
if (!this->ValidateLabel(label))
{
- return PerspectiveDescriptor::Pointer(0);
+ throw Poco::InvalidArgumentException();
}
if (this->FindPerspectiveWithLabel(label) != 0)
{
- return PerspectiveDescriptor::Pointer(0);
+ throw Poco::InvalidArgumentException();
}
// Calculate ID.
std::string id(label);
std::replace(id.begin(), id.end(), ' ', '_');
Poco::trimInPlace(id);
+
+ if (this->FindPerspectiveWithId(id) != 0)
+ {
+ throw Poco::InvalidArgumentException();
+ }
+
// Create descriptor.
- PerspectiveDescriptor::Pointer desc(
- new PerspectiveDescriptor(id, label, originalDescriptor));
- this->Add(desc);
+ IPerspectiveDescriptor::Pointer desc;
+
+ desc = new PerspectiveDescriptor(id, label, originalDescriptor.Cast());
+
+ this->Add(desc.Cast());
return desc;
}
void PerspectiveRegistry::RevertPerspectives(
const std::list& perspToRevert)
{
// indicate that the user is removing these perspectives
for (std::list::const_iterator iter = perspToRevert.begin();
iter != perspToRevert.end(); ++iter)
{
PerspectiveDescriptor::Pointer desc = *iter;
perspToRemove.push_back(desc->GetId());
desc->RevertToPredefined();
}
}
void PerspectiveRegistry::DeletePerspectives(
const std::list& perspToDelete)
{
for (std::list::const_iterator iter = perspToDelete.begin();
iter != perspToDelete.end(); ++iter)
{
this->DeletePerspective(*iter);
}
}
void PerspectiveRegistry::DeletePerspective(IPerspectiveDescriptor::Pointer in)
{
PerspectiveDescriptor::Pointer desc = in.Cast();
// Don't delete predefined perspectives
if (!desc->IsPredefined())
{
perspToRemove.push_back(desc->GetId());
perspectives.remove(desc);
desc->DeleteCustomDefinition();
this->VerifyDefaultPerspective();
}
}
IPerspectiveDescriptor::Pointer PerspectiveRegistry::FindPerspectiveWithId(const std::string& id)
{
for (std::list::iterator iter = perspectives.begin();
iter != perspectives.end(); ++iter)
{
PerspectiveDescriptor::Pointer desc = *iter;
if (desc->GetId() == id)
{
// if (WorkbenchActivityHelper.restrictUseOf(desc))
// {
// return null;
// }
return desc;
}
}
return IPerspectiveDescriptor::Pointer(0);
}
IPerspectiveDescriptor::Pointer PerspectiveRegistry::FindPerspectiveWithLabel(
const std::string& label)
{
for (std::list::iterator iter = perspectives.begin();
iter != perspectives.end(); ++iter)
{
PerspectiveDescriptor::Pointer desc = *iter;
if (desc->GetLabel() == label)
{
// if (WorkbenchActivityHelper.restrictUseOf(desc))
// {
// return 0;
// }
return desc;
}
}
return IPerspectiveDescriptor::Pointer(0);
}
std::string PerspectiveRegistry::GetDefaultPerspective()
{
return defaultPerspID;
}
std::vector PerspectiveRegistry::GetPerspectives()
{
// Collection descs = WorkbenchActivityHelper.restrictCollection(perspectives,
// new ArrayList());
// return (IPerspectiveDescriptor[]) descs.toArray(
// new IPerspectiveDescriptor[descs.size()]);
std::vector result;
for (std::list::iterator iter = perspectives.begin();
iter != perspectives.end(); ++iter)
{
result.push_back(iter->Cast());
}
return result;
}
void PerspectiveRegistry::Load()
{
// Load the registries.
this->LoadPredefined();
this->LoadCustom();
// Get default perspective.
// Get it from the R1.0 dialog settings first. Fixes bug 17039
// IDialogSettings dialogSettings =
// WorkbenchPlugin.getDefault() .getDialogSettings();
// std::string str = dialogSettings.get(ID_DEF_PERSP);
// if (str != null && str.length() > 0)
// {
// this->SetDefaultPerspective(str);
// dialogSettings.put(ID_DEF_PERSP, ""); //$NON-NLS-1$
// }
this->VerifyDefaultPerspective();
}
//void PerspectiveRegistry::SaveCustomPersp(PerspectiveDescriptor::Pointer desc,
// XMLMemento::Pointer memento)
//{
//
// IPreferenceStore store = WorkbenchPlugin.getDefault() .getPreferenceStore();
//
// // Save it to the preference store.
// Writer writer = new StringWriter();
//
// memento.save(writer);
// writer.close();
// store.setValue(desc.getId() + PERSP, writer.toString());
//
//}
IMemento::Pointer PerspectiveRegistry::GetCustomPersp(const std::string& /*id*/)
{
//TODO CustomPersp
// Reader reader = null;
//
// IPreferenceStore store = WorkbenchPlugin.getDefault() .getPreferenceStore();
// std::string xmlString = store.getString(id + PERSP);
// if (xmlString != null && xmlString.length() != 0)
// { // defined in store
// reader = new StringReader(xmlString);
// }
// XMLMemento memento = XMLMemento.createReadRoot(reader);
// reader.close();
// return memento;
return IMemento::Pointer(0);
}
void PerspectiveRegistry::SetDefaultPerspective(const std::string& id)
{
IPerspectiveDescriptor::Pointer desc = this->FindPerspectiveWithId(id);
if (desc != 0)
{
defaultPerspID = id;
//TODO Preferences
// PrefUtil.getAPIPreferenceStore().setValue(
// IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID, id);
}
}
bool PerspectiveRegistry::ValidateLabel(const std::string& label)
{
return !Poco::trim(label).empty();
}
IPerspectiveDescriptor::Pointer PerspectiveRegistry::ClonePerspective(const std::string& id,
const std::string& label,
IPerspectiveDescriptor::Pointer originalDescriptor)
{
// Check for invalid labels
if (label == "" || Poco::trim(label).empty())
{
throw Poco::InvalidArgumentException();
}
// Check for duplicates
IPerspectiveDescriptor::Pointer desc = this->FindPerspectiveWithId(id);
if (desc != 0)
{
throw Poco::InvalidArgumentException();
}
+ if (this->FindPerspectiveWithLabel(label) != 0)
+ {
+ throw Poco::InvalidArgumentException();
+ }
+
// Create descriptor.
desc
= new PerspectiveDescriptor(id, label, originalDescriptor.Cast());
this->Add(desc.Cast());
return desc;
}
void PerspectiveRegistry::RevertPerspective(IPerspectiveDescriptor::Pointer perspToRevert)
{
PerspectiveDescriptor::Pointer desc = perspToRevert.Cast();
perspToRemove.push_back(desc->GetId());
desc->RevertToPredefined();
}
PerspectiveRegistry::~PerspectiveRegistry()
{
// PlatformUI.getWorkbench().getExtensionTracker().unregisterHandler(this);
// WorkbenchPlugin.getDefault().getPreferenceStore() .removePropertyChangeListener(
// preferenceListener);
}
void PerspectiveRegistry::DeleteCustomDefinition(PerspectiveDescriptor::Pointer /*desc*/)
{
//TODO Preferences
// remove the entry from the preference store.
//IPreferenceStore store = WorkbenchPlugin.getDefault() .getPreferenceStore();
/*
* To delete the perspective definition from the preference store, use
* the setToDefault method. Since no default is defined, this will
* remove the entry
*/
//store.setToDefault(desc.getId() + PERSP);
}
bool PerspectiveRegistry::HasCustomDefinition(PerspectiveDescriptor::ConstPointer /*desc*/) const
{
//TODO Preferences
//IPreferenceStore store = WorkbenchPlugin::GetDefault()->GetPreferenceStore();
//return store.contains(desc.getId() + PERSP);
return false;
}
void PerspectiveRegistry::InitializePreferenceChangeListener()
{
// preferenceListener = new IPropertyChangeListener()
// {
// public void propertyChange(PropertyChangeEvent event)
// {
// /*
// * To ensure the that no custom perspective definitions are
// * deleted when preferences are imported, merge old and new
// * values
// */
// if (event.getProperty().endsWith(PERSP))
// {
// /* A Perspective is being changed, merge */
// mergePerspectives(event);
// }
// else if (event.getProperty().equals(
// IPreferenceConstants.PERSPECTIVES))
// {
// /* The list of perpsectives is being changed, merge */
// updatePreferenceList((IPreferenceStore) event.getSource());
// }
// }
//
// void MergePerspectives(PropertyChangeEvent::Pointer event)
// {
// IPreferenceStore store = (IPreferenceStore) event.getSource();
// if (event.getNewValue() == null
// || event.getNewValue().equals(""))
// { //$NON-NLS-1$
// /*
// * Perpsective is being removed; if the user has deleted or
// * reverted a custom perspective, let the change pass
// * through. Otherwise, restore the custom perspective entry
// */
//
// // Find the matching descriptor in the registry
// IPerspectiveDescriptor[] perspectiveList = getPerspectives();
// for (int i = 0; i < perspectiveList.length; i++)
// {
// std::string id = perspectiveList[i].getId();
// if (event.getProperty().equals(id + PERSP))
// { // found
// // descriptor
// // see if the perspective has been flagged for
// // reverting or deleting
// if (!perspToRemove.contains(id))
// { // restore
// store.setValue(id + PERSP, (std::string) event
// .getOldValue());
// }
// else
// { // remove element from the list
// perspToRemove.remove(id);
// }
// }
// }
// }
// else if ((event.getOldValue() == null || event.getOldValue()
// .equals("")))
// { //$NON-NLS-1$
//
// /*
// * New perspective is being added, update the
// * perspectiveRegistry to contain the new custom perspective
// */
//
// std::string id = event.getProperty().substring(0,
// event.getProperty().lastIndexOf(PERSP));
// if (findPerspectiveWithId(id) == null)
// {
// // perspective does not already exist in registry, add
// // it
// PerspectiveDescriptor desc = new PerspectiveDescriptor(
// null, null, null);
// StringReader reader = new StringReader((std::string) event
// .getNewValue());
// try
// {
// XMLMemento memento = XMLMemento
// .createReadRoot(reader);
// desc.restoreState(memento);
// addPerspective(desc);
// }
// catch (WorkbenchException e)
// {
// unableToLoadPerspective(e.getStatus());
// }
// }
// }
// /* If necessary, add to the list of perspectives */
// updatePreferenceList(store);
// }
//
// void UpdatePreferenceList(IPreferenceStore store)
// {
// IPerspectiveDescriptor[] perspectiveList = getPerspectives();
// StringBuffer perspBuffer = new StringBuffer();
// for (int i = 0; i < perspectiveList.length; i++)
// {
// PerspectiveDescriptor desc = (PerspectiveDescriptor) perspectiveList[i];
// if (hasCustomDefinition(desc))
// {
// perspBuffer.append(desc.getId())
// .append(SPACE_DELIMITER);
// }
// }
// std::string newList = perspBuffer.toString().trim();
// store.setValue(IPreferenceConstants.PERSPECTIVES, newList);
// }
// };
}
void PerspectiveRegistry::Add(PerspectiveDescriptor::Pointer desc)
{
perspectives.push_back(desc);
// IConfigurationElement::Pointer element = desc->GetConfigElement();
// if (element != 0)
// {
// PlatformUI::GetWorkbench().getExtensionTracker().registerObject(
// element.getDeclaringExtension(), desc, IExtensionTracker.REF_WEAK);
// }
}
void PerspectiveRegistry::InternalDeletePerspective(PerspectiveDescriptor::Pointer desc)
{
perspToRemove.push_back(desc->GetId());
perspectives.remove(desc);
desc->DeleteCustomDefinition();
this->VerifyDefaultPerspective();
}
void PerspectiveRegistry::LoadCustom()
{
// Reader reader = null;
//
// /* Get the entries from the Preference store */
// IPreferenceStore store = WorkbenchPlugin.getDefault() .getPreferenceStore();
//
// /* Get the space-delimited list of custom perspective ids */
// std::string customPerspectives = store .getString(
// IPreferenceConstants.PERSPECTIVES);
// std::string[] perspectivesList = StringConverter.asArray(customPerspectives);
//
// for (int i = 0; i < perspectivesList.length; i++)
// {
// try
// {
// std::string xmlString = store.getString(perspectivesList[i] + PERSP);
// if (xmlString != null && xmlString.length() != 0)
// {
// reader = new StringReader(xmlString);
// }
//
// // Restore the layout state.
// XMLMemento memento = XMLMemento.createReadRoot(reader);
// PerspectiveDescriptor newPersp =
// new PerspectiveDescriptor(null, null, null);
// newPersp.restoreState(memento);
// std::string id = newPersp.getId();
// IPerspectiveDescriptor oldPersp = findPerspectiveWithId(id);
// if (oldPersp == null)
// {
// add(newPersp);
// }
// reader.close();
// } catch (IOException e)
// {
// unableToLoadPerspective(null);
// } catch (WorkbenchException e)
// {
// unableToLoadPerspective(e.getStatus());
// }
// }
//
// // Get the entries from files, if any
// // if -data @noDefault specified the state location may not be
// // initialized
// IPath path = WorkbenchPlugin.getDefault().getDataLocation();
// if (path == null)
// {
// return;
// }
//
// File folder = path.toFile();
//
// if (folder.isDirectory())
// {
// File[] fileList = folder.listFiles();
// int nSize = fileList.length;
// for (int nX = 0; nX < nSize; nX++)
// {
// File file = fileList[nX];
// if (file.getName().endsWith(EXT))
// {
// // get the memento
// InputStream stream = null;
// try
// {
// stream = new FileInputStream(file);
// reader = new BufferedReader(new InputStreamReader(stream, "utf-8")); //$NON-NLS-1$
//
// // Restore the layout state.
// XMLMemento memento = XMLMemento.createReadRoot(reader);
// PerspectiveDescriptor newPersp =
// new PerspectiveDescriptor(null, null, null);
// newPersp.restoreState(memento);
// IPerspectiveDescriptor oldPersp = findPerspectiveWithId(
// newPersp .getId());
// if (oldPersp == null)
// {
// add(newPersp);
// }
//
// // save to the preference store
// saveCustomPersp(newPersp, memento);
//
// // delete the file
// file.delete();
//
// reader.close();
// stream.close();
// } catch (IOException e)
// {
// unableToLoadPerspective(null);
// } catch (WorkbenchException e)
// {
// unableToLoadPerspective(e.getStatus());
// }
// }
// }
// }
}
void PerspectiveRegistry::UnableToLoadPerspective(const std::string& status)
{
std::string msg = "Unable to load perspective";
if (status == "")
{
WorkbenchPlugin::Log(msg);
//IStatus errStatus =
// new Status(IStatus.ERR, WorkbenchPlugin.PI_WORKBENCH, msg);
//StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
}
else
{
WorkbenchPlugin::Log(status + ": " + msg);
//IStatus errStatus = StatusUtil.newStatus(status, msg);
//StatusManager.getManager().handle(errStatus, StatusManager.SHOW);
}
}
void PerspectiveRegistry::LoadPredefined()
{
PerspectiveRegistryReader reader;
reader.ReadPerspectives(this);
}
void PerspectiveRegistry::VerifyDefaultPerspective()
{
// Step 1: Try current defPerspId value.
IPerspectiveDescriptor::Pointer desc;
if (defaultPerspID != "")
{
desc = this->FindPerspectiveWithId(defaultPerspID);
}
if (desc != 0)
{
return;
}
// Step 2. Read default value.
//TODO Preferences
// std::string str = PrefUtil.getAPIPreferenceStore().getString(
// IWorkbenchPreferenceConstants.DEFAULT_PERSPECTIVE_ID);
// if (str != null && str.length() > 0)
// {
// desc = this->FindPerspectiveWithId(str);
// }
// if (desc != 0)
// {
// defaultPerspID = str;
// return;
// }
// Step 3. Use application-specific default
defaultPerspID = Workbench::GetInstance()->GetDefaultPerspectiveId();
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.h
index a0f9d300f5..9560648a16 100755
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.h
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryPerspectiveRegistry.h
@@ -1,309 +1,309 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYPERSPECTIVEREGISTRY_H_
#define BERRYPERSPECTIVEREGISTRY_H_
#include "berryIPerspectiveRegistry.h"
#include "berryPerspectiveDescriptor.h"
#include
namespace berry {
/**
* Perspective registry.
*/
class PerspectiveRegistry : public IPerspectiveRegistry {
// IExtensionChangeHandler {
friend class PerspectiveDescriptor;
private:
std::string defaultPerspID;
static const std::string EXT; // = "_persp.xml";
static const std::string ID_DEF_PERSP; // = "PerspectiveRegistry.DEFAULT_PERSP";
static const std::string PERSP; // = "_persp";
static const char SPACE_DELIMITER; // = ' ';
std::list perspectives;
// keep track of the perspectives the user has selected to remove or revert
std::list perspToRemove;
//IPropertyChangeListener::Pointer preferenceListener;
public:
/**
* Construct a new registry.
*/
PerspectiveRegistry();
/**
* Adds a perspective. This is typically used by the reader.
*
* @param desc
*/
void AddPerspective(PerspectiveDescriptor::Pointer desc);
/**
* Create a new perspective.
*
* @param label
* the name of the new descriptor
* @param originalDescriptor
* the descriptor on which to base the new descriptor
* @return a new perspective descriptor or null
if the
* creation failed.
*/
- PerspectiveDescriptor::Pointer CreatePerspective(const std::string& label,
- PerspectiveDescriptor::Pointer originalDescriptor);
+ IPerspectiveDescriptor::Pointer CreatePerspective(const std::string& label,
+ IPerspectiveDescriptor::Pointer originalDescriptor);
/**
* Reverts a list of perspectives back to the plugin definition
*
* @param perspToRevert
*/
void RevertPerspectives(const std::list& perspToRevert);
/**
* Deletes a list of perspectives
*
* @param perspToDelete
*/
void DeletePerspectives(const std::list& perspToDelete);
/**
* Delete a perspective. Has no effect if the perspective is defined in an
* extension.
*
* @param in
*/
void DeletePerspective(IPerspectiveDescriptor::Pointer in);
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IPerspectiveRegistry#findPerspectiveWithId(java.lang.std::string)
*/
IPerspectiveDescriptor::Pointer FindPerspectiveWithId(const std::string& id);
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IPerspectiveRegistry#findPerspectiveWithLabel(java.lang.std::string)
*/
IPerspectiveDescriptor::Pointer FindPerspectiveWithLabel(const std::string& label);
/**
* @see IPerspectiveRegistry#getDefaultPerspective()
*/
std::string GetDefaultPerspective();
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IPerspectiveRegistry#getPerspectives()
*/
std::vector GetPerspectives();
/**
* Loads the registry.
*/
void Load();
/**
* Saves a custom perspective definition to the preference store.
*
* @param desc
* the perspective
* @param memento
* the memento to save to
* @throws IOException
*/
// void SaveCustomPersp(PerspectiveDescriptor::Pointer desc, XMLMemento::Pointer memento);
/**
* Gets the Custom perspective definition from the preference store.
*
* @param id
* the id of the perspective to find
* @return IMemento a memento containing the perspective description
*
* @throws WorkbenchException
* @throws IOException
*/
IMemento::Pointer GetCustomPersp(const std::string& id);
/**
* @see IPerspectiveRegistry#setDefaultPerspective(std::string)
*/
void SetDefaultPerspective(const std::string& id);
/**
* Return true
if a label is valid. This checks only the
* given label in isolation. It does not check whether the given label is
* used by any existing perspectives.
*
* @param label
* the label to test
* @return whether the label is valid
*/
bool ValidateLabel(const std::string& label);
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IPerspectiveRegistry#clonePerspective(java.lang.std::string,
* java.lang.std::string, org.blueberry.ui.IPerspectiveDescriptor)
*/
IPerspectiveDescriptor::Pointer ClonePerspective(const std::string& id, const std::string& label,
IPerspectiveDescriptor::Pointer originalDescriptor);
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IPerspectiveRegistry#revertPerspective(org.blueberry.ui.IPerspectiveDescriptor)
*/
void RevertPerspective(IPerspectiveDescriptor::Pointer perspToRevert);
/**
* Dispose the receiver.
*/
~PerspectiveRegistry();
/*
* (non-Javadoc)
*
* @see org.blueberry.core.runtime.dynamicHelpers.IExtensionChangeHandler#removeExtension(org.blueberry.core.runtime.IExtension,
* java.lang.Object[])
*/
// void removeExtension(IExtension source, Object[] objects) {
// for (int i = 0; i < objects.length; i++) {
// if (objects[i] instanceof PerspectiveDescriptor) {
// // close the perspective in all windows
// IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
// .getWorkbenchWindows();
// PerspectiveDescriptor desc = (PerspectiveDescriptor) objects[i];
// for (int w = 0; w < windows.length; ++w) {
// IWorkbenchWindow window = windows[w];
// IWorkbenchPage[] pages = window.getPages();
// for (int p = 0; p < pages.length; ++p) {
// WorkbenchPage page = (WorkbenchPage) pages[p];
// ClosePerspectiveHandler.closePerspective(page, page
// .findPerspective(desc));
// }
// }
//
// // ((Workbench)PlatformUI.getWorkbench()).getPerspectiveHistory().removeItem(desc);
//
// internalDeletePerspective(desc);
// }
//
// }
// }
/*
* (non-Javadoc)
*
* @see org.blueberry.core.runtime.dynamicHelpers.IExtensionChangeHandler#addExtension(org.blueberry.core.runtime.dynamicHelpers.IExtensionTracker,
* org.blueberry.core.runtime.IExtension)
*/
// void addExtension(IExtensionTracker tracker,
// IExtension addedExtension) {
// IConfigurationElement[] addedElements = addedExtension
// .getConfigurationElements();
// for (int i = 0; i < addedElements.length; i++) {
// PerspectiveRegistryReader reader = new PerspectiveRegistryReader(
// this);
// reader.readElement(addedElements[i]);
// }
// }
protected:
/**
* Removes the custom definition of a perspective from the preference store
*
* @param desc
*/
/* package */
void DeleteCustomDefinition(PerspectiveDescriptor::Pointer desc);
/**
* Method hasCustomDefinition.
*
* @param desc
*/
/* package */
bool HasCustomDefinition(PerspectiveDescriptor::ConstPointer desc) const;
private:
/**
* Initialize the preference change listener.
*/
void InitializePreferenceChangeListener();
/**
* @param desc
*/
void Add(PerspectiveDescriptor::Pointer desc);
/**
* Delete a perspective. This will remove perspectives defined in
* extensions.
*
* @param desc
* the perspective to delete
* @since 3.1
*/
void InternalDeletePerspective(PerspectiveDescriptor::Pointer desc);
/**
* Read children from the file system.
*/
void LoadCustom();
/**
* @param status
*/
void UnableToLoadPerspective(const std::string& status);
/**
* Read children from the plugin registry.
*/
void LoadPredefined();
/**
* Verifies the id of the default perspective. If the default perspective is
* invalid use the workbench default.
*/
void VerifyDefaultPerspective();
};
}
#endif /* BERRYPERSPECTIVEREGISTRY_H_ */
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewReference.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewReference.cpp
index 3dcaa8fde8..976393c818 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewReference.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryViewReference.cpp
@@ -1,438 +1,441 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryViewReference.h"
#include
#include "berryUIException.h"
#include "tweaklets/berryWorkbenchPageTweaklet.h"
#include "berryPlatformUI.h"
#include "berryImageDescriptor.h"
#include "berryWorkbenchPage.h"
#include "berryWorkbenchConstants.h"
#include "berryViewDescriptor.h"
#include "berryViewFactory.h"
#include "berryViewRegistry.h"
#include "berryViewSite.h"
#include "berryPartTester.h"
#include "berryWorkbenchPlugin.h"
#include "berryErrorViewPart.h"
namespace berry
{
ViewReference::ViewReference(ViewFactory* fac, const std::string& id,
const std::string& secId, IMemento::Pointer m) :
factory(fac), secondaryId(secId), memento(m)
{
ViewDescriptor::Pointer desc =
this->factory->GetViewRegistry()->Find(id).Cast ();
ImageDescriptor::Pointer iDesc;
std::string title;
if (!desc.IsNull())
{
iDesc = desc->GetImageDescriptor();
title = desc->GetLabel();
}
std::string name;
if (!memento.IsNull())
{
// name = memento.getString(IWorkbenchConstants.TAG_PART_NAME);
// IMemento propBag = memento.getChild(IWorkbenchConstants.TAG_PROPERTIES);
// if (propBag != null) {
// IMemento[] props = propBag
// .getChildren(IWorkbenchConstants.TAG_PROPERTY);
// for (int i = 0; i < props.length; i++) {
// propertyCache.put(props[i].getID(), props[i].getTextData());
// }
// }
}
if (name.empty())
{
name = title;
}
this->Init(id, "", iDesc, name, ""); //$NON-NLS-1$//$NON-NLS-2$
}
void ViewReference::DoDisposePart()
{
IViewPart::Pointer view = part.Cast ();
//WorkbenchPartReference::DoDisposePart();
if (!view.IsNull())
{
// Free action bars, pane, etc.
//PartSite site = (PartSite) view.getSite();
//ViewActionBars actionBars = (ViewActionBars) site.getActionBars();
//
// 3.3 start
//
//IMenuService menuService = (IMenuService) site
// .getService(IMenuService.class);
//menuService.releaseContributions((ContributionManager) site.getActionBars()
// .getMenuManager());
//menuService.releaseContributions((ContributionManager) site.getActionBars()
// .getToolBarManager());
// 3.3 end
//actionBars.dispose();
// and now dispose the delegates since the
// PluginActionContributionItem
// can no longer do that
// if (actionBuilder != null) {
// actionBuilder.dispose();
// actionBuilder = null;
// }
// Free the site.
//site.dispose();
}
}
IWorkbenchPage::Pointer ViewReference::GetPage() const
{
return IWorkbenchPage::Pointer(this->factory->GetWorkbenchPage());
}
std::string ViewReference::GetRegisteredName()
{
if (!part.IsNull() && !part->GetSite().IsNull())
{
return part->GetSite()->GetRegisteredName();
}
const IViewRegistry* reg = this->factory->GetViewRegistry();
IViewDescriptor::Pointer desc = reg->Find(this->GetId());
if (!desc.IsNull())
{
return desc->GetLabel();
}
return this->GetPartName();
}
std::string ViewReference::GetSecondaryId()
{
return secondaryId;
}
IViewPart::Pointer ViewReference::GetView(bool restore)
{
return this->GetPart(restore).Cast ();
}
IWorkbenchPart::Pointer ViewReference::CreatePart()
{
// Check the status of this part
IWorkbenchPart::Pointer result;
PartInitException exception;
bool error = false;
// Try to restore the view -- this does the real work of restoring the
// view
//
try
{
result = this->CreatePartHelper();
} catch (PartInitException e)
{
exception = e;
error = true;
}
// If unable to create the part, create an error part instead
// and pass the error to the status handling facility
if (error)
{
// IStatus partStatus = exception.getStatus();
// IStatus displayStatus = StatusUtil.newStatus(partStatus,
// NLS.bind(WorkbenchMessages.ViewFactory_initException, partStatus.getMessage()));
// IStatus logStatus = StatusUtil
// .newStatus(
// partStatus,
// NLS
// .bind(
// "Unable to create view ID {0}: {1}", getId(), partStatus.getMessage())); //$NON-NLS-1$
// Pass the error to the status handling facility
// StatusManager.getManager().handle(logStatus);
std::string errorTitle = "Unable to create view ID " + this->GetId();
WorkbenchPlugin::Log(errorTitle + ": " + exception.displayText());
IViewDescriptor::Pointer desc = factory->GetViewRegistry()->Find(
this->GetId());
std::string label = this->GetId();
if (!desc.IsNull())
{
label = desc->GetLabel();
}
std::string errorMsg = exception.displayText();
errorMsg
+= "- Check your shared library for unresolved symbols
"
"- Check your class attribute in your plugin.xml file
"
"- Check your manifest.cpp file
"
"For a comprehensive check-list, see http://www.mitk.org/wiki/How_to_fix_your_plug-in_DLL";
ErrorViewPart::Pointer part(new ErrorViewPart(errorTitle, errorMsg));
//PartPane pane = getPane();
IViewReference::Pointer viewRef(this);
ViewSite::Pointer site(new ViewSite(viewRef, part,
factory->GetWorkbenchPage(), GetId(), PlatformUI::PLUGIN_ID, label));
//site.setActionBars(new ViewActionBars(factory.page.getActionBars(),
// site, (ViewPane) pane));
try
{
part->Init(site);
} catch (PartInitException e)
{
BERRY_ERROR << e.displayText();
//StatusUtil.handleStatus(e, StatusManager.SHOW
// | StatusManager.LOG);
return IWorkbenchPart::Pointer(0);
}
part->SetPartName(label);
void* parent = pane->GetControl();
try
{
part->CreatePartControl(parent);
} catch (std::exception e)
{
BERRY_ERROR << "Error creating view: " << e.what() << std::endl;
// StatusUtil.handleStatus(e, StatusManager.SHOW
// | StatusManager.LOG);
return IWorkbenchPart::Pointer(0);
}
result = part.Cast ();
}
return result;
}
PartPane::Pointer ViewReference::CreatePane()
{
IWorkbenchPartReference::Pointer partRef(this);
PartPane::Pointer pane(new PartPane(partRef,
this->factory->GetWorkbenchPage()));
return pane;
//return Tweaklets::Get(WorkbenchTweaklet::KEY)->CreateViewPane(this, this->factory->GetWorkbenchPage());
}
IWorkbenchPart::Pointer ViewReference::CreatePartHelper()
{
IWorkbenchPart::Pointer result;
IMemento::Pointer stateMem;
if (!memento.IsNull())
{
stateMem = memento->GetChild(WorkbenchConstants::TAG_VIEW_STATE);
}
IViewDescriptor::Pointer desc = factory->GetViewRegistry()->Find(GetId());
if (desc.IsNull())
{
throw PartInitException("Could not create view", this->GetId());
}
// Create the part pane
PartPane::Pointer pane = this->GetPane();
// Create the pane's top-level control
pane->CreateControl(factory->GetWorkbenchPage()->GetClientComposite());
std::string label = desc->GetLabel(); // debugging only
// Things that will need to be disposed if an exception occurs (they are
// listed here
// in the order they should be disposed)
//Composite content = null;
IViewPart::Pointer initializedView;
ViewSite::Pointer site;
//ViewActionBars actionBars = null;
// End of things that need to be explicitly disposed from the try block
try
{
IViewPart::Pointer view;
view = desc->CreateView();
+ if (view.IsNull())
+ return result;
+
this->CreatePartProperties(view);
// Create site
IViewReference::Pointer viewRef(this);
site = new ViewSite(viewRef, view, factory->GetWorkbenchPage(), desc);
//actionBars = new ViewActionBars(factory.page.getActionBars(), site,
// (ViewPane) pane);
//site.setActionBars(actionBars);
view->Init(site, stateMem);
// Once we've called init, we MUST dispose the view. Remember
// the fact that
// we've initialized the view in case an exception is thrown.
initializedView = view;
if (view->GetSite() != site)
{
throw PartInitException("View initialization failed. Site is incorrect.");
}
// Create the top-level composite
{
void* parent = pane->GetControl();
view->CreatePartControl(parent);
}
// Install the part's tools and menu
{
//
// 3.3 start
//
// IMenuService menuService = (IMenuService) site
// .getService(IMenuService.class);
// menuService.populateContributionManager(
// (ContributionManager) site.getActionBars()
// .getMenuManager(), "menu:" //$NON-NLS-1$
// + site.getId());
// menuService
// .populateContributionManager((ContributionManager) site
// .getActionBars().getToolBarManager(),
// "toolbar:" + site.getId()); //$NON-NLS-1$
// 3.3 end
// actionBuilder = new ViewActionBuilder();
// actionBuilder.readActionExtensions(view);
// ActionDescriptor[] actionDescriptors = actionBuilder
// .getExtendedActions();
// IKeyBindingService keyBindingService = view.getSite()
// .getKeyBindingService();
//
// if (actionDescriptors != null) {
// for (int i = 0; i < actionDescriptors.length; i++) {
// ActionDescriptor actionDescriptor = actionDescriptors[i];
//
// if (actionDescriptor != null) {
// IAction action = actionDescriptors[i].getAction();
//
// if (action != null
// && action.getActionDefinitionId() != null) {
// keyBindingService.registerAction(action);
// }
// }
// }
// }
//
// site.getActionBars().updateActionBars();
}
// The part should now be fully created. Exercise its public
// interface, and sanity-check
// it wherever possible. If it's going to throw exceptions or behave
// badly, it's much better
// that it does so now while we can still cancel creation of the
// part.
PartTester::TestView(view);
result = view.Cast ();
// IConfigurationElement::Pointer element = desc->GetConfigurationElement();
// if (!element.IsNull()) {
// factory.page.getExtensionTracker().registerObject(
// element.getDeclaringExtension(), view,
// IExtensionTracker.REF_WEAK);
// }
} catch (const Poco::Exception& e)
{
// if ((e instanceof Error) && !(e instanceof LinkageError)) {
// throw (Error) e;
// }
// An exception occurred. First deallocate anything we've allocated
// in the try block (see the top
// of the try block for a list of objects that need to be explicitly
// disposed)
// if (content != null) {
// try {
// content.dispose();
// } catch (RuntimeException re) {
// StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
// re));
// }
// }
//
// if (initializedView != null) {
// try {
// initializedView.dispose();
// } catch (RuntimeException re) {
// StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
// re));
// }
// }
//
// if (site != null) {
// try {
// site.dispose();
// } catch (RuntimeException re) {
// StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
// re));
// }
// }
//
// if (actionBars != null) {
// try {
// actionBars.dispose();
// } catch (RuntimeException re) {
// StatusManager.getManager().handle(
// StatusUtil.newStatus(WorkbenchPlugin.PI_WORKBENCH,
// re));
// }
// }
throw PartInitException(e.message(), e, e.code());
}
catch (const std::exception& e)
{
throw PartInitException(e.what());
}
return result;
}
IMemento::Pointer ViewReference::GetMemento()
{
return memento;
}
} // namespace berry
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp
index dc7eca49d6..d711cce9d6 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.cpp
@@ -1,4111 +1,4120 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#include "berryLog.h"
#include "tweaklets/berryGuiWidgetsTweaklet.h"
#include "tweaklets/berryWorkbenchPageTweaklet.h"
#include "berryWorkbenchPage.h"
#include "berryPartSite.h"
#include "berryWorkbenchRegistryConstants.h"
#include "berryPerspective.h"
#include "berryLayoutPartSash.h"
#include "berryWorkbenchPlugin.h"
#include "berryEditorAreaHelper.h"
#include "berrySaveablesList.h"
#include "berryPerspectiveHelper.h"
#include "berryLayoutTreeNode.h"
#include "berryWorkbench.h"
#include "berryWorkbenchConstants.h"
#include "berryPartService.h"
#include "berryStickyViewManager.h"
#include "intro/berryIntroConstants.h"
#include "intro/berryViewIntroAdapterPart.h"
#include "dialogs/berryMessageDialog.h"
#include "berryWorkbenchWindow.h"
#include "berryUIException.h"
#include "berryPlatformUI.h"
#include "berryPartPane.h"
#include "berryImageDescriptor.h"
#include
#include
namespace berry
{
WorkbenchPage::ActivationOrderPred::ActivationOrderPred(
WorkbenchPage::ActivationList* al) :
activationList(al)
{
}
bool WorkbenchPage::ActivationOrderPred::operator()(
const IViewReference::Pointer o1, const IViewReference::Pointer o2) const
{
WorkbenchPage::ActivationList::PartListIter pos1 = activationList->IndexOf(
o1.Cast ());
WorkbenchPage::ActivationList::PartListIter pos2 = activationList->IndexOf(
o2.Cast ());
return pos1 < pos2;
}
void WorkbenchPage::PerspectiveList::UpdateActionSets(
Perspective::Pointer /*oldPersp*/, Perspective::Pointer /*newPersp*/)
{
//TODO WorkbenchPage action sets
// // Update action sets
//
// IContextService service = (IContextService) window
// .getService(IContextService.class);
// try {
// service.activateContext(ContextAuthority.DEFER_EVENTS);
// if (newPersp != 0) {
// IActionSetDescriptor[] newAlwaysOn = newPersp
// .getAlwaysOnActionSets();
// for (int i = 0; i < newAlwaysOn.length; i++) {
// IActionSetDescriptor descriptor = newAlwaysOn[i];
//
// actionSets.showAction(descriptor);
// }
//
// IActionSetDescriptor[] newAlwaysOff = newPersp
// .getAlwaysOffActionSets();
// for (int i = 0; i < newAlwaysOff.length; i++) {
// IActionSetDescriptor descriptor = newAlwaysOff[i];
//
// actionSets.maskAction(descriptor);
// }
// }
//
// if (oldPersp != 0) {
// IActionSetDescriptor[] newAlwaysOn = oldPersp
// .getAlwaysOnActionSets();
// for (int i = 0; i < newAlwaysOn.length; i++) {
// IActionSetDescriptor descriptor = newAlwaysOn[i];
//
// actionSets.hideAction(descriptor);
// }
//
// IActionSetDescriptor[] newAlwaysOff = oldPersp
// .getAlwaysOffActionSets();
// for (int i = 0; i < newAlwaysOff.length; i++) {
// IActionSetDescriptor descriptor = newAlwaysOff[i];
//
// actionSets.unmaskAction(descriptor);
// }
// }
// } finally {
// service.activateContext(ContextAuthority.SEND_EVENTS);
// }
}
WorkbenchPage::PerspectiveList::PerspectiveList()
{
}
void WorkbenchPage::PerspectiveList::Reorder(
IPerspectiveDescriptor::Pointer perspective, int newLoc)
{
PerspectiveListType::iterator oldLocation = openedList.end();
Perspective::Pointer movedPerspective;
for (PerspectiveListType::iterator iterator = openedList.begin(); iterator
!= openedList.end(); ++iterator)
{
Perspective::Pointer openPerspective = *iterator;
if (openPerspective->GetDesc() == perspective)
{
oldLocation = std::find(openedList.begin(), openedList.end(),
openPerspective);
movedPerspective = openPerspective;
}
}
PerspectiveListType::iterator newLocation = openedList.begin();
for (int i = 0; i < newLoc; ++i, ++newLocation)
;
if (oldLocation == newLocation)
{
return;
}
openedList.erase(oldLocation);
openedList.insert(newLocation, movedPerspective);
}
WorkbenchPage::PerspectiveList::PerspectiveListType WorkbenchPage::PerspectiveList::GetSortedPerspectives()
{
return usedList;
}
bool WorkbenchPage::PerspectiveList::Add(Perspective::Pointer perspective)
{
openedList.push_back(perspective);
usedList.push_front(perspective);
//It will be moved to top only when activated.
return true;
}
WorkbenchPage::PerspectiveList::PerspectiveListType::iterator WorkbenchPage::PerspectiveList::Begin()
{
return openedList.begin();
}
WorkbenchPage::PerspectiveList::PerspectiveListType::iterator WorkbenchPage::PerspectiveList::End()
{
return openedList.end();
}
WorkbenchPage::PerspectiveList::PerspectiveListType WorkbenchPage::PerspectiveList::GetOpenedPerspectives()
{
return openedList;
}
bool WorkbenchPage::PerspectiveList::Remove(Perspective::Pointer perspective)
{
if (active == perspective)
{
this->UpdateActionSets(active, Perspective::Pointer(0));
active = 0;
}
usedList.remove(perspective);
PerspectiveListType::size_type origSize = openedList.size();
openedList.remove(perspective);
return openedList.size() != origSize;
}
void WorkbenchPage::PerspectiveList::Swap(Perspective::Pointer oldPerspective,
Perspective::Pointer newPerspective)
{
PerspectiveListType::iterator oldIter = std::find(openedList.begin(),
openedList.end(), oldPerspective);
PerspectiveListType::iterator newIter = std::find(openedList.begin(),
openedList.end(), newPerspective);
if (oldIter == openedList.end() || newIter == openedList.end())
{
return;
}
std::iter_swap(oldIter, newIter);
}
bool WorkbenchPage::PerspectiveList::IsEmpty()
{
return openedList.empty();
}
Perspective::Pointer WorkbenchPage::PerspectiveList::GetActive()
{
return active;
}
Perspective::Pointer WorkbenchPage::PerspectiveList::GetNextActive()
{
if (active == 0)
{
if (usedList.empty())
{
return Perspective::Pointer(0);
}
else
{
return usedList.back();
}
}
else
{
if (usedList.size() < 2)
{
return Perspective::Pointer(0);
}
else
{
return *(++usedList.rbegin());
}
}
}
WorkbenchPage::PerspectiveList::PerspectiveListType::size_type WorkbenchPage::PerspectiveList::Size()
{
return openedList.size();
}
void WorkbenchPage::PerspectiveList::SetActive(Perspective::Pointer perspective)
{
if (perspective == active)
{
return;
}
this->UpdateActionSets(active, perspective);
active = perspective;
if (perspective != 0)
{
usedList.remove(perspective);
usedList.push_back(perspective);
}
}
WorkbenchPage::ActivationList::ActivationList(WorkbenchPage* page) :
page(page)
{
}
void WorkbenchPage::ActivationList::SetActive(SmartPointer part)
{
if (parts.empty())
{
return;
}
IWorkbenchPartReference::Pointer ref(page->GetReference(part));
if (ref)
{
if (ref == parts.back())
{
return;
}
parts.erase(std::find(parts.begin(), parts.end(), ref));
parts.push_back(ref);
}
}
void WorkbenchPage::ActivationList::BringToTop(SmartPointer<
IWorkbenchPartReference> ref)
{
ILayoutContainer::Pointer targetContainer(page->GetContainer(ref));
PartListIter newIndex = this->LastIndexOfContainer(targetContainer);
if (newIndex != parts.end() && ref == *newIndex)
{
return;
}
if (newIndex == parts.end())
{
parts.push_back(ref);
}
else
{
PartListType::size_type index = newIndex - parts.begin();
parts.erase(std::find(parts.begin(), parts.end(), ref));
PartListIter insertIndex = parts.begin() + index;
parts.insert(insertIndex, ref);
}
}
WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::LastIndexOfContainer(
SmartPointer container)
{
PartListReverseIter i = parts.rbegin();
while (i != parts.rend())
{
IWorkbenchPartReference::Pointer ref(*i);
ILayoutContainer::Pointer cnt(page->GetContainer(ref));
if (cnt == container)
{
return --i.base();
}
++i;
}
return parts.end();
}
void WorkbenchPage::ActivationList::SetActive(SmartPointer<
IWorkbenchPartReference> ref)
{
this->SetActive(ref->GetPart(true));
}
void WorkbenchPage::ActivationList::Add(
SmartPointer ref)
{
if (std::find(parts.begin(), parts.end(), ref) != parts.end())
{
return;
}
ref->GetPart(false);
parts.push_front(ref);
}
SmartPointer WorkbenchPage::ActivationList::GetActive()
{
if (parts.empty())
{
return IWorkbenchPart::Pointer(0);
}
return this->GetActive(parts.end());
}
SmartPointer WorkbenchPage::ActivationList::GetPreviouslyActive()
{
if (parts.size() < 2)
{
return IWorkbenchPart::Pointer(0);
}
return this->GetActive(--parts.end());
}
SmartPointer WorkbenchPage::ActivationList::GetActiveReference(
bool editorsOnly)
{
return this->GetActiveReference(parts.end(), editorsOnly);
}
WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::IndexOf(
SmartPointer part)
{
IWorkbenchPartReference::Pointer ref(page->GetReference(part));
if (ref == 0)
{
return parts.end();
}
return std::find(parts.begin(), parts.end(), ref);
}
WorkbenchPage::ActivationList::PartListIter WorkbenchPage::ActivationList::IndexOf(
SmartPointer ref)
{
return std::find(parts.begin(), parts.end(), ref);
}
bool WorkbenchPage::ActivationList::Remove(
SmartPointer ref)
{
bool contains = std::find(parts.begin(), parts.end(), ref) != parts.end();
parts.erase(std::find(parts.begin(), parts.end(), ref));
return contains;
}
SmartPointer WorkbenchPage::ActivationList::GetTopEditor()
{
IEditorReference::Pointer editor =
this->GetActiveReference(parts.end(), true).Cast ();
if (editor == 0)
{
return IEditorPart::Pointer(0);
}
return editor->GetEditor(true);
}
SmartPointer WorkbenchPage::ActivationList::GetActive(
PartListIter start)
{
IWorkbenchPartReference::Pointer ref(this->GetActiveReference(start, false));
if (!ref)
{
return IWorkbenchPart::Pointer(0);
}
return ref->GetPart(true);
}
SmartPointer WorkbenchPage::ActivationList::GetActiveReference(
PartListIter start, bool editorsOnly)
{
// First look for parts that aren't obscured by the current zoom state
IWorkbenchPartReference::Pointer nonObscured = this->GetActiveReference(
start, editorsOnly, true);
if (nonObscured)
{
return nonObscured;
}
// Now try all the rest of the parts
return this->GetActiveReference(start, editorsOnly, false);
}
SmartPointer WorkbenchPage::ActivationList::GetActiveReference(
PartListIter start, bool editorsOnly, bool /*skipPartsObscuredByZoom*/)
{
std::vector views = page->GetViewReferences();
PartListReverseIter i(start);
while (i != parts.rend())
{
WorkbenchPartReference::Pointer ref(i->Cast ());
if (editorsOnly && (ref.Cast () == 0))
{
++i;
continue;
}
// Skip parts whose containers have disabled auto-focus
PartPane::Pointer pane(ref->GetPane());
if (pane)
{
if (!pane->AllowsAutoFocus())
{
++i;
continue;
}
// if (skipPartsObscuredByZoom) {
// if (pane.isObscuredByZoom()) {
// continue;
// }
// }
}
// Skip fastviews (unless overridden)
if (IViewReference::Pointer viewRef = ref.Cast())
{
//if (ref == getActiveFastView() || !((IViewReference) ref).isFastView()) {
for (unsigned int j = 0; j < views.size(); j++)
{
if (views[j] == viewRef)
{
return viewRef.Cast ();
}
}
//}
}
else
{
return ref.Cast ();
}
++i;
}
return IWorkbenchPartReference::Pointer(0);
}
std::vector > WorkbenchPage::ActivationList::GetEditors()
{
std::vector editors;
for (PartListIter i = parts.begin(); i != parts.end(); ++i)
{
if (IEditorReference::Pointer part = i->Cast())
{
editors.push_back(part);
}
}
return editors;
}
std::vector > WorkbenchPage::ActivationList::GetParts()
{
std::vector views(page->GetViewReferences());
std::vector resultList;
for (PartListIter iterator = parts.begin(); iterator != parts.end(); ++iterator)
{
if (IViewReference::Pointer ref = iterator->Cast())
{
//Filter views from other perspectives
for (unsigned int i = 0; i < views.size(); i++)
{
if (ref == views[i])
{
resultList.push_back(ref);
break;
}
}
}
else
{
resultList.push_back(*iterator);
}
}
return resultList;
}
void WorkbenchPage::ActionSwitcher::UpdateActivePart(
IWorkbenchPart::Pointer newPart)
{
IWorkbenchPart::Pointer _activePart = this->activePart.Lock();
IEditorPart::Pointer _topEditor = this->topEditor.Lock();
if (_activePart == newPart)
{
return;
}
bool isNewPartAnEditor = newPart.Cast ().IsNotNull();
if (isNewPartAnEditor)
{
std::string oldId;
if (_topEditor)
{
oldId = _topEditor->GetSite()->GetId();
}
std::string newId = newPart->GetSite()->GetId();
// if the active part is an editor and the new editor
// is the same kind of editor, then we don't have to do
// anything
if (activePart == topEditor && newId == oldId)
{
activePart = newPart;
topEditor = newPart.Cast ();
return;
}
// remove the contributions of the old editor
// if it is a different kind of editor
if (oldId != newId)
{
this->DeactivateContributions(_topEditor, true);
}
// if a view was the active part, disable its contributions
if (_activePart && _activePart != _topEditor)
{
this->DeactivateContributions(_activePart, true);
}
// show (and enable) the contributions of the new editor
// if it is a different kind of editor or if the
// old active part was a view
if (newId != oldId || _activePart != _topEditor)
{
this->ActivateContributions(newPart, true);
}
}
else if (newPart.IsNull())
{
if (_activePart)
{
// remove all contributions
this->DeactivateContributions(_activePart, true);
}
}
else
{
// new part is a view
// if old active part is a view, remove all contributions,
// but if old part is an editor only disable
if (_activePart)
{
this->DeactivateContributions(_activePart,
_activePart.Cast ().IsNotNull());
}
this->ActivateContributions(newPart, true);
}
//TODO WorkbenchPage action sets
// ArrayList newActionSets = 0;
// if (isNewPartAnEditor || (activePart == topEditor && newPart == 0))
// {
// newActionSets = calculateActionSets(newPart, 0);
// }
// else
// {
// newActionSets = calculateActionSets(newPart, topEditor);
// }
//
// if (!updateActionSets(newActionSets))
// {
// updateActionBars();
// }
if (isNewPartAnEditor)
{
topEditor = newPart.Cast ();
}
else if (activePart == topEditor && newPart.IsNull())
{
// since we removed all the contributions, we clear the top
// editor
topEditor.Reset();
}
activePart = newPart;
}
void WorkbenchPage::ActionSwitcher::UpdateTopEditor(
IEditorPart::Pointer newEditor)
{
if (topEditor.Lock() == newEditor)
{
return;
}
if (activePart == topEditor)
{
this->UpdateActivePart(newEditor);
return;
}
std::string oldId;
if (!topEditor.Expired())
{
oldId = topEditor.Lock()->GetSite()->GetId();
}
std::string newId;
if (newEditor.IsNotNull())
{
newId = newEditor->GetSite()->GetId();
}
if (oldId == newId)
{
// we don't have to change anything
topEditor = newEditor;
return;
}
// Remove the contributions of the old editor
if (!topEditor.Expired())
{
this->DeactivateContributions(topEditor.Lock(), true);
}
// Show (disabled) the contributions of the new editor
if (newEditor.IsNotNull())
{
this->ActivateContributions(newEditor, false);
}
// ArrayList newActionSets = calculateActionSets(activePart, newEditor);
// if (!updateActionSets(newActionSets))
// {
// updateActionBars();
// }
topEditor = newEditor;
}
void WorkbenchPage::ActionSwitcher::ActivateContributions(
IWorkbenchPart::Pointer /*part*/, bool /*enable*/)
{
//PartSite::Pointer site = part->GetSite().Cast ();
//site->ActivateActionBars(enable);
}
void WorkbenchPage::ActionSwitcher::DeactivateContributions(
IWorkbenchPart::Pointer /*part*/, bool /*remove*/)
{
//PartSite::Pointer site = part->GetSite().Cast ();
//site->DeactivateActionBars(remove);
}
const IExtensionPoint* WorkbenchPage::GetPerspectiveExtensionPoint()
{
return Platform::GetExtensionPointService()->GetExtensionPoint(
PlatformUI::PLUGIN_ID + "."
+ WorkbenchRegistryConstants::PL_PERSPECTIVE_EXTENSIONS);
}
WorkbenchPage::WorkbenchPage(WorkbenchWindow* w, const std::string& layoutID,
IAdaptable* input)
{
if (layoutID == "")
{
throw WorkbenchException("Perspective ID is undefined");
}
this->Register();
this->Init(w, layoutID, input, true);
this->UnRegister(false);
}
WorkbenchPage::WorkbenchPage(WorkbenchWindow* w, IAdaptable* input)
{
this->Register();
this->Init(w, "", input, false);
this->UnRegister(false);
}
void WorkbenchPage::Activate(IWorkbenchPart::Pointer part)
{
// Sanity check.
if (!this->CertifyPart(part))
{
return;
}
if (window->IsClosing())
{
return;
}
// if (composite!=0 && composite.isVisible() && !((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part))
// {
// return;
// }
// Activate part.
//if (window.getActivePage() == this) {
IWorkbenchPartReference::Pointer ref = this->GetReference(part);
this->InternalBringToTop(ref);
this->SetActivePart(part);
}
void WorkbenchPage::ActivatePart(const IWorkbenchPart::Pointer part)
{
// Platform.run(new SafeRunnable(WorkbenchMessages.WorkbenchPage_ErrorActivatingView)
// {
// public void WorkbenchPage::run()
// {
if (part.IsNotNull())
{
//part.setFocus();
PartPane::Pointer pane = this->GetPane(part);
pane->SetFocus();
PartSite::Pointer site = part->GetSite().Cast ();
pane->ShowFocus(true);
//this->UpdateTabList(part);
//SubActionBars bars = (SubActionBars) site.getActionBars();
//bars.partChanged(part);
}
// }
// }
// );
}
void WorkbenchPage::AddPartListener(IPartListener::Pointer l)
{
partList->GetPartService()->AddPartListener(l);
}
void WorkbenchPage::AddSelectionListener(ISelectionListener::Pointer listener)
{
selectionService->AddSelectionListener(listener);
}
void WorkbenchPage::AddSelectionListener(const std::string& partId,
ISelectionListener::Pointer listener)
{
selectionService->AddSelectionListener(partId, listener);
}
void WorkbenchPage::AddPostSelectionListener(
ISelectionListener::Pointer listener)
{
selectionService->AddPostSelectionListener(listener);
}
void WorkbenchPage::AddPostSelectionListener(const std::string& partId,
ISelectionListener::Pointer listener)
{
selectionService->AddPostSelectionListener(partId, listener);
}
ILayoutContainer::Pointer WorkbenchPage::GetContainer(
IWorkbenchPart::Pointer part)
{
PartPane::Pointer pane = this->GetPane(part);
if (pane == 0)
{
return ILayoutContainer::Pointer(0);
}
return pane->GetContainer();
}
ILayoutContainer::Pointer WorkbenchPage::GetContainer(
IWorkbenchPartReference::Pointer part)
{
PartPane::Pointer pane = this->GetPane(part);
if (pane == 0)
{
return ILayoutContainer::Pointer(0);
}
return pane->GetContainer();
}
PartPane::Pointer WorkbenchPage::GetPane(IWorkbenchPart::Pointer part)
{
if (part.IsNull())
{
return PartPane::Pointer(0);
}
return this->GetPane(this->GetReference(part));
}
PartPane::Pointer WorkbenchPage::GetPane(IWorkbenchPartReference::Pointer part)
{
if (part.IsNull())
{
return PartPane::Pointer(0);
}
return part.Cast ()->GetPane();
}
bool WorkbenchPage::InternalBringToTop(IWorkbenchPartReference::Pointer part)
{
bool broughtToTop = false;
// Move part.
if (part.Cast ().IsNotNull())
{
ILayoutContainer::Pointer container = this->GetContainer(part);
if (container.Cast () != 0)
{
PartStack::Pointer stack = container.Cast ();
PartPane::Pointer newPart = this->GetPane(part);
if (stack->GetSelection() != newPart)
{
stack->SetSelection(newPart);
}
broughtToTop = true;
}
}
else if (part.Cast ().IsNotNull())
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
broughtToTop = persp->BringToTop(part.Cast ());
}
}
// Ensure that this part is considered the most recently activated part
// in this stack
activationList->BringToTop(part);
return broughtToTop;
}
void WorkbenchPage::BringToTop(IWorkbenchPart::Pointer part)
{
// Sanity check.
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0 || !this->CertifyPart(part))
{
return;
}
// if (!((GrabFocus)Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part))
// {
// return;
// }
// std::string label; // debugging only
// if (UIStats.isDebugging(UIStats.BRING_PART_TO_TOP))
// {
// label = part != 0 ? part.getTitle() : "none"; //$NON-NLS-1$
// }
IWorkbenchPartReference::Pointer ref = this->GetReference(part);
ILayoutContainer::Pointer activeEditorContainer = this->GetContainer(
this->GetActiveEditor().Cast ());
ILayoutContainer::Pointer activePartContainer = this->GetContainer(
this->GetActivePart());
ILayoutContainer::Pointer newPartContainer = this->GetContainer(part);
if (newPartContainer == activePartContainer)
{
this->MakeActive(ref);
}
else if (newPartContainer == activeEditorContainer)
{
if (ref.Cast () != 0)
{
if (part != 0)
{
IWorkbenchPartSite::Pointer site = part->GetSite();
if (site.Cast () != 0)
{
ref = site.Cast ()->GetPane()->GetPartReference();
}
}
this->MakeActiveEditor(ref.Cast ());
}
else
{
this->MakeActiveEditor(IEditorReference::Pointer(0));
}
}
else
{
this->InternalBringToTop(ref);
if (ref != 0)
{
partList->FirePartBroughtToTop(ref);
}
}
}
void WorkbenchPage::BusyResetPerspective()
{
ViewIntroAdapterPart::Pointer
introViewAdapter =
dynamic_cast (GetWorkbenchWindow() ->GetWorkbench()->GetIntroManager())->GetIntroAdapterPart().Cast<
ViewIntroAdapterPart> ();
// PartPane introPane = 0;
// boolean introFullScreen = false;
// if (introViewAdapter != 0)
// {
// introPane = ((PartSite) introViewAdapter.getSite()).getPane();
// introViewAdapter.setHandleZoomEvents(false);
// introFullScreen = introPane.isZoomed();
// }
// //try to prevent intro flicker.
// if (introFullScreen)
// {
// window.getShell().setRedraw(false);
// }
// try
// {
// // Always unzoom
// if (isZoomed())
// {
// zoomOut();
// }
// Get the current perspective.
// This describes the working layout of the page and differs from
// the original template.
Perspective::Pointer oldPersp = this->GetActivePerspective();
// Map the current perspective to the original template.
// If the original template cannot be found then it has been deleted.
// In that case just return. (PR#1GDSABU).
IPerspectiveRegistry* reg =
WorkbenchPlugin::GetDefault() ->GetPerspectiveRegistry();
PerspectiveDescriptor::Pointer desc = reg->FindPerspectiveWithId(
oldPersp->GetDesc()->GetId()).Cast ();
if (desc == 0)
{
desc
= reg->FindPerspectiveWithId(oldPersp ->GetDesc().Cast<
PerspectiveDescriptor> ()->GetOriginalId()).Cast<
PerspectiveDescriptor> ();
}
if (desc == 0)
{
return;
}
// Notify listeners that we are doing a reset.
window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc,
CHANGE_RESET);
// Create new persp from original template.
// Suppress the perspectiveOpened and perspectiveClosed events otherwise it looks like two
// instances of the same perspective are open temporarily (see bug 127470).
Perspective::Pointer newPersp = this->CreatePerspective(desc, false);
if (newPersp == 0)
{
// We're not going through with the reset, so it is complete.
window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc,
CHANGE_RESET_COMPLETE);
return;
}
// Update the perspective list and shortcut
perspList.Swap(oldPersp, newPersp);
// Install new persp.
this->SetPerspective(newPersp);
// Destroy old persp.
this->DisposePerspective(oldPersp, false);
// Update the Coolbar layout.
this->ResetToolBarLayout();
// restore the maximized intro
if (introViewAdapter)
{
try
{
// ensure that the intro is visible in the new perspective
ShowView(IntroConstants::INTRO_VIEW_ID);
// if (introFullScreen)
// {
// toggleZoom(introPane.getPartReference());
// }
} catch (PartInitException& e)
{
//TODO IStatus
WorkbenchPlugin::Log("Could not restore intro", e);
// WorkbenchPlugin.getStatus(e));
}
// finally
// {
// // we want the intro back to a normal state before we fire the event
// introViewAdapter.setHandleZoomEvents(true);
// }
}
// Notify listeners that we have completed our reset.
window->FirePerspectiveChanged(IWorkbenchPage::Pointer(this), desc,
CHANGE_RESET_COMPLETE);
// }
// finally
// {
// // reset the handling of zoom events (possibly for the second time) in case there was
// // an exception thrown
// if (introViewAdapter != 0)
// {
// introViewAdapter.setHandleZoomEvents(true);
// }
//
// if (introFullScreen)
// {
// window.getShell().setRedraw(true);
// }
// }
}
void WorkbenchPage::BusySetPerspective(IPerspectiveDescriptor::Pointer desc)
{
// Create new layout.
std::string label = desc->GetId(); // debugging only
Perspective::Pointer newPersp;
//try
//{
//UIStats.start(UIStats.SWITCH_PERSPECTIVE, label);
PerspectiveDescriptor::Pointer realDesc = desc.Cast ();
newPersp = this->FindPerspective(realDesc);
if (newPersp == 0)
{
newPersp = this->CreatePerspective(realDesc, true);
if (newPersp == 0)
{
return;
}
}
// Change layout.
this->SetPerspective(newPersp);
// }
// catch (std::exception& e)
// {
// UIStats.end(UIStats.SWITCH_PERSPECTIVE, desc.getId(), label);
// throw e;
// }
}
IViewPart::Pointer WorkbenchPage::BusyShowView(const std::string& viewID,
const std::string& secondaryID, int mode)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return IViewPart::Pointer(0);
}
// If this view is already visible just return.
IViewReference::Pointer ref = persp->FindView(viewID, secondaryID);
IViewPart::Pointer view;
if (ref != 0)
{
view = ref->GetView(true);
}
if (view != 0)
{
this->BusyShowView(view, mode);
return view;
}
// Show the view.
view = persp->ShowView(viewID, secondaryID);
if (view != 0)
{
this->BusyShowView(view, mode);
IWorkbenchPartReference::Pointer partReference = this->GetReference(view);
PartPane::Pointer partPane = this->GetPane(partReference);
partPane->SetInLayout(true);
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveChanged(thisPage, GetPerspective(), partReference,
CHANGE_VIEW_SHOW);
window->FirePerspectiveChanged(thisPage, GetPerspective(), CHANGE_VIEW_SHOW);
}
return view;
}
void WorkbenchPage::BusyShowView(IViewPart::Pointer part, int mode)
{
// if (!((GrabFocus) Tweaklets.get(GrabFocus.KEY)).grabFocusAllowed(part))
// {
// return;
// }
if (mode == VIEW_ACTIVATE)
{
this->Activate(part);
}
else if (mode == VIEW_VISIBLE)
{
IWorkbenchPartReference::Pointer ref = this->GetActivePartReference();
// if there is no active part or it's not a view, bring to top
if (ref == 0 || ref.Cast () == 0)
{
this->BringToTop(part);
}
else
{
// otherwise check to see if the we're in the same stack as the active view
IViewReference::Pointer activeView = ref.Cast ();
std::vector viewStack =
this->GetViewReferenceStack(part);
for (unsigned int i = 0; i < viewStack.size(); i++)
{
if (viewStack[i] == activeView)
{
return;
}
}
this->BringToTop(part);
}
}
}
bool WorkbenchPage::CertifyPart(IWorkbenchPart::Pointer part)
{
//Workaround for bug 22325
if (part != 0 && part->GetSite().Cast () == 0)
{
return false;
}
if (part.Cast () != 0)
{
IEditorReference::Pointer ref = this->GetReference(part).Cast<
IEditorReference> ();
return ref != 0 && this->GetEditorManager()->ContainsEditor(ref);
}
if (part.Cast () != 0)
{
Perspective::Pointer persp = this->GetActivePerspective();
return persp != 0 && persp->ContainsView(part.Cast ());
}
return false;
}
bool WorkbenchPage::Close()
{
bool ret;
//BusyIndicator.showWhile(0, new Runnable()
// {
// public void WorkbenchPage::run()
// {
ret = window->ClosePage(IWorkbenchPage::Pointer(this), true);
// }
// });
return ret;
}
bool WorkbenchPage::CloseAllSavedEditors()
{
// get the Saved editors
std::list editors = this->GetEditorReferences();
std::list savedEditors;
for (std::list::iterator iter = editors.begin(); iter
!= editors.end(); ++iter)
{
IEditorReference::Pointer editor = *iter;
if (!editor->IsDirty())
{
savedEditors.push_back(editor);
}
}
//there are no unsaved editors
if (savedEditors.empty())
{
return true;
}
return this->CloseEditors(savedEditors, false);
}
bool WorkbenchPage::CloseAllEditors(bool save)
{
return this->CloseEditors(this->GetEditorReferences(), save);
}
void WorkbenchPage::UpdateActivePart()
{
if (this->IsDeferred())
{
return;
}
IWorkbenchPartReference::Pointer oldActivePart =
partList->GetActivePartReference();
IWorkbenchPartReference::Pointer oldActiveEditor =
partList->GetActiveEditorReference();
IWorkbenchPartReference::Pointer newActivePart;
IEditorReference::Pointer newActiveEditor;
if (!window->IsClosing())
{
// If an editor is active, try to keep an editor active
if (oldActiveEditor && oldActivePart == oldActiveEditor)
{
newActiveEditor = activationList->GetActiveReference(true).Cast<
IEditorReference> ();
newActivePart = newActiveEditor;
if (newActivePart == 0)
{
// Only activate a non-editor if there's no editors left
newActivePart = activationList->GetActiveReference(false);
}
}
else
{
// If a non-editor is active, activate whatever was activated most recently
newActivePart = activationList->GetActiveReference(false);
if (newActivePart.Cast () != 0)
{
// If that happens to be an editor, make it the active editor as well
newActiveEditor = newActivePart.Cast ();
}
else
{
// Otherwise, select whatever editor was most recently active
newActiveEditor = activationList->GetActiveReference(true).Cast<
IEditorReference> ();
}
}
}
if (oldActiveEditor != newActiveEditor)
{
this->MakeActiveEditor(newActiveEditor);
}
if (newActivePart != oldActivePart)
{
this->MakeActive(newActivePart);
}
}
void WorkbenchPage::MakeActive(IWorkbenchPartReference::Pointer ref)
{
if (ref == 0)
{
this->SetActivePart(IWorkbenchPart::Pointer(0));
}
else
{
IWorkbenchPart::Pointer newActive = ref->GetPart(true);
if (newActive == 0)
{
this->SetActivePart(IWorkbenchPart::Pointer(0));
}
else
{
this->Activate(newActive);
}
}
}
void WorkbenchPage::MakeActiveEditor(IEditorReference::Pointer ref)
{
if (ref == this->GetActiveEditorReference())
{
return;
}
IEditorPart::Pointer part = (ref == 0) ? IEditorPart::Pointer(0)
: ref->GetEditor(true);
if (part)
{
editorMgr->SetVisibleEditor(ref, false);
//navigationHistory.MarkEditor(part);
}
actionSwitcher.UpdateTopEditor(part);
if (ref)
{
activationList->BringToTop(this->GetReference(part));
}
partList->SetActiveEditor(ref);
}
bool WorkbenchPage::CloseEditors(
const std::list& refArray, bool save)
{
if (refArray.empty())
{
return true;
}
IWorkbenchPage::Pointer thisPage(this);
// Check if we're being asked to close any parts that are already closed or cannot
// be closed at this time
std::vector editorRefs;
for (std::list::const_iterator iter =
refArray.begin(); iter != refArray.end(); ++iter)
{
IEditorReference::Pointer reference = *iter;
// If we're in the middle of creating this part, this is a programming error. Abort the entire
// close operation. This usually occurs if someone tries to open a dialog in a method that
// isn't allowed to do so, and a *syncExec tries to close the part. If this shows up in a log
// file with a dialog's event loop on the stack, then the code that opened the dialog is usually
// at fault.
if (partBeingActivated == reference)
{
Poco::RuntimeException re(
"WARNING: Blocked recursive attempt to close part " //$NON-NLS-1$
+ partBeingActivated->GetId()
+ " while still in the middle of activating it");
WorkbenchPlugin::Log(re);
return false;
}
// if (reference.Cast () != 0)
// {
// WorkbenchPartReference::Pointer ref = reference.Cast();
//
// // If we're being asked to close a part that is disposed (ie: already closed),
// // skip it and proceed with closing the remaining parts.
// if (ref.isDisposed())
// {
// continue;
// }
// }
editorRefs.push_back(reference);
}
// notify the model manager before the close
std::list partsToClose;
for (unsigned int i = 0; i < editorRefs.size(); i++)
{
IWorkbenchPart::Pointer refPart = editorRefs[i]->GetPart(false);
if (refPart != 0)
{
partsToClose.push_back(refPart);
}
}
SaveablesList::Pointer modelManager;
SaveablesList::PostCloseInfo::Pointer postCloseInfo;
if (partsToClose.size() > 0)
{
modelManager = this->GetWorkbenchWindow()->GetService(
ISaveablesLifecycleListener::GetManifestName()).Cast ();
// this may prompt for saving and return 0 if the user canceled:
postCloseInfo = modelManager->PreCloseParts(partsToClose, save,
this->GetWorkbenchWindow());
if (postCloseInfo == 0)
{
return false;
}
}
// Fire pre-removal changes
for (unsigned int i = 0; i < editorRefs.size(); i++)
{
IEditorReference::Pointer ref = editorRefs[i];
// Notify interested listeners before the close
window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref,
CHANGE_EDITOR_CLOSE);
}
this->DeferUpdates(true);
try
{
if (modelManager != 0)
{
modelManager->PostClose(postCloseInfo);
}
// Close all editors.
for (unsigned int i = 0; i < editorRefs.size(); i++)
{
IEditorReference::Pointer ref = editorRefs[i];
// Remove editor from the presentation
editorPresentation->CloseEditor(ref);
this->PartRemoved(ref.Cast ());
}
} catch (...)
{
}
this->DeferUpdates(false);
// Notify interested listeners after the close
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_CLOSE);
// Return true on success.
return true;
}
void WorkbenchPage::DeferUpdates(bool shouldDefer)
{
if (shouldDefer)
{
if (deferCount == 0)
{
this->StartDeferring();
}
deferCount++;
}
else
{
deferCount--;
if (deferCount == 0)
{
this->HandleDeferredEvents();
}
}
}
void WorkbenchPage::StartDeferring()
{
//editorPresentation.getLayoutPart().deferUpdates(true);
}
void WorkbenchPage::HandleDeferredEvents()
{
editorPresentation->GetLayoutPart()->DeferUpdates(false);
this->UpdateActivePart();
std::vector disposals = pendingDisposals;
pendingDisposals.clear();
for (unsigned int i = 0; i < disposals.size(); i++)
{
this->DisposePart(disposals[i]);
}
}
bool WorkbenchPage::IsDeferred()
{
return deferCount > 0;
}
bool WorkbenchPage::CloseEditor(IEditorReference::Pointer editorRef, bool save)
{
std::list list;
list.push_back(editorRef);
return this->CloseEditors(list, save);
}
bool WorkbenchPage::CloseEditor(IEditorPart::Pointer editor, bool save)
{
IWorkbenchPartReference::Pointer ref = this->GetReference(editor);
if (ref.Cast ().IsNotNull())
{
std::list list;
list.push_back(ref.Cast ());
return this->CloseEditors(list, save);
}
return false;
}
+void WorkbenchPage::CloseCurrentPerspective(bool saveParts, bool closePage)
+{
+ Perspective::Pointer persp = this->GetActivePerspective();
+ if (persp != 0)
+ {
+ this->ClosePerspective(persp, saveParts, closePage);
+ }
+}
+
void WorkbenchPage::ClosePerspective(IPerspectiveDescriptor::Pointer desc,
bool saveParts, bool closePage)
{
Perspective::Pointer persp = this->FindPerspective(desc);
if (persp != 0)
{
this->ClosePerspective(persp, saveParts, closePage);
}
}
void WorkbenchPage::ClosePerspective(Perspective::Pointer persp,
bool saveParts, bool closePage)
{
// // Always unzoom
// if (isZoomed())
// {
// zoomOut();
// }
std::vector partsToSave;
std::list viewsToClose;
// collect views that will go away and views that are dirty
std::vector viewReferences =
persp->GetViewReferences();
for (unsigned int i = 0; i < viewReferences.size(); i++)
{
IViewReference::Pointer reference = viewReferences[i];
if (this->GetViewFactory()->GetReferenceCount(reference) == 1)
{
IViewPart::Pointer viewPart = reference->GetView(false);
if (viewPart != 0)
{
viewsToClose.push_back(viewPart);
if (saveParts && reference->IsDirty())
{
partsToSave.push_back(viewPart);
}
}
}
}
if (saveParts && perspList.Size() == 1)
{
// collect editors that are dirty
std::list editorReferences =
this->GetEditorReferences();
for (std::list::iterator refIter =
editorReferences.begin(); refIter != editorReferences.end(); ++refIter)
{
IEditorReference::Pointer reference = *refIter;
if (reference->IsDirty())
{
IEditorPart::Pointer editorPart = reference->GetEditor(false);
if (editorPart != 0)
{
partsToSave.push_back(editorPart);
}
}
}
}
if (saveParts && !partsToSave.empty())
{
if (!EditorManager::SaveAll(partsToSave, true, true, false,
IWorkbenchWindow::Pointer(window)))
{
// user canceled
return;
}
}
// Close all editors on last perspective close
if (perspList.Size() == 1 && this->GetEditorManager()->GetEditorCount() > 0)
{
// Close all editors
if (!this->CloseAllEditors(false))
{
return;
}
}
// closeAllEditors already notified the saveables list about the editors.
SaveablesList::Pointer
saveablesList =
this->GetWorkbenchWindow()->GetWorkbench()->GetService(
ISaveablesLifecycleListener::GetManifestName()).Cast<
SaveablesList> ();
// we took care of the saving already, so pass in false (postCloseInfo will be non-0)
SaveablesList::PostCloseInfo::Pointer postCloseInfo =
saveablesList->PreCloseParts(viewsToClose, false,
this->GetWorkbenchWindow());
saveablesList->PostClose(postCloseInfo);
// Dispose of the perspective
bool isActive = (perspList.GetActive() == persp);
if (isActive)
{
this->SetPerspective(perspList.GetNextActive());
}
this->DisposePerspective(persp, true);
if (closePage && perspList.Size() == 0)
{
this->Close();
}
}
void WorkbenchPage::CloseAllPerspectives(bool saveEditors, bool closePage)
{
if (perspList.IsEmpty())
{
return;
}
// // Always unzoom
// if (isZoomed())
// {
// zoomOut();
// }
if (saveEditors)
{
if (!this->SaveAllEditors(true))
{
return;
}
}
// Close all editors
if (!this->CloseAllEditors(false))
{
return;
}
// Deactivate the active perspective and part
this->SetPerspective(Perspective::Pointer(0));
// Close each perspective in turn
PerspectiveList oldList = perspList;
perspList = PerspectiveList();
for (PerspectiveList::iterator itr = oldList.Begin(); itr != oldList.End(); ++itr)
{
this->ClosePerspective(*itr, false, false);
}
if (closePage)
{
this->Close();
}
}
void WorkbenchPage::CreateClientComposite()
{
void* parent = window->GetPageComposite();
// StartupThreading.runWithoutExceptions(new StartupRunnable()
// {
//
// public void WorkbenchPage::runWithException()
// {
composite
= Tweaklets::Get(WorkbenchPageTweaklet::KEY)->CreateClientComposite(
parent);
Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, false); // Make visible on activate.
// force the client composite to be layed out
// parent.layout();
// }
// });
}
Perspective::Pointer WorkbenchPage::CreatePerspective(
PerspectiveDescriptor::Pointer desc, bool notify)
{
std::string label = desc->GetId(); // debugging only
try
{
//UIStats.start(UIStats.CREATE_PERSPECTIVE, label);
WorkbenchPage::Pointer thisPage(this);
Perspective::Pointer persp(new Perspective(desc, thisPage));
perspList.Add(persp);
if (notify)
{
window->FirePerspectiveOpened(thisPage, desc);
}
//if the perspective is fresh and uncustomzied then it is not dirty
//no reset will be prompted for
if (!desc->HasCustomDefinition())
{
dirtyPerspectives.erase(desc->GetId());
}
return persp;
} catch (WorkbenchException& /*e*/)
{
if (!window->GetWorkbenchImpl()->IsStarting())
{
MessageDialog::OpenError(window->GetShell(), "Error",
"Problems opening perspective \"" + desc->GetId() + "\"");
}
return Perspective::Pointer(0);
}
// finally
// {
// UIStats.end(UIStats.CREATE_PERSPECTIVE, desc.getId(), label);
// }
}
void WorkbenchPage::PartAdded(WorkbenchPartReference::Pointer ref)
{
activationList->Add(ref);
partList->AddPart(ref);
this->UpdateActivePart();
}
void WorkbenchPage::PartRemoved(WorkbenchPartReference::Pointer ref)
{
activationList->Remove(ref);
this->DisposePart(ref);
}
void WorkbenchPage::DisposePart(WorkbenchPartReference::Pointer ref)
{
if (this->IsDeferred())
{
pendingDisposals.push_back(ref);
}
else
{
partList->RemovePart(ref);
ref->Dispose();
}
}
void WorkbenchPage::DeactivatePart(IWorkbenchPart::Pointer part)
{
if (part.IsNotNull())
{
PartSite::Pointer site = part->GetSite().Cast ();
site->GetPane()->ShowFocus(false);
}
}
void WorkbenchPage::DetachView(IViewReference::Pointer ref)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return;
}
PerspectiveHelper* presentation = persp->GetPresentation();
presentation->DetachPart(ref);
}
void WorkbenchPage::AttachView(IViewReference::Pointer ref)
{
PerspectiveHelper* presentation = this->GetPerspectivePresentation();
presentation->AttachPart(ref);
}
WorkbenchPage::~WorkbenchPage()
{
// increment reference count to prevent recursive deletes
this->Register();
{
{
this->MakeActiveEditor(IEditorReference::Pointer(0));
this->MakeActive(IWorkbenchPartReference::Pointer(0));
// Close and dispose the editors.
this->CloseAllEditors(false);
// Need to make sure model data is cleaned up when the page is
// disposed. Collect all the views on the page and notify the
// saveable list of a pre/post close. This will free model data.
std::vector partsToClose =
this->GetOpenParts();
std::list dirtyParts;
for (unsigned int i = 0; i < partsToClose.size(); i++)
{
IWorkbenchPart::Pointer part = partsToClose[i]->GetPart(false);
if (part != 0 && part.Cast () != 0)
{
dirtyParts.push_back(part);
}
}
SaveablesList::Pointer saveablesList =
this->GetWorkbenchWindow()->GetWorkbench()->GetService(
ISaveablesLifecycleListener::GetManifestName()).Cast<
SaveablesList> ();
SaveablesList::PostCloseInfo::Pointer postCloseInfo =
saveablesList->PreCloseParts(dirtyParts, false,
this->GetWorkbenchWindow());
saveablesList->PostClose(postCloseInfo);
IWorkbenchPage::Pointer thisPage(this);
// Get rid of perspectives. This will close the views
for (PerspectiveList::iterator itr = perspList.Begin(); itr
!= perspList.End(); ++itr)
{
Perspective::Pointer perspective = *itr;
window->FirePerspectiveClosed(thisPage, perspective->GetDesc());
//perspective->Dispose();
}
perspList = PerspectiveList();
// Capture views.
std::vector refs = viewFactory->GetViews();
// if (refs.size() > 0)
// {
// // Dispose views.
// for (unsigned int i = 0; i < refs.size(); i++)
// {
// WorkbenchPartReference::Pointer ref = refs[i].Cast();
// //partList.RemovePart(ref);
// //this->FirePartClosed(refs[i]);
// // Platform.run(new SafeRunnable() {
// // public void run() {
// // // WorkbenchPlugin.log(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH,
// // // Status.OK, "WorkbenchPage leaked a refcount for view " + ref.getId(), 0)); //$NON-NLS-1$//$NON-NLS-2$
//
// ref.dispose();
// // }
//
// // public void handleException(Throwable e) {
// // }
// // });
// }
// }
// Get rid of editor presentation.
//editorPresentation->Dispose();
// Get rid of composite.
//composite.dispose();
//navigationHistory.dispose();
//stickyViewMan.clear();
// if (tracker != 0)
// {
// tracker.close();
// }
// // if we're destroying a window in a non-shutdown situation then we should
// // clean up the working set we made.
// if (!window->GetWorkbench()->IsClosing())
// {
// if (aggregateWorkingSet != 0)
// {
// PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(
// aggregateWorkingSet);
// }
// }
}
partBeingActivated = 0;
pendingDisposals.clear();
stickyViewMan = 0;
delete viewFactory;
delete editorPresentation;
delete editorMgr;
delete activationList;
deferredActivePersp = 0;
dirtyPerspectives.clear();
delete selectionService;
partList = 0;
}
// decrement reference count again, without explicit deletion
this->UnRegister(false);
}
void WorkbenchPage::DisposePerspective(Perspective::Pointer persp, bool notify)
{
// Get rid of perspective.
perspList.Remove(persp);
if (notify)
{
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveClosed(thisPage, persp->GetDesc());
}
//persp->Dispose();
stickyViewMan->Remove(persp->GetDesc()->GetId());
}
Perspective::Pointer WorkbenchPage::FindPerspective(
IPerspectiveDescriptor::Pointer desc)
{
for (PerspectiveList::iterator itr = perspList.Begin(); itr
!= perspList.End(); ++itr)
{
Perspective::Pointer mgr = *itr;
if (desc->GetId() == mgr->GetDesc()->GetId())
{
return mgr;
}
}
return Perspective::Pointer(0);
}
IViewPart::Pointer WorkbenchPage::FindView(const std::string& id)
{
IViewReference::Pointer ref = this->FindViewReference(id);
if (ref == 0)
{
return IViewPart::Pointer(0);
}
return ref->GetView(true);
}
IViewReference::Pointer WorkbenchPage::FindViewReference(
const std::string& viewId)
{
return this->FindViewReference(viewId, "");
}
IViewReference::Pointer WorkbenchPage::FindViewReference(
const std::string& viewId, const std::string& secondaryId)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return IViewReference::Pointer(0);
}
return persp->FindView(viewId, secondaryId);
}
IEditorPart::Pointer WorkbenchPage::GetActiveEditor()
{
return partList->GetActiveEditor();
}
IEditorReference::Pointer WorkbenchPage::GetActiveEditorReference()
{
return partList->GetActiveEditorReference();
}
IWorkbenchPart::Pointer WorkbenchPage::GetActivePart()
{
return partList->GetActivePart();
}
IWorkbenchPartReference::Pointer WorkbenchPage::GetActivePartReference()
{
return partList->GetActivePartReference();
}
Perspective::Pointer WorkbenchPage::GetActivePerspective()
{
return perspList.GetActive();
}
void* WorkbenchPage::GetClientComposite()
{
return composite;
}
EditorManager* WorkbenchPage::GetEditorManager()
{
return editorMgr;
}
PerspectiveHelper* WorkbenchPage::GetPerspectivePresentation()
{
if (this->GetActivePerspective() != 0)
{
return this->GetActivePerspective()->GetPresentation();
}
return 0;
}
/**
* Answer the editor presentation.
*/
EditorAreaHelper* WorkbenchPage::GetEditorPresentation()
{
return editorPresentation;
}
std::vector WorkbenchPage::GetEditors()
{
std::list refs = this->GetEditorReferences();
std::vector result;
//Display d = getWorkbenchWindow().getShell().getDisplay();
//Must be backward compatible.
// d.syncExec(new Runnable()
// {
// public void WorkbenchPage::run()
// {
for (std::list::iterator iter = refs.begin(); iter
!= refs.end(); ++iter)
{
IEditorPart::Pointer part = (*iter)->GetEditor(true);
if (part != 0)
{
result.push_back(part);
}
}
// }
// });
return result;
}
std::vector WorkbenchPage::GetDirtyEditors()
{
return this->GetEditorManager()->GetDirtyEditors();
}
std::vector WorkbenchPage::GetDirtyParts()
{
std::vector result;
std::vector allParts = this->GetAllParts();
for (unsigned int i = 0; i < allParts.size(); i++)
{
IWorkbenchPartReference::Pointer reference = allParts[i];
IWorkbenchPart::Pointer part = reference->GetPart(false);
if (part != 0 && part.Cast () != 0)
{
ISaveablePart::Pointer saveable = part.Cast ();
if (saveable->IsDirty())
{
result.push_back(saveable);
}
}
}
return result;
}
IEditorPart::Pointer WorkbenchPage::FindEditor(IEditorInput::Pointer input)
{
return this->GetEditorManager()->FindEditor(input);
}
std::vector WorkbenchPage::FindEditors(
IEditorInput::Pointer input, const std::string& editorId, int matchFlags)
{
return this->GetEditorManager()->FindEditors(input, editorId, matchFlags);
}
std::list WorkbenchPage::GetEditorReferences()
{
return editorPresentation->GetEditors();
}
IAdaptable* WorkbenchPage::GetInput()
{
return input;
}
std::string WorkbenchPage::GetLabel()
{
std::string label = "";
// IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(input,
// IWorkbenchAdapter.class);
// if (adapter != 0)
// {
// label = adapter.getLabel(input);
// }
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
label = label + " - " + persp->GetDesc()->GetLabel();
}
else if (deferredActivePersp != 0)
{
label = label + " - " + deferredActivePersp->GetLabel();
}
return label;
}
IPerspectiveDescriptor::Pointer WorkbenchPage::GetPerspective()
{
if (deferredActivePersp != 0)
{
return deferredActivePersp;
}
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
return persp->GetDesc();
}
else
{
return IPerspectiveDescriptor::Pointer(0);
}
}
ISelection::ConstPointer WorkbenchPage::GetSelection() const
{
return selectionService->GetSelection();
}
ISelection::ConstPointer WorkbenchPage::GetSelection(const std::string& partId)
{
return selectionService->GetSelection(partId);
}
//ISelectionService::SelectionEvents& WorkbenchPage::GetSelectionEvents(const std::string& partId)
//{
// return selectionService->GetSelectionEvents(partId);
//}
ViewFactory* WorkbenchPage::GetViewFactory()
{
if (viewFactory == 0)
{
viewFactory = new ViewFactory(this,
WorkbenchPlugin::GetDefault()->GetViewRegistry());
}
return viewFactory;
}
std::vector WorkbenchPage::GetViewReferences()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
return persp->GetViewReferences();
}
else
{
return std::vector();
}
}
std::vector WorkbenchPage::GetViews()
{
return this->GetViews(Perspective::Pointer(0), true);
}
std::vector WorkbenchPage::GetViews(
Perspective::Pointer persp, bool restore)
{
if (persp == 0)
{
persp = this->GetActivePerspective();
}
std::vector parts;
if (persp != 0)
{
std::vector refs = persp->GetViewReferences();
for (unsigned int i = 0; i < refs.size(); i++)
{
IViewPart::Pointer part = refs[i]->GetPart(restore).Cast ();
if (part != 0)
{
parts.push_back(part);
}
}
}
return parts;
}
IWorkbenchWindow::Pointer WorkbenchPage::GetWorkbenchWindow()
{
return IWorkbenchWindow::Pointer(window);
}
void WorkbenchPage::HideView(IViewReference::Pointer ref)
{
// Sanity check.
if (ref == 0)
{
return;
}
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return;
}
bool promptedForSave = false;
IViewPart::Pointer view = ref->GetView(false);
if (view != 0)
{
if (!this->CertifyPart(view))
{
return;
}
// Confirm.
if (view.Cast () != 0)
{
ISaveablePart::Pointer saveable = view.Cast ();
if (saveable->IsSaveOnCloseNeeded())
{
IWorkbenchWindow::Pointer window =
view->GetSite()->GetWorkbenchWindow();
std::vector partsToSave;
partsToSave.push_back(view);
bool success = EditorManager::SaveAll(partsToSave, true, true, false,
window);
if (!success)
{
// the user cancelled.
return;
}
promptedForSave = true;
}
}
}
int refCount = this->GetViewFactory()->GetReferenceCount(ref);
SaveablesList::Pointer saveablesList;
SaveablesList::PostCloseInfo::Pointer postCloseInfo;
if (refCount == 1)
{
IWorkbenchPart::Pointer actualPart = ref->GetPart(false);
if (actualPart != 0)
{
saveablesList
= actualPart->GetSite()->GetService(
ISaveablesLifecycleListener::GetManifestName()).Cast<
SaveablesList> ();
std::list partsToClose;
partsToClose.push_back(actualPart);
postCloseInfo = saveablesList->PreCloseParts(partsToClose,
!promptedForSave, this->GetWorkbenchWindow());
if (postCloseInfo == 0)
{
// cancel
return;
}
}
}
IWorkbenchPage::Pointer thisPage(this);
// Notify interested listeners before the hide
window->FirePerspectiveChanged(thisPage, persp->GetDesc(), ref,
CHANGE_VIEW_HIDE);
PartPane::Pointer pane = this->GetPane(ref.Cast ());
pane->SetInLayout(false);
this->UpdateActivePart();
if (saveablesList != 0)
{
saveablesList->PostClose(postCloseInfo);
}
// Hide the part.
persp->HideView(ref);
// Notify interested listeners after the hide
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_VIEW_HIDE);
}
void WorkbenchPage::RefreshActiveView()
{
this->UpdateActivePart();
}
void WorkbenchPage::HideView(IViewPart::Pointer view)
{
this->HideView(this->GetReference(view).Cast ());
}
void WorkbenchPage::Init(WorkbenchWindow* w, const std::string& layoutID,
IAdaptable* input, bool openExtras)
{
// Save args.
this->window = w;
this->input = input;
this->composite = 0;
this->viewFactory = 0;
this->activationList = new ActivationList(this);
this->selectionService = new PageSelectionService(this);
this->partList = new WorkbenchPagePartList(this->selectionService);
this->stickyViewMan = new StickyViewManager(this);
//actionSets = new ActionSetManager(w);
deferCount = 0;
// Create presentation.
this->CreateClientComposite();
editorPresentation = new EditorAreaHelper(this);
editorMgr = new EditorManager(WorkbenchWindow::Pointer(window),
WorkbenchPage::Pointer(this), editorPresentation);
//TODO WorkbenchPage perspective reorder listener?
// // add this page as a client to be notified when the UI has re-ordered perspectives
// // so that the order can be properly maintained in the receiver.
// // E.g. a UI might support drag-and-drop and will need to make this known to ensure
// // #saveState and #restoreState do not lose this re-ordering
// w.addPerspectiveReorderListener(new IReorderListener()
// {
// public void WorkbenchPage::reorder(Object perspective, int newLoc)
// {
// perspList.reorder((IPerspectiveDescriptor)perspective, newLoc);
// }
// });
if (openExtras)
{
this->OpenPerspectiveExtras();
}
// Get perspective descriptor.
if (layoutID != "")
{
PerspectiveDescriptor::Pointer
desc =
WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry()->FindPerspectiveWithId(
layoutID).Cast ();
if (desc == 0)
{
throw WorkbenchException("Unable to create Perspective " + layoutID
+ ". There is no corresponding perspective extension.");
}
Perspective::Pointer persp = this->FindPerspective(desc);
if (persp == 0)
{
persp = this->CreatePerspective(desc, true);
}
perspList.SetActive(persp);
window->FirePerspectiveActivated(IWorkbenchPage::Pointer(this), desc);
}
// getExtensionTracker() .registerHandler(perspectiveChangeHandler,
// ExtensionTracker .createExtensionPointFilter(
// getPerspectiveExtensionPoint()));
}
void WorkbenchPage::OpenPerspectiveExtras()
{
//TODO WorkbenchPage perspectice extras
std::string extras = ""; //PrefUtil.getAPIPreferenceStore().getString(
// IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS);
Poco::StringTokenizer tok(extras, ", ", Poco::StringTokenizer::TOK_TRIM
| Poco::StringTokenizer::TOK_IGNORE_EMPTY); //$NON-NLS-1$
std::vector descs;
for (Poco::StringTokenizer::Iterator itr = tok.begin(); itr != tok.end(); ++itr)
{
std::string id = *itr;
IPerspectiveDescriptor::Pointer
desc =
WorkbenchPlugin::GetDefault()->GetPerspectiveRegistry()->FindPerspectiveWithId(
id);
if (desc != 0)
{
descs.push_back(desc);
}
}
// HACK: The perspective switcher currently adds the button for a new perspective to the beginning of the list.
// So, we process the extra perspectives in reverse order here to have their buttons appear in the order declared.
for (int i = (int) descs.size(); --i >= 0;)
{
PerspectiveDescriptor::Pointer desc =
descs[i].Cast ();
if (this->FindPerspective(desc) == 0)
{
this->CreatePerspective(desc, true);
}
}
}
bool WorkbenchPage::IsPartVisible(IWorkbenchPart::Pointer part)
{
PartPane::Pointer pane = this->GetPane(part);
return pane != 0 && pane->GetVisible();
}
bool WorkbenchPage::IsEditorAreaVisible()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return false;
}
return persp->IsEditorAreaVisible();
}
bool WorkbenchPage::IsFastView(IViewReference::Pointer /*ref*/)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
//return persp->IsFastView(ref);
return false;
}
else
{
return false;
}
}
bool WorkbenchPage::IsCloseable(IViewReference::Pointer ref)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
return persp->IsCloseable(ref);
}
return false;
}
bool WorkbenchPage::IsMoveable(IViewReference::Pointer ref)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
return persp->IsMoveable(ref);
}
return false;
}
bool WorkbenchPage::IsFixedLayout()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
return persp->IsFixedLayout();
}
else
{
return false;
}
}
bool WorkbenchPage::IsSaveNeeded()
{
return this->GetEditorManager()->IsSaveAllNeeded();
}
void WorkbenchPage::OnActivate()
{
Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, true);
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
persp->OnActivate();
this->UpdateVisibility(Perspective::Pointer(0), persp);
}
}
void WorkbenchPage::OnDeactivate()
{
this->MakeActiveEditor(IEditorReference::Pointer(0));
this->MakeActive(IWorkbenchPartReference::Pointer(0));
if (this->GetActivePerspective() != 0)
{
this->GetActivePerspective()->OnDeactivate();
}
Tweaklets::Get(GuiWidgetsTweaklet::KEY)->SetVisible(composite, false);
}
void WorkbenchPage::ReuseEditor(IReusableEditor::Pointer editor,
IEditorInput::Pointer input)
{
// Rather than calling editor.setInput on the editor directly, we do it through the part reference.
// This case lets us detect badly behaved editors that are not firing a PROP_INPUT event in response
// to the input change... but if all editors obeyed their API contract, the "else" branch would be
// sufficient.
IWorkbenchPartReference::Pointer ref = this->GetReference(editor);
if (ref.Cast () != 0)
{
EditorReference::Pointer editorRef = ref.Cast ();
editorRef->SetInput(input);
}
else
{
editor->SetInput(input);
}
//navigationHistory.markEditor(editor);
}
IEditorPart::Pointer WorkbenchPage::OpenEditor(IEditorInput::Pointer input,
const std::string& editorID)
{
return this->OpenEditor(input, editorID, true, MATCH_INPUT);
}
IEditorPart::Pointer WorkbenchPage::OpenEditor(IEditorInput::Pointer input,
const std::string& editorID, bool activate)
{
return this->OpenEditor(input, editorID, activate, MATCH_INPUT);
}
IEditorPart::Pointer WorkbenchPage::OpenEditor(
const IEditorInput::Pointer input, const std::string& editorID,
bool activate, int matchFlags)
{
return this->OpenEditor(input, editorID, activate, matchFlags,
IMemento::Pointer(0));
}
IEditorPart::Pointer WorkbenchPage::OpenEditor(
const IEditorInput::Pointer input, const std::string& editorID,
bool activate, int matchFlags, IMemento::Pointer editorState)
{
if (input == 0 || editorID == "")
{
throw Poco::InvalidArgumentException();
}
// BusyIndicator.showWhile(window.getWorkbench().getDisplay(),
// new Runnable()
// {
// public void WorkbenchPage::run()
// {
return this->BusyOpenEditor(input, editorID, activate, matchFlags,
editorState);
}
IEditorPart::Pointer WorkbenchPage::OpenEditorFromDescriptor(
IEditorInput::Pointer input, IEditorDescriptor::Pointer editorDescriptor,
bool activate, IMemento::Pointer editorState)
{
if (input == 0 || !(editorDescriptor.Cast () != 0))
{
throw Poco::InvalidArgumentException();
}
// BusyIndicator.showWhile(window.getWorkbench().getDisplay(),
// new Runnable()
// {
// public void WorkbenchPage::run()
// {
return this->BusyOpenEditorFromDescriptor(input, editorDescriptor.Cast<
EditorDescriptor> (), activate, editorState);
// }
// });
}
IEditorPart::Pointer WorkbenchPage::BusyOpenEditor(IEditorInput::Pointer input,
const std::string& editorID, bool activate, int matchFlags,
IMemento::Pointer editorState)
{
Workbench* workbench =
this->GetWorkbenchWindow().Cast ()->GetWorkbenchImpl();
workbench->LargeUpdateStart();
IEditorPart::Pointer result;
try
{
result = this->BusyOpenEditorBatched(input, editorID, activate, matchFlags,
editorState);
} catch (std::exception& e)
{
workbench->LargeUpdateEnd();
throw e;
}
workbench->LargeUpdateEnd();
return result;
}
IEditorPart::Pointer WorkbenchPage::BusyOpenEditorFromDescriptor(
IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor,
bool activate, IMemento::Pointer editorState)
{
Workbench* workbench =
this->GetWorkbenchWindow().Cast ()->GetWorkbenchImpl();
workbench->LargeUpdateStart();
IEditorPart::Pointer result;
try
{
result = this->BusyOpenEditorFromDescriptorBatched(input, editorDescriptor,
activate, editorState);
} catch (std::exception& e)
{
workbench->LargeUpdateEnd();
throw e;
}
workbench->LargeUpdateEnd();
return result;
}
IEditorPart::Pointer WorkbenchPage::BusyOpenEditorBatched(
IEditorInput::Pointer input, const std::string& editorID, bool activate,
int matchFlags, IMemento::Pointer editorState)
{
// If an editor already exists for the input, use it.
IEditorPart::Pointer editor;
// Reuse an existing open editor, unless we are in "new editor tab management" mode
editor = this->GetEditorManager()->FindEditor(editorID, input, matchFlags);
if (editor != 0)
{
if (IEditorRegistry::SYSTEM_EXTERNAL_EDITOR_ID == editorID)
{
if (editor->IsDirty())
{
std::vector dlgLabels;
dlgLabels.push_back("Yes");
dlgLabels.push_back("No");
dlgLabels.push_back("Cancel");
IDialog::Pointer
dialog =
MessageDialog::CreateMessageDialog(
this->GetWorkbenchWindow()->GetShell(),
"Save",
(void*) 0, // accept the default window icon
"\"" + input->GetName()
+ "\" is opened and has unsaved changes. Do you want to save it?",
IDialog::QUESTION, dlgLabels, 0);
int saveFile = dialog->Open();
if (saveFile == 0)
{
// try
// {
IEditorPart::Pointer editorToSave = editor;
// getWorkbenchWindow().run(false, false,
// new IRunnableWithProgress()
// {
// public void WorkbenchPage::run(IProgressMonitor monitor)
// throws InvocationTargetException,
// InterruptedException
// {
//TODO progress monitor
editorToSave->DoSave();//monitor);
// }
// });
// }
// catch (InvocationTargetException& e)
// {
// throw(RuntimeException) e->GetTargetException();
// }
// catch (InterruptedException& e)
// {
// return 0;
// }
}
else if (saveFile == 2)
{
return IEditorPart::Pointer(0);
}
}
}
else
{
// // do the IShowEditorInput notification before showing the editor
// // to reduce flicker
// if (editor.Cast () != 0)
// {
// ((IShowEditorInput) editor).showEditorInput(input);
// }
this->ShowEditor(activate, editor);
return editor;
}
}
// Otherwise, create a new one. This may cause the new editor to
// become the visible (i.e top) editor.
IEditorReference::Pointer ref = this->GetEditorManager()->OpenEditor(
editorID, input, true, editorState);
if (ref != 0)
{
editor = ref->GetEditor(true);
}
if (editor != 0)
{
this->SetEditorAreaVisible(true);
if (activate)
{
this->Activate(editor);
}
else
{
this->BringToTop(editor);
}
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref,
CHANGE_EDITOR_OPEN);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_OPEN);
}
return editor;
}
/*
* Added to fix Bug 178235 [EditorMgmt] DBCS 3.3 - Cannot open file with external program.
* See openEditorFromDescriptor().
*/
IEditorPart::Pointer WorkbenchPage::BusyOpenEditorFromDescriptorBatched(
IEditorInput::Pointer input, EditorDescriptor::Pointer editorDescriptor,
bool activate, IMemento::Pointer editorState)
{
IEditorPart::Pointer editor;
// Create a new one. This may cause the new editor to
// become the visible (i.e top) editor.
IEditorReference::Pointer ref;
ref = this->GetEditorManager()->OpenEditorFromDescriptor(editorDescriptor,
input, editorState);
if (ref != 0)
{
editor = ref->GetEditor(true);
}
if (editor != 0)
{
this->SetEditorAreaVisible(true);
if (activate)
{
this->Activate(editor);
}
else
{
this->BringToTop(editor);
}
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref,
CHANGE_EDITOR_OPEN);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_OPEN);
}
return editor;
}
void WorkbenchPage::OpenEmptyTab()
{
IEditorPart::Pointer editor;
EditorReference::Pointer ref;
ref = this->GetEditorManager()->OpenEmptyTab().Cast ();
if (ref != 0)
{
editor
= ref->GetEmptyEditor(
dynamic_cast (WorkbenchPlugin::GetDefault()->GetEditorRegistry())->FindEditor(
EditorRegistry::EMPTY_EDITOR_ID).Cast ());
}
if (editor != 0)
{
this->SetEditorAreaVisible(true);
this->Activate(editor);
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(), ref,
CHANGE_EDITOR_OPEN);
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_OPEN);
}
}
void WorkbenchPage::ShowEditor(bool activate, IEditorPart::Pointer editor)
{
this->SetEditorAreaVisible(true);
if (activate)
{
//zoomOutIfNecessary(editor);
this->Activate(editor);
}
else
{
this->BringToTop(editor);
}
}
bool WorkbenchPage::IsEditorPinned(IEditorPart::Pointer editor)
{
WorkbenchPartReference::Pointer ref = this->GetReference(editor).Cast<
WorkbenchPartReference> ();
return ref != 0 && ref->IsPinned();
}
/**
* Removes an IPartListener from the part service.
*/
void WorkbenchPage::RemovePartListener(IPartListener::Pointer l)
{
partList->GetPartService()->RemovePartListener(l);
}
/**
* Implements IWorkbenchPage
*
* @see org.blueberry.ui.IWorkbenchPage#removePropertyChangeListener(IPropertyChangeListener)
* @since 2.0
* @deprecated individual views should store a working set if needed and
* register a property change listener directly with the
* working set manager to receive notification when the view
* working set is removed.
*/
// void WorkbenchPage::RemovePropertyChangeListener(IPropertyChangeListener listener) {
// propertyChangeListeners.remove(listener);
// }
void WorkbenchPage::RemoveSelectionListener(
ISelectionListener::Pointer listener)
{
selectionService->RemoveSelectionListener(listener);
}
void WorkbenchPage::RemoveSelectionListener(const std::string& partId,
ISelectionListener::Pointer listener)
{
selectionService->RemoveSelectionListener(partId, listener);
}
void WorkbenchPage::RemovePostSelectionListener(
ISelectionListener::Pointer listener)
{
selectionService->RemovePostSelectionListener(listener);
}
void WorkbenchPage::RemovePostSelectionListener(const std::string& partId,
ISelectionListener::Pointer listener)
{
selectionService->RemovePostSelectionListener(partId, listener);
}
void WorkbenchPage::RequestActivation(IWorkbenchPart::Pointer part)
{
// Sanity check.
if (!this->CertifyPart(part))
{
return;
}
// Real work.
this->SetActivePart(part);
}
/**
* Resets the layout for the perspective. The active part in the old layout
* is activated in the new layout for consistent user context.
*/
void WorkbenchPage::ResetPerspective()
{
// Run op in busy cursor.
// Use set redraw to eliminate the "flash" that can occur in the
// coolbar as the perspective is reset.
// ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
// try
// {
// mgr.getControl2().setRedraw(false);
// BusyIndicator.showWhile(0, new Runnable()
// {
// public void WorkbenchPage::run()
// {
this->BusyResetPerspective();
// }
// });
// }finally
// {
// mgr.getControl2().setRedraw(true);
// }
}
bool WorkbenchPage::RestoreState(IMemento::Pointer memento,
const IPerspectiveDescriptor::Pointer activeDescriptor)
{
// StartupThreading.runWithoutExceptions(new StartupRunnable()
// {
//
// public void WorkbenchPage::runWithException() throws Throwable
// {
this->DeferUpdates(true);
// }});
try
{
// Restore working set
std::string pageName;
memento->GetString(WorkbenchConstants::TAG_LABEL, pageName);
// String label = 0; // debugging only
// if (UIStats.isDebugging(UIStats.RESTORE_WORKBENCH))
// {
// label = pageName == 0 ? "" : "::" + pageName; //$NON-NLS-1$ //$NON-NLS-2$
// }
try
{
//UIStats.start(UIStats.RESTORE_WORKBENCH, "WorkbenchPage" + label); //$NON-NLS-1$
// MultiStatus result =
// new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, NLS.bind(
// WorkbenchMessages.WorkbenchPage_unableToRestorePerspective,
// pageName), 0);
bool result = true;
// String workingSetName = memento .getString(
// IWorkbenchConstants.TAG_WORKING_SET);
// if (workingSetName != 0)
// {
// AbstractWorkingSetManager
// workingSetManager =
// (AbstractWorkingSetManager) getWorkbenchWindow() .getWorkbench().getWorkingSetManager();
// setWorkingSet(workingSetManager.getWorkingSet(workingSetName));
// }
//
// IMemento workingSetMem = memento .getChild(
// IWorkbenchConstants.TAG_WORKING_SETS);
// if (workingSetMem != 0)
// {
// std::vector workingSetChildren =
// workingSetMem .getChildren(IWorkbenchConstants.TAG_WORKING_SET);
// List workingSetList = new ArrayList(workingSetChildren.length);
// for (int i = 0; i < workingSetChildren.length; i++)
// {
// IWorkingSet
// set =
// getWorkbenchWindow().getWorkbench() .getWorkingSetManager().getWorkingSet(
// workingSetChildren[i].getID());
// if (set != 0)
// {
// workingSetList.add(set);
// }
// }
//
// workingSets = (IWorkingSet[]) workingSetList .toArray(
// new IWorkingSet[workingSetList.size()]);
// }
//
// aggregateWorkingSetId = memento.getString(ATT_AGGREGATE_WORKING_SET_ID);
//
// IWorkingSet setWithId =
// window.getWorkbench().getWorkingSetManager().getWorkingSet(
// aggregateWorkingSetId);
//
// // check to see if the set has already been made and assign it if it has
// if (setWithId.Cast () != 0)
// {
// aggregateWorkingSet = (AggregateWorkingSet) setWithId;
// }
// Restore editor manager.
IMemento::Pointer childMem = memento->GetChild(
WorkbenchConstants::TAG_EDITORS);
//result.merge(getEditorManager().restoreState(childMem));
result &= this->GetEditorManager()->RestoreState(childMem);
childMem = memento->GetChild(WorkbenchConstants::TAG_VIEWS);
if (childMem)
{
//result.merge(getViewFactory().restoreState(childMem));
result &= this->GetViewFactory()->RestoreState(childMem);
}
// Get persp block.
childMem = memento->GetChild(WorkbenchConstants::TAG_PERSPECTIVES);
std::string activePartID;
childMem->GetString(WorkbenchConstants::TAG_ACTIVE_PART, activePartID);
std::string activePartSecondaryID;
if (!activePartID.empty())
{
activePartSecondaryID = ViewFactory::ExtractSecondaryId(activePartID);
if (!activePartSecondaryID.empty())
{
activePartID = ViewFactory::ExtractPrimaryId(activePartID);
}
}
std::string activePerspectiveID;
childMem->GetString(WorkbenchConstants::TAG_ACTIVE_PERSPECTIVE,
activePerspectiveID);
// Restore perspectives.
std::vector perspMems(childMem->GetChildren(
WorkbenchConstants::TAG_PERSPECTIVE));
Perspective::Pointer activePerspective;
for (std::size_t i = 0; i < perspMems.size(); i++)
{
IMemento::Pointer current = perspMems[i];
// StartupThreading
// .runWithoutExceptions(new StartupRunnable()
// {
//
// public void WorkbenchPage::runWithException() throws Throwable
// {
Perspective::Pointer persp(new Perspective(
PerspectiveDescriptor::Pointer(0), WorkbenchPage::Pointer(this)));
//result.merge(persp.restoreState(current));
result &= persp->RestoreState(current);
IPerspectiveDescriptor::Pointer desc = persp->GetDesc();
if (desc == activeDescriptor)
{
activePerspective = persp;
}
else if ((activePerspective == 0) && desc->GetId()
== activePerspectiveID)
{
activePerspective = persp;
}
perspList.Add(persp);
window->FirePerspectiveOpened(WorkbenchPage::Pointer(this), desc);
// }
// });
}
bool restoreActivePerspective = false;
if (!activeDescriptor)
{
restoreActivePerspective = true;
}
else if (activePerspective && activePerspective->GetDesc()
== activeDescriptor)
{
restoreActivePerspective = true;
}
else
{
restoreActivePerspective = false;
activePerspective = this->CreatePerspective(activeDescriptor.Cast<
PerspectiveDescriptor> (), true);
if (activePerspective == 0)
{
// result .merge(
// new Status(IStatus.ERR, PlatformUI.PLUGIN_ID, 0, NLS.bind(
// WorkbenchMessages.Workbench_showPerspectiveError,
// activeDescriptor.getId()), 0));
result &= false;
}
}
perspList.SetActive(activePerspective);
// Make sure we have a valid perspective to work with,
// otherwise return.
activePerspective = perspList.GetActive();
if (activePerspective == 0)
{
activePerspective = perspList.GetNextActive();
perspList.SetActive(activePerspective);
}
if (activePerspective && restoreActivePerspective)
{
//result.merge(activePerspective.restoreState());
result &= activePerspective->RestoreState();
}
if (activePerspective)
{
Perspective::Pointer myPerspective = activePerspective;
std::string myActivePartId = activePartID;
std::string mySecondaryId = activePartSecondaryID;
// StartupThreading.runWithoutExceptions(new StartupRunnable()
// {
//
// public void WorkbenchPage::runWithException() throws Throwable
// {
window->FirePerspectiveActivated(WorkbenchPage::Pointer(this),
myPerspective->GetDesc());
// Restore active part.
if (!myActivePartId.empty())
{
IWorkbenchPartReference::Pointer ref = myPerspective->FindView(
myActivePartId, mySecondaryId);
if (ref)
{
activationList->SetActive(ref);
}
}
// }});
}
// childMem = memento->GetChild(WorkbenchConstants::TAG_NAVIGATION_HISTORY);
// if (childMem)
// {
// navigationHistory.restoreState(childMem);
// }
// else if (GetActiveEditor())
// {
// navigationHistory.markEditor(getActiveEditor());
// }
//
// restore sticky view state
stickyViewMan->Restore(memento);
// std::string blame = activeDescriptor == 0 ? pageName
// : activeDescriptor.getId();
// UIStats.end(UIStats.RESTORE_WORKBENCH, blame, "WorkbenchPage" + label); //$NON-NLS-1$
// StartupThreading.runWithoutExceptions(new StartupRunnable()
// {
// public void WorkbenchPage::runWithException() throws Throwable
// {
DeferUpdates(false);
// }
// });
return result;
} catch (...)
{
// std::string blame = activeDescriptor == 0 ? pageName
// : activeDescriptor.getId();
// UIStats.end(UIStats.RESTORE_WORKBENCH, blame, "WorkbenchPage" + label); //$NON-NLS-1$
throw ;
}
}
catch (...)
{
// StartupThreading.runWithoutExceptions(new StartupRunnable()
// {
// public void WorkbenchPage::runWithException() throws Throwable
// {
DeferUpdates(false);
// }
// });
throw;
}
}
bool WorkbenchPage::SaveAllEditors(bool confirm)
{
return this->SaveAllEditors(confirm, false);
}
bool WorkbenchPage::SaveAllEditors(bool confirm, bool addNonPartSources)
{
return this->GetEditorManager()->SaveAll(confirm, false, addNonPartSources);
}
bool WorkbenchPage::SavePart(ISaveablePart::Pointer saveable,
IWorkbenchPart::Pointer part, bool confirm)
{
// Do not certify part do allow editors inside a multipageeditor to
// call this.
return this->GetEditorManager()->SavePart(saveable, part, confirm);
}
bool WorkbenchPage::SaveEditor(IEditorPart::Pointer editor, bool confirm)
{
return this->SavePart(editor, editor, confirm);
}
/**
* Saves the current perspective.
*/
void WorkbenchPage::SavePerspective()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return;
}
// // Always unzoom.
// if (isZoomed())
// {
// zoomOut();
// }
persp->SaveDesc();
}
/**
* Saves the perspective.
*/
void WorkbenchPage::SavePerspectiveAs(IPerspectiveDescriptor::Pointer newDesc)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return;
}
IPerspectiveDescriptor::Pointer oldDesc = persp->GetDesc();
// // Always unzoom.
// if (isZoomed())
// {
// zoomOut();
// }
persp->SaveDescAs(newDesc);
window->FirePerspectiveSavedAs(IWorkbenchPage::Pointer(this), oldDesc, newDesc);
}
/**
* Save the state of the page.
*/
bool WorkbenchPage::SaveState(IMemento::Pointer memento)
{
// // We must unzoom to get correct layout.
// if (isZoomed())
// {
// zoomOut();
// }
// MultiStatus
// result =
// new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, NLS.bind(
// WorkbenchMessages.WorkbenchPage_unableToSavePerspective,
// getLabel()), 0);
bool result = true;
// Save editor manager.
IMemento::Pointer childMem = memento->CreateChild(WorkbenchConstants::TAG_EDITORS);
//result.merge(editorMgr.saveState(childMem));
result &= editorMgr->SaveState(childMem);
childMem = memento->CreateChild(WorkbenchConstants::TAG_VIEWS);
//result.merge(getViewFactory().saveState(childMem));
result &= this->GetViewFactory()->SaveState(childMem);
// Create persp block.
childMem = memento->CreateChild(WorkbenchConstants::TAG_PERSPECTIVES);
if (this->GetPerspective())
{
childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PERSPECTIVE,
this->GetPerspective()->GetId());
}
if (this->GetActivePart() != 0)
{
if (this->GetActivePart().Cast ())
{
IViewReference::Pointer ref = this->GetReference(this->GetActivePart()).Cast();
if (ref)
{
childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PART,
ViewFactory::GetKey(ref));
}
}
else
{
childMem->PutString(WorkbenchConstants::TAG_ACTIVE_PART,
this->GetActivePart()->GetSite()->GetId());
}
}
// Save each perspective in opened order
for (PerspectiveList::PerspectiveListType::iterator itr = perspList.Begin();
itr != perspList.End(); ++itr)
{
IMemento::Pointer gChildMem = childMem->CreateChild(
WorkbenchConstants::TAG_PERSPECTIVE);
//result.merge(persp.saveState(gChildMem));
result &= (*itr)->SaveState(gChildMem);
}
// // Save working set if set
// if (workingSet != 0)
// {
// memento.putString(IWorkbenchConstants.TAG_WORKING_SET,
// workingSet .getName());
// }
//
// IMemento workingSetMem = memento .createChild(
// IWorkbenchConstants.TAG_WORKING_SETS);
// for (int i = 0; i < workingSets.length; i++)
// {
// workingSetMem.createChild(IWorkbenchConstants.TAG_WORKING_SET,
// workingSets[i].getName());
// }
//
// if (aggregateWorkingSetId != 0)
// {
// memento.putString(ATT_AGGREGATE_WORKING_SET_ID, aggregateWorkingSetId);
// }
//
// navigationHistory.saveState(memento .createChild(
// IWorkbenchConstants.TAG_NAVIGATION_HISTORY));
//
// save the sticky activation state
stickyViewMan->Save(memento);
return result;
}
std::string WorkbenchPage::GetId(IWorkbenchPart::Pointer part)
{
return this->GetId(this->GetReference(part));
}
std::string WorkbenchPage::GetId(IWorkbenchPartReference::Pointer ref)
{
if (ref == 0)
{
return "0"; //$NON-NLS-1$
}
return ref->GetId();
}
void WorkbenchPage::SetActivePart(IWorkbenchPart::Pointer newPart)
{
// Optimize it.
if (this->GetActivePart() == newPart)
{
return;
}
if (partBeingActivated != 0)
{
if (partBeingActivated->GetPart(false) != newPart)
{
WorkbenchPlugin::Log(Poco::RuntimeException(
"WARNING: Prevented recursive attempt to activate part "
+ this->GetId(newPart)
+ " while still in the middle of activating part " + this->GetId(
partBeingActivated)));
}
return;
}
//No need to change the history if the active editor is becoming the
// active part
// String label = 0; // debugging only
// if (UIStats.isDebugging(UIStats.ACTIVATE_PART))
// {
// label = newPart != 0 ? newPart.getTitle() : "none"; //$NON-NLS-1$
// }
try
{
IWorkbenchPartReference::Pointer partref = this->GetReference(newPart);
IWorkbenchPartReference::Pointer realPartRef;
if (newPart != 0)
{
IWorkbenchPartSite::Pointer site = newPart->GetSite();
if (site.Cast () != 0)
{
realPartRef = site.Cast ()->GetPane()->GetPartReference();
}
}
partBeingActivated = realPartRef;
//UIStats.start(UIStats.ACTIVATE_PART, label);
// Notify perspective. It may deactivate fast view.
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
persp->PartActivated(newPart);
}
// Deactivate old part
IWorkbenchPart::Pointer oldPart = this->GetActivePart();
if (oldPart != 0)
{
this->DeactivatePart(oldPart);
}
// Set active part.
if (newPart != 0)
{
activationList->SetActive(newPart);
if (newPart.Cast () != 0)
{
this->MakeActiveEditor(realPartRef.Cast ());
}
}
this->ActivatePart(newPart);
actionSwitcher.UpdateActivePart(newPart);
partList->SetActivePart(partref);
}
catch (std::exception& e)
{
partBeingActivated = 0;
// Object blame = newPart == 0 ? (Object) this : newPart;
// UIStats.end(UIStats.ACTIVATE_PART, blame, label);
throw e;
}
partBeingActivated = 0;
}
void WorkbenchPage::SetEditorAreaVisible(bool showEditorArea)
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return;
}
if (showEditorArea == persp->IsEditorAreaVisible())
{
return;
}
// // If parts change always update zoom.
// if (isZoomed())
// {
// zoomOut();
// }
// Update editor area visibility.
IWorkbenchPage::Pointer thisPage(this);
if (showEditorArea)
{
persp->ShowEditorArea();
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_AREA_SHOW);
}
else
{
persp->HideEditorArea();
this->UpdateActivePart();
window->FirePerspectiveChanged(thisPage, this->GetPerspective(),
CHANGE_EDITOR_AREA_HIDE);
}
}
/**
* Sets the layout of the page. Assumes the new perspective is not 0.
* Keeps the active part if possible. Updates the window menubar and
* toolbar if necessary.
*/
void WorkbenchPage::SetPerspective(Perspective::Pointer newPersp)
{
// Don't do anything if already active layout
Perspective::Pointer oldPersp = this->GetActivePerspective();
if (oldPersp == newPersp)
{
return;
}
window->LargeUpdateStart();
std::exception exc;
bool exceptionOccured = false;
try
{
IWorkbenchPage::Pointer thisPage(this);
if (oldPersp != 0)
{
// fire the pre-deactivate
window->FirePerspectivePreDeactivate(thisPage, oldPersp->GetDesc());
}
if (newPersp != 0)
{
bool status = newPersp->RestoreState();
if (!status)
{
std::string title = "Restoring problems";
std::string msg = "Unable to read workbench state.";
MessageDialog::OpenError(this->GetWorkbenchWindow()->GetShell(), title,
msg);
}
}
// Deactivate the old layout
if (oldPersp != 0)
{
oldPersp->OnDeactivate();
// Notify listeners of deactivation
window->FirePerspectiveDeactivated(thisPage, oldPersp->GetDesc());
}
// Activate the new layout
perspList.SetActive(newPersp);
if (newPersp != 0)
{
newPersp->OnActivate();
// Notify listeners of activation
window->FirePerspectiveActivated(thisPage, newPersp->GetDesc());
}
this->UpdateVisibility(oldPersp, newPersp);
// Update the window
//TODO action sets
//window->UpdateActionSets();
// Update sticky views
stickyViewMan->Update(oldPersp, newPersp);
}
catch (std::exception& e)
{
exc = e;
exceptionOccured = true;
}
window->LargeUpdateEnd();
if (newPersp == 0)
{
return;
}
IPerspectiveDescriptor::Pointer desc = newPersp->GetDesc();
if (desc == 0)
{
return;
}
if (dirtyPerspectives.erase(desc->GetId()))
{
this->SuggestReset();
}
if (exceptionOccured)
throw exc;
}
void WorkbenchPage::UpdateVisibility(Perspective::Pointer oldPersp,
Perspective::Pointer newPersp)
{
// Flag all parts in the old perspective
std::vector oldRefs;
if (oldPersp != 0)
{
oldRefs = oldPersp->GetViewReferences();
for (unsigned int i = 0; i < oldRefs.size(); i++)
{
PartPane::Pointer pane =
oldRefs[i].Cast ()->GetPane();
pane->SetInLayout(false);
}
}
PerspectiveHelper* pres = 0;
// Make parts in the new perspective visible
if (newPersp != 0)
{
pres = newPersp->GetPresentation();
std::vector newRefs =
newPersp->GetViewReferences();
for (unsigned int i = 0; i < newRefs.size(); i++)
{
WorkbenchPartReference::Pointer ref = newRefs[i].Cast<
WorkbenchPartReference> ();
PartPane::Pointer pane = ref->GetPane();
if (pres->IsPartVisible(ref))
{
activationList->BringToTop(ref);
}
pane->SetInLayout(true);
}
}
this->UpdateActivePart();
// Hide any parts in the old perspective that are no longer visible
for (unsigned int i = 0; i < oldRefs.size(); i++)
{
WorkbenchPartReference::Pointer ref = oldRefs[i].Cast<
WorkbenchPartReference> ();
PartPane::Pointer pane = ref->GetPane();
if (pres == 0 || !pres->IsPartVisible(ref))
{
pane->SetVisible(false);
}
}
}
/**
* Sets the perspective.
*
* @param desc
* identifies the new perspective.
*/
void WorkbenchPage::SetPerspective(IPerspectiveDescriptor::Pointer desc)
{
if (this->GetPerspective() == desc)
{
return;
}
// // Going from multiple to single rows can make the coolbar
// // and its adjacent views appear jumpy as perspectives are
// // switched. Turn off redraw to help with this.
// ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
std::exception exc;
bool exceptionOccured = false;
try
{
//mgr.getControl2().setRedraw(false);
//getClientComposite().setRedraw(false);
// Run op in busy cursor.
// BusyIndicator.showWhile(0, new Runnable()
// {
// public void WorkbenchPage::run()
// {
this->BusySetPerspective(desc);
// }
// });
}
catch (std::exception& e)
{
exc = e;
exceptionOccured = true;
}
// getClientComposite().setRedraw(true);
// mgr.getControl2().setRedraw(true);
IWorkbenchPart::Pointer part = this->GetActivePart();
if (part != 0)
{
part->SetFocus();
}
if (exceptionOccured)
throw exc;
}
PartService* WorkbenchPage::GetPartService()
{
return dynamic_cast (partList->GetPartService());
}
void WorkbenchPage::ResetToolBarLayout()
{
// ICoolBarManager2 mgr = (ICoolBarManager2) window.getCoolBarManager2();
// mgr.resetItemOrder();
}
IViewPart::Pointer WorkbenchPage::ShowView(const std::string& viewID)
{
return this->ShowView(viewID, "", VIEW_ACTIVATE);
}
IViewPart::Pointer WorkbenchPage::ShowView(const std::string& viewID,
const std::string& secondaryID, int mode)
{
if (secondaryID != "")
{
if (secondaryID.size() == 0 || secondaryID.find_first_of(
ViewFactory::ID_SEP) != std::string::npos)
{
throw Poco::InvalidArgumentException(
"Illegal secondary id (cannot be empty or contain a colon)");
}
}
if (!this->CertifyMode(mode))
{
throw Poco::InvalidArgumentException("Illegal view mode");
}
// Run op in busy cursor.
// BusyIndicator.showWhile(0, new Runnable()
// {
// public void WorkbenchPage::run()
// {
// try
// {
return this->BusyShowView(viewID, secondaryID, mode);
// } catch (PartInitException& e)
// {
// result = e;
// }
// }
// });
}
bool WorkbenchPage::CertifyMode(int mode)
{
if (mode == VIEW_ACTIVATE || mode == VIEW_VISIBLE || mode == VIEW_CREATE)
return true;
return false;
}
std::vector WorkbenchPage::GetSortedEditors()
{
return activationList->GetEditors();
}
std::vector WorkbenchPage::GetOpenPerspectives()
{
std::list opened = perspList.GetOpenedPerspectives();
std::vector result;
for (std::list::iterator iter = opened.begin(); iter
!= opened.end(); ++iter)
{
result.push_back((*iter)->GetDesc());
}
return result;
}
std::list WorkbenchPage::GetOpenInternalPerspectives()
{
return perspList.GetOpenedPerspectives();
}
Perspective::Pointer WorkbenchPage::GetFirstPerspectiveWithView(
IViewPart::Pointer part)
{
std::list perspectives =
perspList.GetSortedPerspectives();
for (std::list::reverse_iterator iter =
perspectives.rbegin(); iter != perspectives.rend(); ++iter)
{
if ((*iter)->ContainsView(part))
{
return *iter;
}
}
// we should never get here
return Perspective::Pointer(0);
}
std::vector WorkbenchPage::GetSortedPerspectives()
{
std::list sortedArray =
perspList.GetSortedPerspectives();
std::vector result;
for (std::list::iterator iter = sortedArray.begin();
iter != sortedArray.end(); ++iter)
{
result.push_back((*iter)->GetDesc());
}
return result;
}
std::vector WorkbenchPage::GetSortedParts()
{
//return partList->GetParts(this->GetViewReferences());
return activationList->GetParts();
}
IWorkbenchPartReference::Pointer WorkbenchPage::GetReference(
IWorkbenchPart::Pointer part)
{
if (part == 0)
{
return IWorkbenchPartReference::Pointer(0);
}
IWorkbenchPartSite::Pointer site = part->GetSite();
if (site.Cast () == 0)
{
return IWorkbenchPartReference::Pointer(0);
}
PartSite::Pointer partSite = site.Cast ();
PartPane::Pointer pane = partSite->GetPane();
return partSite->GetPartReference();
}
// for dynamic UI
void WorkbenchPage::AddPerspective(Perspective::Pointer persp)
{
perspList.Add(persp);
IWorkbenchPage::Pointer thisPage(this);
window->FirePerspectiveOpened(thisPage, persp->GetDesc());
}
std::vector WorkbenchPage::GetViewReferenceStack(
IViewPart::Pointer part)
{
// Sanity check.
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0 || !this->CertifyPart(part))
{
return std::vector();
}
ILayoutContainer::Pointer container =
part->GetSite().Cast ()->GetPane()->GetContainer();
if (container.Cast () != 0)
{
PartStack::Pointer folder = container.Cast ();
std::vector list;
ILayoutContainer::ChildrenType children = folder->GetChildren();
for (ILayoutContainer::ChildrenType::iterator childIter =
children.begin(); childIter != children.end(); ++childIter)
{
LayoutPart::Pointer stackablePart = *childIter;
if (stackablePart.Cast () != 0)
{
IViewReference::Pointer view =
stackablePart.Cast ()->GetPartReference().Cast<
IViewReference> ();
if (view != 0)
{
list.push_back(view);
}
}
}
// sort the list by activation order (most recently activated first)
std::sort(list.begin(), list.end(), ActivationOrderPred(activationList));
return list;
}
std::vector result;
result.push_back(this->GetReference(part).Cast ());
return result;
}
std::vector WorkbenchPage::GetViewStack(
IViewPart::Pointer part)
{
std::vector refStack = this->GetViewReferenceStack(
part);
std::vector result;
for (unsigned int i = 0; i < refStack.size(); i++)
{
IViewPart::Pointer next = refStack[i]->GetView(false);
if (next != 0)
{
result.push_back(next);
}
}
return result;
}
void WorkbenchPage::ResizeView(IViewPart::Pointer part, int width, int height)
{
SashInfo sashInfo;
PartPane::Pointer pane = part->GetSite().Cast ()->GetPane();
ILayoutContainer::Pointer container = pane->GetContainer();
LayoutTree::Pointer tree =
this->GetPerspectivePresentation()->GetLayout()->GetLayoutTree()->Find(
container.Cast ());
// retrieve our layout sashes from the layout tree
this->FindSashParts(tree, pane->FindSashes(), sashInfo);
// first set the width
int deltaWidth = width - pane->GetBounds().width;
if (sashInfo.right != 0)
{
Rectangle rightBounds = sashInfo.rightNode->GetBounds();
// set the new ratio
sashInfo.right->SetRatio(static_cast((deltaWidth + sashInfo.right->GetBounds().x)
- rightBounds.x) / rightBounds.width);
// complete the resize
sashInfo.rightNode->SetBounds(rightBounds);
}
else if (sashInfo.left != 0)
{
Rectangle leftBounds = sashInfo.leftNode->GetBounds();
// set the ratio
sashInfo.left->SetRatio(static_cast((sashInfo.left->GetBounds().x - deltaWidth)
- leftBounds.x) / leftBounds.width);
// complete the resize
sashInfo.leftNode->SetBounds(sashInfo.leftNode->GetBounds());
}
// next set the height
int deltaHeight = height - pane->GetBounds().height;
if (sashInfo.bottom != 0)
{
Rectangle bottomBounds = sashInfo.bottomNode->GetBounds();
// set the new ratio
sashInfo.bottom->SetRatio(static_cast((deltaHeight + sashInfo.bottom->GetBounds().y)
- bottomBounds.y) / bottomBounds.height);
// complete the resize
sashInfo.bottomNode->SetBounds(bottomBounds);
}
else if (sashInfo.top != 0)
{
Rectangle topBounds = sashInfo.topNode->GetBounds();
// set the ratio
sashInfo.top->SetRatio(static_cast((sashInfo.top->GetBounds().y - deltaHeight)
- topBounds.y) / topBounds.height);
// complete the resize
sashInfo.topNode->SetBounds(topBounds);
}
}
void WorkbenchPage::FindSashParts(LayoutTree::Pointer tree,
const PartPane::Sashes& sashes, SashInfo& info)
{
LayoutTree::Pointer parent(tree->GetParent());
if (parent == 0)
{
return;
}
if (parent->part.Cast () != 0)
{
// get the layout part sash from this tree node
LayoutPartSash::Pointer sash = parent->part.Cast ();
// make sure it has a sash control
void* control = sash->GetControl();
if (control != 0)
{
// check for a vertical sash
if (sash->IsVertical())
{
if (sashes.left == control)
{
info.left = sash;
info.leftNode = parent->FindSash(sash);
}
else if (sashes.right == control)
{
info.right = sash;
info.rightNode = parent->FindSash(sash);
}
}
// check for a horizontal sash
else
{
if (sashes.top == control)
{
info.top = sash;
info.topNode = parent->FindSash(sash);
}
else if (sashes.bottom == control)
{
info.bottom = sash;
info.bottomNode = parent->FindSash(sash);
}
}
}
}
// recursive call to continue up the tree
this->FindSashParts(parent, sashes, info);
}
std::vector WorkbenchPage::GetAllParts()
{
std::vector views = viewFactory->GetViews();
std::list editors = this->GetEditorReferences();
std::vector result;
for (unsigned int i = 0; i < views.size(); i++)
{
result.push_back(views[i]);
}
for (std::list::iterator iter = editors.begin(); iter
!= editors.end(); ++iter)
{
result.push_back(*iter);
}
return result;
}
std::vector WorkbenchPage::GetOpenParts()
{
std::vector refs = this->GetAllParts();
std::vector result;
for (unsigned int i = 0; i < refs.size(); i++)
{
IWorkbenchPartReference::Pointer reference = refs[i];
IWorkbenchPart::Pointer part = reference->GetPart(false);
if (part != 0)
{
result.push_back(reference);
}
}
return result;
}
void WorkbenchPage::TestInvariants()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp != 0)
{
persp->TestInvariants();
// When we have widgets, ensure that there is no situation where the editor area is visible
// and the perspective doesn't want an editor area.
if (this->GetClientComposite()
&& editorPresentation->GetLayoutPart()->IsVisible())
{
poco_assert(persp->IsEditorAreaVisible());
}
}
}
/* (non-Javadoc)
* @see org.blueberry.ui.IWorkbenchPage#getExtensionTracker()
*/
// IExtensionTracker WorkbenchPage::GetExtensionTracker()
// {
// if (tracker == 0)
// {
// tracker = new UIExtensionTracker(getWorkbenchWindow().getWorkbench().getDisplay());
// }
// return tracker;
// }
/*
* (non-Javadoc)
*
* @see org.blueberry.ui.IWorkbenchPage#getPerspectiveShortcuts()
*/
std::vector WorkbenchPage::GetPerspectiveShortcuts()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return std::vector();
}
return persp->GetPerspectiveShortcuts();
}
std::vector WorkbenchPage::GetShowViewShortcuts()
{
Perspective::Pointer persp = this->GetActivePerspective();
if (persp == 0)
{
return std::vector();
}
return persp->GetShowViewShortcuts();
}
void WorkbenchPage::SuggestReset()
{
IWorkbench* workbench = this->GetWorkbenchWindow()->GetWorkbench();
// workbench.getDisplay().asyncExec(new Runnable()
// {
// public void WorkbenchPage::run()
// {
Shell::Pointer parentShell;
IWorkbenchWindow::Pointer window = workbench->GetActiveWorkbenchWindow();
if (window == 0)
{
if (workbench->GetWorkbenchWindowCount() == 0)
{
return;
}
window = workbench->GetWorkbenchWindows()[0];
}
parentShell = window->GetShell();
if (MessageDialog::OpenQuestion(parentShell,
"Reset Perspective?",
"Changes to installed plug-ins have affected this perspective. Would you like to reset this perspective to accept these changes?"))
{
IWorkbenchPage::Pointer page = window->GetActivePage();
if (page == 0)
{
return;
}
page->ResetPerspective();
}
// }
// });
}
bool WorkbenchPage::IsPartVisible(
IWorkbenchPartReference::Pointer reference)
{
IWorkbenchPart::Pointer part = reference->GetPart(false);
// Can't be visible if it isn't created yet
if (part == 0)
{
return false;
}
return this->IsPartVisible(part);
}
}
diff --git a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h
index a81c8d1659..5dc6c68dbe 100644
--- a/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h
+++ b/BlueBerry/Bundles/org.blueberry.ui/src/internal/berryWorkbenchPage.h
@@ -1,1786 +1,1798 @@
/*===================================================================
BlueBerry Platform
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.
See LICENSE.txt or http://www.mitk.org for details.
===================================================================*/
#ifndef BERRYWORKBENCHPAGE_H_
#define BERRYWORKBENCHPAGE_H_
#include
#include
#include "berryIWorkbenchPage.h"
#include "berryIWorkbenchPartReference.h"
#include "berryIReusableEditor.h"
#include "berryILayoutContainer.h"
#include "berryIStickyViewManager.h"
#include "berryWorkbenchPagePartList.h"
#include "berryWorkbenchPartReference.h"
#include "berryPageSelectionService.h"
#include "berryEditorManager.h"
#include "berryViewFactory.h"
#include "berryPartPane.h"
#include
namespace berry
{
//class PartPane;
//class PartPane::Sashes;
class EditorAreaHelper;
class WorkbenchWindow;
class Perspective;
class PerspectiveHelper;
class PerspectiveDescriptor;
class LayoutPartSash;
class LayoutTree;
class LayoutTreeNode;
class PartService;
/**
* \ingroup org_blueberry_ui_internal
*
* A collection of views and editors in a workbench.
*/
class BERRY_UI WorkbenchPage: public IWorkbenchPage
{
public:
berryObjectMacro(WorkbenchPage);
protected:
//TODO Weakpointer
WorkbenchWindow* window;
friend class ViewFactory;
friend class WorkbenchWindow;
friend class EditorAreaHelper;
friend class WWinPartService;
private:
/**
* Manages editor contributions and action set part associations.
*/
class ActionSwitcher
{
private:
IWorkbenchPart::WeakPtr activePart;
IEditorPart::WeakPtr topEditor;
/**
* Updates the contributions given the new part as the active part.
*
* @param newPart
* the new active part, may be null
*/
public:
void UpdateActivePart(IWorkbenchPart::Pointer newPart);
/**
* Updates the contributions given the new part as the topEditor.
*
* @param newEditor
* the new top editor, may be null
*/
public:
void UpdateTopEditor(IEditorPart::Pointer newEditor);
/**
* Activates the contributions of the given part. If enable
* is true
the contributions are visible and enabled,
* otherwise they are disabled.
*
* @param part
* the part whose contributions are to be activated
* @param enable
* true
the contributions are to be enabled,
* not just visible.
*/
private:
void ActivateContributions(IWorkbenchPart::Pointer part, bool enable);
/**
* Deactivates the contributions of the given part. If remove
* is true
the contributions are removed, otherwise they
* are disabled.
*
* @param part
* the part whose contributions are to be deactivated
* @param remove
* true
the contributions are to be removed,
* not just disabled.
*/
private:
void DeactivateContributions(IWorkbenchPart::Pointer part, bool remove);
};
class ActivationList
{
public:
//List of parts in the activation order (oldest first)
typedef std::deque PartListType;
typedef std::deque::iterator PartListIter;
typedef std::deque::reverse_iterator PartListReverseIter;
private:
PartListType parts;
WorkbenchPage* page;
public:
ActivationList(WorkbenchPage* page);
/*
* Add/Move the active part to end of the list;
*/
void SetActive(SmartPointer part);
/*
* Ensures that the given part appears AFTER any other part in the same
* container.
*/
void BringToTop(SmartPointer ref);
/*
* Returns the last (most recent) iterator (index) of the given container in the activation list, or returns
* end() if the given container does not appear in the activation list.
*/
PartListIter LastIndexOfContainer(SmartPointer container);
/*
* Add/Move the active part to end of the list;
*/
void SetActive(SmartPointer ref);
/*
* Add the active part to the beginning of the list.
*/
void Add(SmartPointer ref);
/*
* Return the active part. Filter fast views.
*/
SmartPointer GetActive();
/*
* Return the previously active part. Filter fast views.
*/
SmartPointer GetPreviouslyActive();
SmartPointer GetActiveReference(bool editorsOnly);
/*
* Retuns the index of the part within the activation list. The higher
* the index, the more recently it was used.
*/
PartListIter IndexOf(SmartPointer part);
/*
* Returns the index of the part reference within the activation list.
* The higher the index, the more recent it was used.
*/
PartListIter IndexOf(SmartPointer ref);
/*
* Remove a part from the list
*/
bool Remove(SmartPointer ref);
/*
* Returns the topmost editor on the stack, or null if none.
*/
SmartPointer GetTopEditor();
/*
* Returns the editors in activation order (oldest first).
*/
std::vector > GetEditors();
/*
* Return a list with all parts (editors and views).
*/
std::vector > GetParts();
private:
SmartPointer GetActive(PartListIter start);
SmartPointer GetActiveReference(PartListIter start, bool editorsOnly);
/*
* Find a part in the list starting from the end and filter
* and views from other perspectives. Will filter fast views
* unless 'includeActiveFastViews' is true;
*/
SmartPointer