private TabDefinition GetTabDefinition(Tab tab) { TabDefinition tabDefinition = TabDefinitionRepository.GetTabDefinition(tab.Name); if(tabDefinition == null) tabDefinition = new TabDefinition(); return tabDefinition; }
private void CreateOrDeleteTab(string tabName, bool createNew) { var obj2 = _lock; lock (obj2) { var tabDefinition = this._tabDefinitionRepository.Service.Load(tabName); if (createNew) { if (tabDefinition != null) { return; } tabDefinition = new TabDefinition { Name = tabName, SortIndex = 300, RequiredAccess = AccessLevel.Edit }; _tabDefinitionRepository.Service.Save(tabDefinition); } else if (tabDefinition != null) { _tabDefinitionRepository.Service.Delete(tabDefinition); } } }
public void GivenExistingTabThatShouldBeUpdated_UpdateTabDefinitions_UpdatesTab() { MockRepository fakes = new MockRepository(); TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.PartialMock(fakes); List <Tab> tabs = new List <Tab>(); Tab existingTab = new TestTab(); tabs.Add(existingTab); tabDefinitionUpdater.Stub(updater => updater.UpdateTabDefinition(Arg <TabDefinition> .Is.Anything, Arg <Tab> .Is.Anything)); TabDefinitionRepository fakeTabDefinitionRepository = fakes.Stub <TabDefinitionRepository>(); tabDefinitionUpdater.TabDefinitionRepository = fakeTabDefinitionRepository; TabDefinition existingTabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(existingTab); tabDefinitionUpdater.TabDefinitionRepository.Stub(factory => factory.GetTabDefinition(existingTab.Name)).Return(existingTabDefinition); tabDefinitionUpdater.TabDefinitionRepository.Stub(factory => factory.SaveTabDefinition(Arg <TabDefinition> .Is.Anything)); tabDefinitionUpdater.TabDefinitionRepository.Replay(); tabDefinitionUpdater.Stub(updater => updater.TabDefinitionShouldBeUpdated(existingTabDefinition, existingTab)).Return(true); tabDefinitionUpdater.Replay(); tabDefinitionUpdater.UpdateTabDefinitions(tabs); tabDefinitionUpdater.AssertWasCalled(updater => updater.UpdateTabDefinition(existingTabDefinition, existingTab)); tabDefinitionUpdater.TabDefinitionRepository.AssertWasCalled(factory => factory.SaveTabDefinition(existingTabDefinition)); }
private void CreateOrDeleteTab(string tabName, bool createNew) { var obj2 = _lock; lock (obj2) { TabDefinition tabDefinition = this._tabDefinitionRepository.Load(tabName); if (createNew) { if (tabDefinition != null) { return; } tabDefinition = new TabDefinition { Name = tabName, SortIndex = int.MaxValue, RequiredAccess = AccessLevel.Publish }; _tabDefinitionRepository.Save(tabDefinition); } else if (tabDefinition != null) { _tabDefinitionRepository.Delete(tabDefinition); } } }
private static TabDefinition GetExistingTabDefinition(ITabDefinitionRepository tabDefinitionRepository, TabDefinition definition) { return tabDefinitionRepository.List() .FirstOrDefault( t => t.Name.Equals(definition.Name, StringComparison.InvariantCultureIgnoreCase)); }
private XElement GetTabElement(TabDefinition definition) { var tabElement = new XElement("Tab", new XAttribute("Id", "Ribbon." + definition.Id), new XAttribute("Title", definition.Title), new XAttribute("Sequence", definition.Sequence), new XElement("Scaling", new XAttribute("Id", "Ribbon." + definition.Id + ".Scaling") ), new XElement("Groups", new XAttribute("Id", "Ribbon." + definition.Id + ".Groups") ) ); int groupIndex = 0; foreach (GroupDefinition group in definition.Groups) { groupIndex++; var groupElement = GetGroupElement(group, groupIndex, "Ribbon." + definition.Id); tabElement.Element("Scaling").AddFirst(groupElement.Element("Scaling").Element("MaxSize")); tabElement.Element("Scaling").Add(groupElement.Element("Scaling").Element("Scaling")); tabElement.Element("Groups").Add(groupElement.Element("Group")); } return(tabElement); }
/// <summary> /// Add ribbon tab to the specified page /// </summary> /// <param name="definition">Definition of the ribbon tab</param> /// <param name="page">Page, to which the definition will be added</param> /// <param name="makeInitial">if true, the ribbon tab will be active when page is loaded, otherwise the default tab (Browse) will be active</param> /// <remarks> /// <para> /// This method is intended to provide ability to add local ribbon customizations. The customizations have to be specified each time /// when the page gets loaded. To add permanent customizations, use <see cref="RibbonCustomAction"/>. /// </para> /// <para> /// This method cannot create contextual tabs, only static. /// </para> /// </remarks> /// <example> /// <para> /// Example of usage: /// </para> /// <code lang="csharp"> /// public class MyPage : LayoutsPageBase /// { /// public void Page_Load(object sender, EventArgs e) /// { /// RibbonController.Current.AddRibbonTabToPage(MyRibbonManager.MyTabDefinition, this, true); /// } /// } /// </code> /// <para> /// This will add initially active ribbon tab to the application page MyPage. /// Tab definition is supposed to be stored in some custom user class MyRibbonManager. /// </para> /// <para> /// Also its possible to use this method for adding tabs to ribbon from webparts. But you must provide different ribbon ids /// for different webparts and even for different instances of the same webpart. /// </para> /// </example> public void AddRibbonTabToPage(TabDefinition definition, Page page, bool makeInitial) { if (SPRibbon.GetCurrent(page) == null) { throw new Exception("SPRibbon.GetCurrent returned null for the specified page!"); } AddRibbonExtension(XmlGenerator.Current.GetTabXML(definition), page, "Ribbon.Tabs", makeInitial); AddGroupTemplatesRibbonExtensions(definition.GroupTemplates, page); var commands = new RibbonCommandRepository(); commands.AddCommands(definition); page.Items[CommandsKey] = commands; page.PreRenderComplete -= new EventHandler(page_PreRenderComplete); page.PreRenderComplete += new EventHandler(page_PreRenderComplete); Ribbon ribbon = SPRibbon.GetCurrent(page); ribbon.MakeTabAvailable("Ribbon." + definition.Id); if (makeInitial) { ribbon.InitialTabId = "Ribbon." + definition.Id; } }
public static TabDefinition CreateTabDefinition(Tab tab) { TabDefinition tabDefinition = new TabDefinition(); tabDefinition.Name = tab.Name; tabDefinition.RequiredAccess = tab.RequiredAccess; tabDefinition.SortIndex = tab.SortIndex; return tabDefinition; }
private static bool TabIsNotPersisted(TabDefinition tab) { if (tab != null) { return(tab.ID == -1); } return(true); }
internal string GetTabXML(TabDefinition definition) { if (definition != null) { definition.Validate(); return(new XDocument(GetTabElement(definition)).ToString()); } return(null); }
private IEnumerable<TabDefinition> MapRecordsToExposedObjects(IEnumerable<TabDefinition> internalRecords) { return internalRecords.Select(record => { var exposed = new TabDefinition(); Mapper.Map(record, exposed); return exposed; }); }
/// <summary> /// Registers custom ribbon tab for a list at specified SPWeb, replacing one of the existing tabs. /// </summary> /// <param name="tabDefinition">Definition of the ribbon tab.</param> /// <param name="oldTabId">Valid existing ribbon tab id, for tab which will be replaced. <seealso cref="T: Hemrika.SharePresence.Common.Ribbon.SPRibbonIds"/></param> public void ReplaceTab(TabDefinition tabDefinition, string oldTabId) { RibbonXML = ConcatXML(RibbonXML, XmlGenerator.Current.GetCommandUIDefinitionXML( oldTabId, XmlGenerator.Current.GetTabXML(tabDefinition))); RibbonCommandsXML = ConcatXML(RibbonCommandsXML, GetCommandsXML(tabDefinition)); }
private TabDefinition GetExistingTabDefinition(TabDefinition definition) { if (_definedTabs == null) { _definedTabs = _tabDefinitionRepository.Service.List().ToList(); } return(_definedTabs.FirstOrDefault(t => t.Name.Equals(definition.Name, StringComparison.InvariantCultureIgnoreCase))); }
/// <summary> /// Registers custom ribbon tab for a list at specified SPWeb. /// </summary> /// <param name="tabDefinition">Definition of the ribbon tab.</param> public void AddTab(TabDefinition tabDefinition) { RibbonXML = ConcatXML(RibbonXML, XmlGenerator.Current.GetCommandUIDefinitionXML( "Ribbon.Tabs._children", XmlGenerator.Current.GetTabXML(tabDefinition))); RibbonCommandsXML = ConcatXML(RibbonCommandsXML, GetCommandsXML(tabDefinition)); }
public static TabDefinition CreateTabDefinition(Tab tab) { TabDefinition tabDefinition = new TabDefinition(); tabDefinition.Name = tab.Name; tabDefinition.RequiredAccess = tab.RequiredAccess; tabDefinition.SortIndex = tab.SortIndex; return(tabDefinition); }
/// <summary> /// Adds custom tab to specified contextual tab group /// </summary> /// <param name="tabDefinition">Definition of the ribbon tab.</param> /// <param name="contextualGroupId">Valid existing ribbon contextual tab group id, inside which the tab will be added. <seealso cref="T: Hemrika.SharePresence.Common.Ribbon.SPRibbonIds"/></param> public void AddTabToContextualGroup(TabDefinition tabDefinition, string contextualGroupId) { RibbonXML = ConcatXML(RibbonXML, XmlGenerator.Current.GetCommandUIDefinitionXML( contextualGroupId + "._children", XmlGenerator.Current.GetTabXML(tabDefinition))); RibbonCommandsXML = ConcatXML(RibbonCommandsXML, GetCommandsXML(tabDefinition)); }
private IEnumerable <TabDefinition> MapRecordsToExposedObjects(IEnumerable <TabDefinition> internalRecords) { return(internalRecords.Select(record => { var exposed = new TabDefinition(); Mapper.Map(record, exposed); return exposed; })); }
private void AddTabToList(ITabDefinitionRepository tabDefinitionRepository, TabDefinition definition) { TabDefinition existingTab = GetExistingTabDefinition(tabDefinitionRepository, definition); if (existingTab != null) { definition.ID = existingTab.ID; } tabDefinitionRepository.Save(definition); }
private TabDefinition GetTabDefinition(Tab tab) { TabDefinition tabDefinition = TabFactory.GetTabDefinition(tab.Name); if (tabDefinition == null) { tabDefinition = new TabDefinition(); } return(tabDefinition); }
public void GivenTabDefinitionWithAllValuesEqualToTab_TabDefinitionShouldBeUpdated_ReturnsFalse() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); bool shouldBeUpdated = tabDefinitionUpdater.TabDefinitionShouldBeUpdated(tabDefinition, tab); Assert.False(shouldBeUpdated); }
protected internal virtual void UpdatePageDefinitionTab(PageDefinition pageDefinition, PageTypePropertyAttribute propertyAttribute) { TabDefinition tab = _tabFactory.List().First(); if (propertyAttribute.Tab != null) { Tab definedTab = (Tab)Activator.CreateInstance(propertyAttribute.Tab); tab = _tabFactory.GetTabDefinition(definedTab.Name); } pageDefinition.Tab = tab; }
public void GivenTabDefinitionWithDifferentName_TabDefinitionShouldBeUpdated_ReturnsTrue() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); tabDefinition.Name = TestValueUtility.CreateRandomString(); TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); bool shouldBeUpdated = tabDefinitionUpdater.TabDefinitionShouldBeUpdated(tabDefinition, tab); Assert.True(shouldBeUpdated); }
public void GivenTab_UpdateTabDefinition_UpdatesTabDefinitionsSortIndex() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); tabDefinition.SortIndex = tab.SortIndex + 1; TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); tabDefinitionUpdater.UpdateTabDefinition(tabDefinition, tab); Assert.Equal <int>(tab.SortIndex, tabDefinition.SortIndex); }
public void GivenTab_UpdateTabDefinition_UpdatesTabDefinitionsRequiredAccess() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); tabDefinition.RequiredAccess = tab.RequiredAccess + 1; TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); tabDefinitionUpdater.UpdateTabDefinition(tabDefinition, tab); Assert.Equal <AccessLevel>(tab.RequiredAccess, tabDefinition.RequiredAccess); }
public void GivenTab_UpdateTabDefinition_UpdatesTabDefinitionsName() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); tabDefinition.Name = TestValueUtility.CreateRandomString(); TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); tabDefinitionUpdater.UpdateTabDefinition(tabDefinition, tab); Assert.Equal <string>(tab.Name, tabDefinition.Name); }
private void AddTabToList(TabDefinition definition) { var existingTab = GetExistingTabDefinition(definition); if (existingTab != null) { definition.ID = existingTab.ID; } _definedTabs.Add(definition); _tabDefinitionRepository.Service.Save(definition); }
public void GivenTabDefinitionWithDifferentSortIndex_TabDefinitionShouldBeUpdated_ReturnsTrue() { Tab tab = new TestTab(); TabDefinition tabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(tab); tabDefinition.SortIndex++; TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); bool shouldBeUpdated = tabDefinitionUpdater.TabDefinitionShouldBeUpdated(tabDefinition, tab); Assert.True(shouldBeUpdated); }
public TabDefinition GetTabDefinition(string name) { var record = tabs.Where(t => t.Name == name).FirstOrDefault(); if (record == null) return null; var exposedTab = new TabDefinition(); Mapper.Map(record, exposedTab); return exposedTab; }
public virtual void UpdateTabDefinitions(IEnumerable <Tab> tabs) { foreach (Tab tab in tabs) { TabDefinition tabDefinition = GetTabDefinition(tab); if (TabDefinitionShouldBeUpdated(tabDefinition, tab)) { UpdateTabDefinition(tabDefinition, tab); TabDefinitionRepository.SaveTabDefinition(tabDefinition); } } }
protected internal virtual bool TabDefinitionShouldBeUpdated(TabDefinition tabDefinition, Tab tab) { if(tabDefinition.Name != tab.Name) return true; if (tabDefinition.RequiredAccess != tab.RequiredAccess) return true; if (tabDefinition.SortIndex != tab.SortIndex) return true; return false; }
public TabDefinition GetTabDefinition(string name) { var record = tabs.Where(t => t.Name == name).FirstOrDefault(); if (record == null) { return(null); } var exposedTab = new TabDefinition(); Mapper.Map(record, exposedTab); return(exposedTab); }
protected void btnCleanUpProperty_Click(object sender, EventArgs e) { var propertyDefinitionRes = ServiceLocator.Current.GetInstance <IPropertyDefinitionRepository>(); var propDefinitionModelRes = ServiceLocator.Current.GetInstance <ContentTypeModelRepository>(); var tabRes = ServiceLocator.Current.GetInstance <ITabDefinitionRepository>(); foreach (RepeaterItem item in repeaterUnusedProperties.Items) { var checkBox = item.FindControl("chkProperties") as CheckBox; var hiddenPropertyId = item.FindControl("hiddenPropertyId") as HiddenField; if (checkBox != null && checkBox.Checked && hiddenPropertyId != null) { var propertyId = -1; if (int.TryParse(hiddenPropertyId.Value, out propertyId)) { var selectedPropertyDefinition = propertyDefinitionRes.Load(propertyId); if (selectedPropertyDefinition != null) { var selectedPropertyModel = propDefinitionModelRes.GetPropertyModel(selectedPropertyDefinition.ContentTypeID, selectedPropertyDefinition); if (ddlChooseActionType.SelectedValue == "1") { propertyDefinitionRes.Delete(selectedPropertyDefinition); } else if (selectedPropertyModel != null && !string.IsNullOrEmpty(selectedPropertyModel.TabName)) { var cloneProperty = selectedPropertyDefinition.CreateWritableClone(); var newTab = tabRes.Load(selectedPropertyModel.TabName); if (newTab == null) { newTab = new TabDefinition(); newTab.Name = selectedPropertyModel.TabName; tabRes.Save(newTab); } newTab = tabRes.Load(selectedPropertyModel.TabName); cloneProperty.Tab = newTab; propertyDefinitionRes.Save(cloneProperty); } } } } } BindData(); }
public void SaveTabDefinition(TabDefinition tabDefinition) { if(tabDefinition.ID <= 0) { tabDefinition.ID = nextId++; var record = new TabDefinition(); Mapper.Map(tabDefinition, record); tabs.Add(record); } else { var existingTabDefinitionRecord = tabs.First(td => td.ID == tabDefinition.ID); Mapper.Map(tabDefinition, existingTabDefinitionRecord); } numberOfSavesPerTabIdCounter.IncrementNumberOfSaves(tabDefinition.ID); }
public void SaveTabDefinition(TabDefinition tabDefinition) { if (tabDefinition.ID <= 0) { tabDefinition.ID = nextId++; var record = new TabDefinition(); Mapper.Map(tabDefinition, record); tabs.Add(record); } else { var existingTabDefinitionRecord = tabs.First(td => td.ID == tabDefinition.ID); Mapper.Map(tabDefinition, existingTabDefinitionRecord); } numberOfSavesPerTabIdCounter.IncrementNumberOfSaves(tabDefinition.ID); }
protected internal virtual bool TabDefinitionShouldBeUpdated(TabDefinition tabDefinition, Tab tab) { if (tabDefinition.Name != tab.Name) { return(true); } if (tabDefinition.RequiredAccess != tab.RequiredAccess) { return(true); } if (tabDefinition.SortIndex != tab.SortIndex) { return(true); } return(false); }
public void GivenExistingTab_UpdateTabDefinitions_DoesNotSaveTab() { MockRepository fakes = new MockRepository(); TabDefinitionUpdater tabDefinitionUpdater = TabDefinitionUpdaterFactory.Create(); List <Tab> tabs = new List <Tab>(); Tab existingTab = new TestTab(); tabs.Add(existingTab); TabDefinitionRepository fakeTabDefinitionRepository = fakes.Stub <TabDefinitionRepository>(); tabDefinitionUpdater.TabDefinitionRepository = fakeTabDefinitionRepository; TabDefinition existingTabDefinition = TabDefinitionUpdaterTestsUtility.CreateTabDefinition(existingTab); tabDefinitionUpdater.TabDefinitionRepository.Stub(factory => factory.GetTabDefinition(existingTab.Name)).Return(existingTabDefinition); tabDefinitionUpdater.TabDefinitionRepository.Replay(); tabDefinitionUpdater.UpdateTabDefinitions(tabs); tabDefinitionUpdater.TabDefinitionRepository.AssertWasNotCalled(factory => factory.SaveTabDefinition(Arg <TabDefinition> .Is.Anything)); }
public virtual void AddNewPropertyDefinitionToPageType(ContentType contentType, string hashedPropertyName, string editCaption, string helpText, TabDefinition tabDefinition) { var propertyDefinition = new PropertyDefinition { ContentTypeID = contentType.ID, ID = 0, DisplayEditUI = true, EditCaption = editCaption, ExistsOnModel = false, HelpText = helpText, LanguageSpecific = true, Name = hashedPropertyName, Required = false, Searchable = false, Tab = tabDefinition, Type = _stringPropertyDefinitionType }; _propertyDefinitionRepository.Service.Save(propertyDefinition); contentType = (ContentType)contentType.CreateWritableClone(); contentType.PropertyDefinitions.Add(propertyDefinition); _contentTypeRepository.Service.Save(contentType); }
public virtual void Delete(TabDefinition tabDefinition) { tabDefinition.Delete(); }
public void SaveTabDefinition(TabDefinition tabDefinition) { }
protected internal virtual void UpdateTabDefinition(TabDefinition tabDefinition, Tab tab) { tabDefinition.Name = tab.Name; tabDefinition.RequiredAccess = tab.RequiredAccess; tabDefinition.SortIndex = tab.SortIndex; }
public virtual void SaveTabDefinition(TabDefinition tabDefinition) { tabDefinition.Save(); }